Address review comments
This commit is contained in:
Vendored
+2
-2
@@ -338,13 +338,13 @@ export interface Config {
|
||||
* AwsOrganizationCloudAccountProcessor configuration
|
||||
*/
|
||||
awsOrganization?: {
|
||||
providers: Array<{
|
||||
provider: {
|
||||
/**
|
||||
* The role to be assumed by this processor
|
||||
*
|
||||
*/
|
||||
roleArn?: string;
|
||||
}>;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
+7
-8
@@ -19,7 +19,7 @@ import { Account, ListAccountsResponse } from 'aws-sdk/clients/organizations';
|
||||
|
||||
import * as results from './results';
|
||||
import { CatalogProcessor, CatalogProcessorEmit } from './types';
|
||||
import { Config } from '../../../../../packages/config/src';
|
||||
import { Config } from '@backstage/config';
|
||||
import { Logger } from 'winston';
|
||||
import {
|
||||
AwsOrganizationProviderConfig,
|
||||
@@ -41,33 +41,32 @@ const ORGANIZATION_ANNOTATION: string = 'amazonaws.com/organization-id';
|
||||
export class AwsOrganizationCloudAccountProcessor implements CatalogProcessor {
|
||||
logger: Logger;
|
||||
organizations: Organizations;
|
||||
providers: AwsOrganizationProviderConfig[];
|
||||
provider: AwsOrganizationProviderConfig;
|
||||
|
||||
static fromConfig(config: Config, options: { logger: Logger }) {
|
||||
const c = config.getOptionalConfig('catalog.processors.awsOrganization');
|
||||
return new AwsOrganizationCloudAccountProcessor({
|
||||
...options,
|
||||
providers: c ? readAwsOrganizationConfig(c) : [],
|
||||
provider: c ? readAwsOrganizationConfig(c) : {},
|
||||
});
|
||||
}
|
||||
|
||||
constructor(options: {
|
||||
providers: AwsOrganizationProviderConfig[];
|
||||
provider: AwsOrganizationProviderConfig;
|
||||
logger: Logger;
|
||||
}) {
|
||||
this.providers = options.providers;
|
||||
this.provider = options.provider;
|
||||
this.logger = options.logger;
|
||||
let credentials = undefined;
|
||||
if (
|
||||
this.providers.length > 0 &&
|
||||
this.providers[0].roleArn !== undefined &&
|
||||
this.provider.roleArn !== undefined &&
|
||||
AWS.config.credentials instanceof Credentials
|
||||
) {
|
||||
credentials = new AWS.ChainableTemporaryCredentials({
|
||||
masterCredentials: AWS.config.credentials as Credentials,
|
||||
params: {
|
||||
RoleSessionName: 'backstage-aws-organization-processor',
|
||||
RoleArn: this.providers[0].roleArn,
|
||||
RoleArn: this.provider.roleArn,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -28,17 +28,11 @@ export type AwsOrganizationProviderConfig = {
|
||||
|
||||
export function readAwsOrganizationConfig(
|
||||
config: Config,
|
||||
): AwsOrganizationProviderConfig[] {
|
||||
const providers: AwsOrganizationProviderConfig[] = [];
|
||||
const providerConfigs = config.getOptionalConfigArray('providers') ?? [];
|
||||
): AwsOrganizationProviderConfig {
|
||||
const providerConfig = config.getOptionalConfig('provider');
|
||||
|
||||
for (const providerConfig of providerConfigs) {
|
||||
const roleArn = providerConfig.getOptionalString('roleArn');
|
||||
|
||||
providers.push({
|
||||
roleArn,
|
||||
});
|
||||
}
|
||||
|
||||
return providers;
|
||||
const roleArn = providerConfig?.getOptionalString('roleArn');
|
||||
return {
|
||||
roleArn,
|
||||
};
|
||||
}
|
||||
|
||||
Vendored
+1
-2
@@ -88,8 +88,7 @@ export interface Config {
|
||||
secretAccessKey: string;
|
||||
/**
|
||||
* ARN of role to be assumed
|
||||
* attr: 'roleArn' - accepts a string value
|
||||
* @visibility secret
|
||||
* @visibility backend
|
||||
*/
|
||||
roleArn?: string;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user