Skip to content

Commit

Permalink
Fix feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Martina Iglesias Fernandez <martina@roadie.io>
  • Loading branch information
martina-if committed Apr 7, 2021
1 parent 6a9b9d0 commit c410cae
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
6 changes: 3 additions & 3 deletions app-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 12 additions & 5 deletions packages/backend-common/src/reading/GoogleGcsUrlReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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();
Expand All @@ -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 {
Expand All @@ -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)}}`;
}
}
9 changes: 3 additions & 6 deletions packages/integration/src/googleGcs/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}

0 comments on commit c410cae

Please sign in to comment.