Skip to content

Commit

Permalink
Merge pull request #1247 from RoadieHQ/sc-18900-allow-multiple-aws-pr…
Browse files Browse the repository at this point in the history
…oviders

Add uniqueness to AWS providers to allow multiple configuration if wanted.
  • Loading branch information
Xantier authored Feb 9, 2024
2 parents 5676860 + f67229d commit 08702a0
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-carrots-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@roadiehq/catalog-backend-module-aws': patch
---

Add uniqueness to AWS providers to allow multiple configuration if wanted.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ import { arnToName } from '../utils/arnToName';
* Provides entities from AWS DynamoDB service.
*/
export class AWSDynamoDbTableProvider extends AWSEntityProvider {
static fromConfig(config: Config, options: { logger: winston.Logger }) {
static fromConfig(
config: Config,
options: { logger: winston.Logger; providerId?: string },
) {
const accountId = config.getString('accountId');
const roleArn = config.getString('roleArn');
const externalId = config.getOptionalString('externalId');
Expand All @@ -39,7 +42,7 @@ export class AWSDynamoDbTableProvider extends AWSEntityProvider {
}

getProviderName(): string {
return `aws-dynamo-db-table-${this.accountId}`;
return `aws-dynamo-db-table-${this.accountId}-${this.providerId ?? 0}`;
}

async run(): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ import { ANNOTATION_AWS_EC2_INSTANCE_ID } from '../annotations';
* Provides entities from AWS Elastic Compute Cloud.
*/
export class AWSEC2Provider extends AWSEntityProvider {
static fromConfig(config: Config, options: { logger: winston.Logger }) {
static fromConfig(
config: Config,
options: { logger: winston.Logger; providerId?: string },
) {
const accountId = config.getString('accountId');
const roleArn = config.getString('roleArn');
const externalId = config.getOptionalString('externalId');
Expand All @@ -38,7 +41,7 @@ export class AWSEC2Provider extends AWSEntityProvider {
}

getProviderName(): string {
return `aws-ec2-provider-${this.accountId}`;
return `aws-ec2-provider-${this.accountId}-${this.providerId ?? 0}`;
}

async run(): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ import { arnToName } from '../utils/arnToName';
* Provides entities from AWS EKS Cluster service.
*/
export class AWSEKSClusterProvider extends AWSEntityProvider {
static fromConfig(config: Config, options: { logger: winston.Logger }) {
static fromConfig(
config: Config,
options: { logger: winston.Logger; providerId?: string },
) {
const accountId = config.getString('accountId');
const roleArn = config.getString('roleArn');
const externalId = config.getOptionalString('externalId');
Expand All @@ -42,7 +45,7 @@ export class AWSEKSClusterProvider extends AWSEntityProvider {
}

getProviderName(): string {
return `aws-eks-cluster-${this.accountId}`;
return `aws-eks-cluster-${this.accountId}-${this.providerId ?? 0}`;
}

async run(): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,22 @@ export abstract class AWSEntityProvider implements EntityProvider {
protected readonly roleArn: string;
private readonly externalId?: string;
protected readonly region: string;
protected readonly providerId?: string;
protected readonly logger: winston.Logger;
protected connection?: EntityProviderConnection;

public abstract getProviderName(): string;

protected constructor(
account: AccountConfig,
options: { logger: winston.Logger },
options: { logger: winston.Logger; providerId?: string },
) {
this.accountId = account.accountId;
this.roleArn = account.roleArn;
this.externalId = account.externalId;
this.region = account.region;
this.logger = options.logger;
this.providerId = options.providerId;
}

protected getCredentials() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ import { ARN } from 'link2aws';
* Provides entities from AWS IAM Role service.
*/
export class AWSIAMRoleProvider extends AWSEntityProvider {
static fromConfig(config: Config, options: { logger: winston.Logger }) {
static fromConfig(
config: Config,
options: { logger: winston.Logger; providerId?: string },
) {
const accountId = config.getString('accountId');
const roleArn = config.getString('roleArn');
const externalId = config.getOptionalString('externalId');
Expand All @@ -40,7 +43,7 @@ export class AWSIAMRoleProvider extends AWSEntityProvider {
}

getProviderName(): string {
return `aws-iam-role-${this.accountId}`;
return `aws-iam-role-${this.accountId}-${this.providerId ?? 0}`;
}

async run(): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ import { ARN } from 'link2aws';
* Provides entities from AWS IAM User service.
*/
export class AWSIAMUserProvider extends AWSEntityProvider {
static fromConfig(config: Config, options: { logger: winston.Logger }) {
static fromConfig(
config: Config,
options: { logger: winston.Logger; providerId?: string },
) {
const accountId = config.getString('accountId');
const roleArn = config.getString('roleArn');
const externalId = config.getOptionalString('externalId');
Expand All @@ -40,7 +43,7 @@ export class AWSIAMUserProvider extends AWSEntityProvider {
}

getProviderName(): string {
return `aws-iam-user-${this.accountId}`;
return `aws-iam-user-${this.accountId}-${this.providerId ?? 0}`;
}

async run(): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ describe('AWSLambdaFunctionProvider', () => {
'amazon.com/lambda-function-arn':
'arn:aws:lambda:eu-west-1:123456789012:function:my-function',
'backstage.io/managed-by-location':
'aws-lambda-function-123456789012:arn:aws:iam::123456789012:role/role1',
'aws-lambda-function-123456789012-0:arn:aws:iam::123456789012:role/role1',
'backstage.io/managed-by-origin-location':
'aws-lambda-function-123456789012:arn:aws:iam::123456789012:role/role1',
'aws-lambda-function-123456789012-0:arn:aws:iam::123456789012:role/role1',
'backstage.io/view-url':
'https://eu-west-1.console.aws.amazon.com/lambda/home?region=eu-west-1#/functions/my-function',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ import { ARN } from 'link2aws';
* Provides entities from AWS Lambda Function service.
*/
export class AWSLambdaFunctionProvider extends AWSEntityProvider {
static fromConfig(config: Config, options: { logger: winston.Logger }) {
static fromConfig(
config: Config,
options: { logger: winston.Logger; providerId?: string },
) {
const accountId = config.getString('accountId');
const roleArn = config.getString('roleArn');
const externalId = config.getOptionalString('externalId');
Expand All @@ -43,7 +46,7 @@ export class AWSLambdaFunctionProvider extends AWSEntityProvider {
}

getProviderName(): string {
return `aws-lambda-function-${this.accountId}`;
return `aws-lambda-function-${this.accountId}-${this.providerId ?? 0}`;
}

async run(): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ import { ARN } from 'link2aws';
* Provides entities from AWS S3 Bucket service.
*/
export class AWSS3BucketProvider extends AWSEntityProvider {
static fromConfig(config: Config, options: { logger: winston.Logger }) {
static fromConfig(
config: Config,
options: { logger: winston.Logger; providerId?: string },
) {
const accountId = config.getString('accountId');
const roleArn = config.getString('roleArn');
const externalId = config.getOptionalString('externalId');
Expand All @@ -40,7 +43,7 @@ export class AWSS3BucketProvider extends AWSEntityProvider {
}

getProviderName(): string {
return `aws-s3-bucket-${this.accountId}`;
return `aws-s3-bucket-${this.accountId}-${this.providerId ?? 0}`;
}

async run(): Promise<void> {
Expand Down

0 comments on commit 08702a0

Please sign in to comment.