Fix comments on GoogleGcsUrlReader
Signed-off-by: Martina Iglesias Fernandez <martina@roadie.io>
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2020 Spotify AB
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Config, ConfigReader } from '@backstage/config';
|
||||
import {
|
||||
GoogleGcsIntegrationConfig,
|
||||
readGoogleGcsIntegrationConfig,
|
||||
readGoogleGcsIntegrationConfigs,
|
||||
} from './config';
|
||||
|
||||
describe('readGoogleGcsIntegrationConfig', () => {
|
||||
function buildConfig(data: Partial<GoogleGcsIntegrationConfig>): Config {
|
||||
return new ConfigReader(data);
|
||||
}
|
||||
|
||||
it('reads all values', () => {
|
||||
const output = readGoogleGcsIntegrationConfig(
|
||||
buildConfig({
|
||||
privateKey: 'fake-key',
|
||||
clientEmail: 'someone@example.com',
|
||||
}),
|
||||
);
|
||||
expect(output).toEqual({
|
||||
privateKey: 'fake-key',
|
||||
token: 'someone@example.com',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('readGoogleGcsIntegrationConfigs', () => {
|
||||
function buildConfig(data: Partial<GoogleGcsIntegrationConfig>[]): 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',
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2020 Spotify AB
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Config } from '@backstage/config';
|
||||
|
||||
/**
|
||||
* The configuration parameters for a single Google Cloud Storage provider.
|
||||
*/
|
||||
export type GoogleGcsIntegrationConfig = {
|
||||
/**
|
||||
* Service account email used to authenticate requests.
|
||||
*/
|
||||
clientEmail?: string;
|
||||
/**
|
||||
* Service account private key used to authenticate requests.
|
||||
*/
|
||||
privateKey?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Reads a single Google GCS integration config.
|
||||
*
|
||||
* @param config The config object of a single integration
|
||||
*/
|
||||
export function readGoogleGcsIntegrationConfig(
|
||||
config: Config,
|
||||
): GoogleGcsIntegrationConfig {
|
||||
if (!config.has('clientEmail') || !config.has('privateKey')) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const privateKey = config
|
||||
.getOptionalString('privateKey')
|
||||
?.split('\\n')
|
||||
.join('\n');
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2020 Spotify AB
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export {
|
||||
readGoogleGcsIntegrationConfig,
|
||||
readGoogleGcsIntegrationConfigs,
|
||||
} from './config';
|
||||
export type { GoogleGcsIntegrationConfig } from './config';
|
||||
export const GOOGLE_GCS_HOST = 'storage.cloud.google.com';
|
||||
@@ -18,6 +18,7 @@ export * from './azure';
|
||||
export * from './bitbucket';
|
||||
export * from './github';
|
||||
export * from './gitlab';
|
||||
export * from './googleGcs';
|
||||
export { defaultScmResolveUrl } from './helpers';
|
||||
export { ScmIntegrations } from './ScmIntegrations';
|
||||
export type {
|
||||
|
||||
Reference in New Issue
Block a user