Only allow one googleGcs config object

Signed-off-by: Martina Iglesias Fernandez <martina@roadie.io>
This commit is contained in:
Martina Iglesias Fernandez
2021-03-19 17:50:25 +01:00
parent 5bd790984e
commit d5cb51331a
8 changed files with 45 additions and 81 deletions
@@ -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({});
});
});
+4 -11
View File
@@ -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);
}
+1 -4
View File
@@ -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';