Only allow one googleGcs config object
Signed-off-by: Martina Iglesias Fernandez <martina@roadie.io>
This commit is contained in:
@@ -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<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',
|
||||
});
|
||||
it('does not fail when config is not set', () => {
|
||||
const output = readGoogleGcsIntegrationConfig(buildConfig({}));
|
||||
expect(output).toEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user