feat(catalog-backend): update aws-sdk to v3
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
"clean": "backstage-cli clean"
|
||||
},
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-organizations": "^3.2.0",
|
||||
"@azure/msal-node": "^1.0.0-alpha.8",
|
||||
"@backstage/backend-common": "^0.4.2",
|
||||
"@backstage/catalog-model": "^0.6.0",
|
||||
@@ -36,7 +37,6 @@
|
||||
"@octokit/graphql": "^4.5.6",
|
||||
"@types/express": "^4.17.6",
|
||||
"@types/ldapjs": "^1.0.9",
|
||||
"aws-sdk": "^2.817.0",
|
||||
"codeowners-utils": "^1.0.2",
|
||||
"core-js": "^3.6.5",
|
||||
"cross-fetch": "^3.0.6",
|
||||
|
||||
+21
-29
@@ -29,18 +29,14 @@ describe('AwsOrganizationCloudAccountProcessor', () => {
|
||||
it('generates component entities for accounts', async () => {
|
||||
listAccounts.mockImplementation(() => {
|
||||
return {
|
||||
async promise() {
|
||||
return {
|
||||
Accounts: [
|
||||
{
|
||||
Arn:
|
||||
'arn:aws:organizations::192594491037:account/o-1vl18kc5a3/957140518395',
|
||||
Name: 'testaccount',
|
||||
},
|
||||
],
|
||||
NextToken: undefined,
|
||||
};
|
||||
},
|
||||
Accounts: [
|
||||
{
|
||||
Arn:
|
||||
'arn:aws:organizations::192594491037:account/o-1vl18kc5a3/957140518395',
|
||||
Name: 'testaccount',
|
||||
},
|
||||
],
|
||||
NextToken: undefined,
|
||||
};
|
||||
});
|
||||
await processor.readLocation(location, false, emit);
|
||||
@@ -73,23 +69,19 @@ describe('AwsOrganizationCloudAccountProcessor', () => {
|
||||
const location = { type: 'aws-cloud-accounts', target: 'o-1vl18kc5a3' };
|
||||
listAccounts.mockImplementation(() => {
|
||||
return {
|
||||
async promise() {
|
||||
return {
|
||||
Accounts: [
|
||||
{
|
||||
Arn:
|
||||
'arn:aws:organizations::192594491037:account/o-1vl18kc5a3/957140518395',
|
||||
Name: 'testaccount',
|
||||
},
|
||||
{
|
||||
Arn:
|
||||
'arn:aws:organizations::192594491037:account/o-zzzzzzzzz/957140518395',
|
||||
Name: 'testaccount2',
|
||||
},
|
||||
],
|
||||
NextToken: undefined,
|
||||
};
|
||||
},
|
||||
Accounts: [
|
||||
{
|
||||
Arn:
|
||||
'arn:aws:organizations::192594491037:account/o-1vl18kc5a3/957140518395',
|
||||
Name: 'testaccount',
|
||||
},
|
||||
{
|
||||
Arn:
|
||||
'arn:aws:organizations::192594491037:account/o-zzzzzzzzz/957140518395',
|
||||
Name: 'testaccount2',
|
||||
},
|
||||
],
|
||||
NextToken: undefined,
|
||||
};
|
||||
});
|
||||
await processor.readLocation(location, false, emit);
|
||||
|
||||
+9
-6
@@ -17,8 +17,11 @@ import {
|
||||
ComponentEntityV1alpha1,
|
||||
LocationSpec,
|
||||
} from '@backstage/catalog-model';
|
||||
import AWS, { Organizations } from 'aws-sdk';
|
||||
import { Account, ListAccountsResponse } from 'aws-sdk/clients/organizations';
|
||||
import {
|
||||
Account,
|
||||
Organizations,
|
||||
ListAccountsCommandOutput,
|
||||
} from '@aws-sdk/client-organizations';
|
||||
|
||||
import * as results from './results';
|
||||
import { CatalogProcessor, CatalogProcessorEmit } from './types';
|
||||
@@ -38,7 +41,7 @@ const ORGANIZATION_ANNOTATION: string = 'amazonaws.com/organization-id';
|
||||
export class AwsOrganizationCloudAccountProcessor implements CatalogProcessor {
|
||||
organizations: Organizations;
|
||||
constructor() {
|
||||
this.organizations = new AWS.Organizations({
|
||||
this.organizations = new Organizations({
|
||||
region: AWS_ORGANIZATION_REGION,
|
||||
}); // Only available in us-east-1
|
||||
}
|
||||
@@ -67,9 +70,9 @@ export class AwsOrganizationCloudAccountProcessor implements CatalogProcessor {
|
||||
let nextToken = undefined;
|
||||
while (isInitialAttempt || nextToken) {
|
||||
isInitialAttempt = false;
|
||||
const orgAccounts: ListAccountsResponse = await this.organizations
|
||||
.listAccounts({ NextToken: nextToken })
|
||||
.promise();
|
||||
const orgAccounts: ListAccountsCommandOutput = await this.organizations.listAccounts(
|
||||
{ NextToken: nextToken },
|
||||
);
|
||||
if (orgAccounts.Accounts) {
|
||||
awsAccounts = awsAccounts.concat(orgAccounts.Accounts);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user