Skip to content

Commit

Permalink
Merge pull request backstage#4035 from ayshiff/feature/catalog-backen…
Browse files Browse the repository at this point in the history
…d-aws-sdk-v3

Catalog Backend: AWS Organizations SDK version bump
  • Loading branch information
freben authored Jan 12, 2021
2 parents d45a510 + 8b37a25 commit 1df9134
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 106 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-ants-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-backend': patch
---

AWS SDK version bump for Catalog Backend.
2 changes: 1 addition & 1 deletion plugins/catalog-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
"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",
"@backstage/config": "^0.1.2",
"@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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,18 @@ describe('AwsOrganizationCloudAccountProcessor', () => {
afterEach(() => jest.resetAllMocks());

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,
};
},
};
});
listAccounts.mockImplementation(() =>
Promise.resolve({
Accounts: [
{
Arn:
'arn:aws:organizations::192594491037:account/o-1vl18kc5a3/957140518395',
Name: 'testaccount',
},
],
NextToken: undefined,
}),
);
await processor.readLocation(location, false, emit);
expect(emit).toBeCalledWith({
type: 'entity',
Expand Down Expand Up @@ -71,27 +67,23 @@ describe('AwsOrganizationCloudAccountProcessor', () => {

it('filters out accounts not in specified location target', async () => {
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,
};
},
};
});
listAccounts.mockImplementation(() =>
Promise.resolve({
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);
expect(emit).toBeCalledTimes(1);
expect(emit).toBeCalledWith({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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
}
Expand Down Expand Up @@ -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);
}
Expand Down
Loading

0 comments on commit 1df9134

Please sign in to comment.