diff --git a/app-config.yaml b/app-config.yaml index 49ac0b0d00..3dc071c85c 100644 --- a/app-config.yaml +++ b/app-config.yaml @@ -123,10 +123,10 @@ kafka: integrations: googleGcs: - - clientEmail: - $env: GCS_CLIENT_EMAIL - privateKey: - $env: GCS_PRIVATE_KEY + clientEmail: + $env: GCS_CLIENT_EMAIL + privateKey: + $env: GCS_PRIVATE_KEY github: - host: github.com diff --git a/docs/integrations/google-cloud-storage/gcs.md b/docs/integrations/google-cloud-storage/gcs.md index f9cba7a04c..1d46c57b10 100644 --- a/docs/integrations/google-cloud-storage/gcs.md +++ b/docs/integrations/google-cloud-storage/gcs.md @@ -24,10 +24,10 @@ Explicit credentials can be set in the following format: ```yaml integrations: googleGcs: - - clientEmail: - $env: GCS_CLIENT_EMAIL - privateKey: - $env: GCS_PRIVATE_KEY + clientEmail: + $env: GCS_CLIENT_EMAIL + privateKey: + $env: GCS_PRIVATE_KEY ``` Then make sure the environment variables `GCS_CLIENT_EMAIL` and diff --git a/packages/backend-common/src/reading/GoogleGcsUrlReader.test.ts b/packages/backend-common/src/reading/GoogleGcsUrlReader.test.ts index c8262767e1..e201361a91 100644 --- a/packages/backend-common/src/reading/GoogleGcsUrlReader.test.ts +++ b/packages/backend-common/src/reading/GoogleGcsUrlReader.test.ts @@ -41,26 +41,19 @@ describe('GcsUrlReader', () => { it('creates a reader with credentials correctly configured', () => { const entries = createReader({ integrations: { - googleGcs: [ - { - privateKey: '--- BEGIN KEY ---- fakekey --- END KEY ---', - clientEmail: 'someone@example.com', - }, - { - host: 'proxy.storage.cloud.google.com', - privateKey: '--- BEGIN KEY ---- fakekey2 --- END KEY ---', - clientEmail: 'someone2@example.com', - }, - ], + googleGcs: { + privateKey: '--- BEGIN KEY ---- fakekey --- END KEY ---', + clientEmail: 'someone@example.com', + }, }, }); - expect(entries).toHaveLength(2); + expect(entries).toHaveLength(1); }); it('creates a reader with default credentials provider', () => { const entries = createReader({ integrations: { - googleGcs: [{}], + googleGcs: {}, }, }); expect(entries).toHaveLength(1); @@ -69,7 +62,7 @@ describe('GcsUrlReader', () => { describe('predicates', () => { const readers = createReader({ integrations: { - googleGcs: [{}], + googleGcs: {}, }, }); const predicate = readers[0].predicate; diff --git a/packages/backend-common/src/reading/GoogleGcsUrlReader.ts b/packages/backend-common/src/reading/GoogleGcsUrlReader.ts index a9100051a6..80b42dd5da 100644 --- a/packages/backend-common/src/reading/GoogleGcsUrlReader.ts +++ b/packages/backend-common/src/reading/GoogleGcsUrlReader.ts @@ -24,7 +24,7 @@ import { import getRawBody from 'raw-body'; import { GOOGLE_GCS_HOST, - readGoogleGcsIntegrationConfigs, + readGoogleGcsIntegrationConfig, } from '@backstage/integration'; const parseURL = ( @@ -49,28 +49,26 @@ export class GoogleGcsUrlReader implements UrlReader { if (!config.has('integrations.googleGcs')) { return []; } - const configs = readGoogleGcsIntegrationConfigs( - config.getOptionalConfigArray('integrations.googleGcs') ?? [], + const gcsConfig = readGoogleGcsIntegrationConfig( + config.getConfig('integrations.googleGcs'), ); - return configs.map(integration => { - let storage: Storage; - if (!integration.clientEmail || !integration.privateKey) { - logger.warn( - 'googleGcs credentials not found in config. Using default credentials provider.', - ); - storage = new Storage(); - } else { - storage = new Storage({ - credentials: { - client_email: integration.clientEmail || undefined, - private_key: integration.privateKey || undefined, - }, - }); - } - const reader = new GoogleGcsUrlReader(storage); - const predicate = (url: URL) => url.host === GOOGLE_GCS_HOST; - return { reader, predicate }; - }); + let storage: Storage; + if (!gcsConfig.clientEmail || !gcsConfig.privateKey) { + logger.warn( + 'googleGcs credentials not found in config. Using default credentials provider.', + ); + storage = new Storage(); + } else { + storage = new Storage({ + credentials: { + client_email: gcsConfig.clientEmail || undefined, + private_key: gcsConfig.privateKey || undefined, + }, + }); + } + const reader = new GoogleGcsUrlReader(storage); + const predicate = (url: URL) => url.host === GOOGLE_GCS_HOST; + return [{ reader, predicate }]; }; constructor(private readonly storage: Storage) {} diff --git a/packages/integration/config.d.ts b/packages/integration/config.d.ts index 2947ba3889..9f9d588f0b 100644 --- a/packages/integration/config.d.ts +++ b/packages/integration/config.d.ts @@ -151,7 +151,7 @@ export interface Config { }>; /** Integration configuration for Google Cloud Storage */ - googleGcs?: Array<{ + googleGcs?: { /** * Service account email used to authenticate requests. * @visibility secret @@ -162,6 +162,6 @@ export interface Config { * @visibility secret */ privateKey?: string; - }>; + }; }; } diff --git a/packages/integration/src/googleGcs/config.test.ts b/packages/integration/src/googleGcs/config.test.ts index d612343b5e..f688df4071 100644 --- a/packages/integration/src/googleGcs/config.test.ts +++ b/packages/integration/src/googleGcs/config.test.ts @@ -18,7 +18,6 @@ import { Config, ConfigReader } from '@backstage/config'; import { GoogleGcsIntegrationConfig, readGoogleGcsIntegrationConfig, - readGoogleGcsIntegrationConfigs, } from './config'; describe('readGoogleGcsIntegrationConfig', () => { @@ -38,25 +37,9 @@ describe('readGoogleGcsIntegrationConfig', () => { token: 'someone@example.com', }); }); -}); -describe('readGoogleGcsIntegrationConfigs', () => { - function buildConfig(data: Partial[]): Config[] { - return data.map(item => new ConfigReader(item)); - } - - it('reads all values', () => { - const output = readGoogleGcsIntegrationConfigs( - buildConfig([ - { - privateKey: 'fake-key', - clientEmail: 'someone@example.com', - }, - ]), - ); - expect(output).toContainEqual({ - privateKey: 'fake-key', - clientEmail: 'someone@example.com', - }); + it('does not fail when config is not set', () => { + const output = readGoogleGcsIntegrationConfig(buildConfig({})); + expect(output).toEqual({}); }); }); diff --git a/packages/integration/src/googleGcs/config.ts b/packages/integration/src/googleGcs/config.ts index 5f70932638..90a679bb4c 100644 --- a/packages/integration/src/googleGcs/config.ts +++ b/packages/integration/src/googleGcs/config.ts @@ -38,6 +38,10 @@ export type GoogleGcsIntegrationConfig = { export function readGoogleGcsIntegrationConfig( config: Config, ): GoogleGcsIntegrationConfig { + if (!config) { + return {}; + } + if (!config.has('clientEmail') || !config.has('privateKey')) { return {}; } @@ -50,14 +54,3 @@ export function readGoogleGcsIntegrationConfig( const clientEmail = config.getOptionalString('clientEmail'); return { clientEmail: clientEmail, privateKey: privateKey }; } - -/** - * Reads a set of Google Cloud Storage integration configs. - * - * @param configs All of the integration config objects - */ -export function readGoogleGcsIntegrationConfigs( - configs: Config[], -): GoogleGcsIntegrationConfig[] { - return configs.map(readGoogleGcsIntegrationConfig); -} diff --git a/packages/integration/src/googleGcs/index.ts b/packages/integration/src/googleGcs/index.ts index f120256d35..ac85d706b5 100644 --- a/packages/integration/src/googleGcs/index.ts +++ b/packages/integration/src/googleGcs/index.ts @@ -14,9 +14,6 @@ * limitations under the License. */ -export { - readGoogleGcsIntegrationConfig, - readGoogleGcsIntegrationConfigs, -} from './config'; +export { readGoogleGcsIntegrationConfig } from './config'; export type { GoogleGcsIntegrationConfig } from './config'; export const GOOGLE_GCS_HOST = 'storage.cloud.google.com';