Address some review comments
This commit is contained in:
+4
-4
@@ -14,12 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { AwsOrganizationProcessor } from './AwsOrganizationProcessor';
|
||||
import { AwsOrganizationCloudAccountProcessor } from './AwsOrganizationCloudAccountProcessor';
|
||||
|
||||
describe('AwsOrganizationProcessor', () => {
|
||||
describe('AwsOrganizationCloudAccountProcessor', () => {
|
||||
describe('readLocation', () => {
|
||||
const processor = new AwsOrganizationProcessor();
|
||||
const location = { type: 'aws-organization', target: 'b' };
|
||||
const processor = new AwsOrganizationCloudAccountProcessor();
|
||||
const location = { type: 'aws-cloud-accounts', target: 'b' };
|
||||
const emit = jest.fn();
|
||||
const listAccounts = jest.fn();
|
||||
|
||||
+11
-23
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
import {
|
||||
ComponentEntityV1alpha1,
|
||||
Entity,
|
||||
LocationSpec,
|
||||
} from '@backstage/catalog-model';
|
||||
import AWS, { Organizations } from 'aws-sdk';
|
||||
@@ -25,9 +24,14 @@ import * as results from './results';
|
||||
import { CatalogProcessor, CatalogProcessorEmit } from './types';
|
||||
|
||||
const AWS_ORGANIZATION_REGION = 'us-east-1';
|
||||
const LOCATION_TYPE = 'aws-organization';
|
||||
const LOCATION_TYPE = 'aws-cloud-accounts';
|
||||
|
||||
export class AwsOrganizationProcessor implements CatalogProcessor {
|
||||
/**
|
||||
* A processor for ingesting AWS Accounts from AWS Organizations.
|
||||
*
|
||||
* If custom authentication is needed, it can be achieved by configuring the global AWS.credentials object.
|
||||
*/
|
||||
export class AwsOrganizationCloudAccountProcessor implements CatalogProcessor {
|
||||
organizations: Organizations;
|
||||
constructor() {
|
||||
this.organizations = new AWS.Organizations({
|
||||
@@ -35,18 +39,6 @@ export class AwsOrganizationProcessor implements CatalogProcessor {
|
||||
}); // Only available in us-east-1
|
||||
}
|
||||
|
||||
async handleError(): Promise<void> {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
async postProcessEntity(entity: Entity): Promise<Entity> {
|
||||
return entity;
|
||||
}
|
||||
|
||||
async preProcessEntity(entity: Entity): Promise<Entity> {
|
||||
return entity;
|
||||
}
|
||||
|
||||
normalizeName(name: string): string {
|
||||
return name
|
||||
.trim()
|
||||
@@ -68,16 +60,16 @@ export class AwsOrganizationProcessor implements CatalogProcessor {
|
||||
async getAwsAccounts(): Promise<Account[]> {
|
||||
let awsAccounts: Account[] = [];
|
||||
let isInitialAttempt = true;
|
||||
let NextToken = undefined;
|
||||
while (isInitialAttempt || NextToken) {
|
||||
let nextToken = undefined;
|
||||
while (isInitialAttempt || nextToken) {
|
||||
isInitialAttempt = false;
|
||||
const orgAccounts: ListAccountsResponse = await this.organizations
|
||||
.listAccounts({ NextToken })
|
||||
.listAccounts({ NextToken: nextToken })
|
||||
.promise();
|
||||
if (orgAccounts.Accounts) {
|
||||
awsAccounts = awsAccounts.concat(orgAccounts.Accounts);
|
||||
NextToken = orgAccounts.NextToken;
|
||||
}
|
||||
nextToken = orgAccounts.NextToken;
|
||||
}
|
||||
|
||||
return awsAccounts;
|
||||
@@ -124,8 +116,4 @@ export class AwsOrganizationProcessor implements CatalogProcessor {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
async validateEntityKind(): Promise<boolean> {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
import * as results from './results';
|
||||
|
||||
export { AnnotateLocationEntityProcessor } from './AnnotateLocationEntityProcessor';
|
||||
export { AwsOrganizationProcessor } from './AwsOrganizationProcessor';
|
||||
export { AwsOrganizationProcessor } from './AwsOrganizationCloudAccountProcessor';
|
||||
export { BuiltinKindsEntityProcessor } from './BuiltinKindsEntityProcessor';
|
||||
export { CodeOwnersProcessor } from './CodeOwnersProcessor';
|
||||
export { FileReaderProcessor } from './FileReaderProcessor';
|
||||
|
||||
Reference in New Issue
Block a user