diff --git a/packages/integration/src/azure/config.ts b/packages/integration/src/azure/config.ts index 0213475cc8..2f6a08a43c 100644 --- a/packages/integration/src/azure/config.ts +++ b/packages/integration/src/azure/config.ts @@ -218,9 +218,17 @@ function asAzureDevOpsCredential( export function readAzureIntegrationConfig( config: Config, ): AzureIntegrationConfig { + deprecatedConfigCheck(config); + const host = config.getOptionalString('host') ?? AZURE_HOST; - let credentialConfigs = config + if (!isValidHost(host)) { + throw new Error( + `Invalid Azure integration config, '${host}' is not a valid host`, + ); + } + + const credentialConfigs = config .getOptionalConfigArray('credentials') ?.map(credential => { const result: Partial = { @@ -239,54 +247,6 @@ export function readAzureIntegrationConfig( return result; }); - const token = config.getOptionalString('token')?.trim(); - - if ( - config.getOptional('credential') !== undefined && - config.getOptional('credentials') !== undefined - ) { - throw new Error( - `Invalid Azure integration config, 'credential' and 'credentials' cannot be used together. Use 'credentials' instead.`, - ); - } - - if ( - config.getOptional('token') !== undefined && - config.getOptional('credentials') !== undefined - ) { - throw new Error( - `Invalid Azure integration config, 'token' and 'credentials' cannot be used together. Use 'credentials' instead.`, - ); - } - - if (token !== undefined) { - const mapped = [{ personalAccessToken: token }]; - credentialConfigs = credentialConfigs?.concat(mapped) ?? mapped; - } - - if (config.getOptional('credential') !== undefined) { - const mapped = [ - { - organizations: config.getOptionalStringArray( - 'credential.organizations', - ), - token: config.getOptionalString('credential.token')?.trim(), - tenantId: config.getOptionalString('credential.tenantId'), - clientId: config.getOptionalString('credential.clientId'), - clientSecret: config - .getOptionalString('credential.clientSecret') - ?.trim(), - }, - ]; - credentialConfigs = credentialConfigs?.concat(mapped) ?? mapped; - } - - if (!isValidHost(host)) { - throw new Error( - `Invalid Azure integration config, '${host}' is not a valid host`, - ); - } - let credentials: AzureDevOpsCredential[] | undefined = undefined; if (credentialConfigs !== undefined) { const errors = credentialConfigs @@ -397,3 +357,19 @@ export function readAzureIntegrationConfigs( return result; } + +/** + * These config sections have been removed but to insure they + * don't leak sensitive tokens we have this check in place + * to throw an error if found + * + * @internal + * @deprecated To be removed at a later date + */ +export function deprecatedConfigCheck(config: Config) { + if (config.getOptional('credential') || config.getOptional('token')) { + throw new Error( + `Invalid Azure integration config, 'credential' and 'token' have been removed. Use 'credentials' instead.`, + ); + } +}