Fix feedback

Signed-off-by: Martina Iglesias Fernandez <martina@roadie.io>
This commit is contained in:
Martina Iglesias Fernandez
2021-04-07 12:06:07 +02:00
parent 6a9b9d0f7c
commit c410cae0f2
3 changed files with 18 additions and 14 deletions
+3 -3
View File
@@ -151,9 +151,9 @@ integrations:
token:
$env: AZURE_TOKEN
# googleGcs:
# clientEmail:
# $env: GCS_CLIENT_EMAIL
# privateKey: 'example@example.com'
# clientEmail: 'example@example.com'
# privateKey:
# $env: GCS_PRIVATE_KEY
catalog:
rules:
@@ -22,7 +22,10 @@ import {
UrlReader,
} from './types';
import getRawBody from 'raw-body';
import { readGoogleGcsIntegrationConfig } from '@backstage/integration';
import {
GoogleGcsIntegrationConfig,
readGoogleGcsIntegrationConfig,
} from '@backstage/integration';
const GOOGLE_GCS_HOST = 'storage.cloud.google.com';
@@ -53,7 +56,7 @@ export class GoogleGcsUrlReader implements UrlReader {
);
let storage: Storage;
if (!gcsConfig.clientEmail || !gcsConfig.privateKey) {
logger.warn(
logger.info(
'googleGcs credentials not found in config. Using default credentials provider.',
);
storage = new Storage();
@@ -65,12 +68,15 @@ export class GoogleGcsUrlReader implements UrlReader {
},
});
}
const reader = new GoogleGcsUrlReader(storage);
const reader = new GoogleGcsUrlReader(gcsConfig, storage);
const predicate = (url: URL) => url.host === GOOGLE_GCS_HOST;
return [{ reader, predicate }];
};
constructor(private readonly storage: Storage) {}
constructor(
private readonly integration: GoogleGcsIntegrationConfig,
private readonly storage: Storage,
) {}
async read(url: string): Promise<Buffer> {
try {
@@ -93,6 +99,7 @@ export class GoogleGcsUrlReader implements UrlReader {
}
toString() {
return `gcs{host=${GOOGLE_GCS_HOST},authed=true}}`;
const key = this.integration.privateKey;
return `googleGcs{host=${GOOGLE_GCS_HOST},authed=${Boolean(key)}}`;
}
}
+3 -6
View File
@@ -42,15 +42,12 @@ export function readGoogleGcsIntegrationConfig(
return {};
}
if (!config.has('clientEmail') || !config.has('privateKey')) {
if (!config.has('clientEmail') && !config.has('privateKey')) {
return {};
}
const privateKey = config
.getOptionalString('privateKey')
?.split('\\n')
.join('\n');
const privateKey = config.getString('privateKey').split('\\n').join('\n');
const clientEmail = config.getOptionalString('clientEmail');
const clientEmail = config.getString('clientEmail');
return { clientEmail: clientEmail, privateKey: privateKey };
}