Skip to content

Commit

Permalink
Add 'aws-cdk/x.y.z' user agent to SDK
Browse files Browse the repository at this point in the history
This fixes aws#11
  • Loading branch information
rix0rrr authored Jun 7, 2018
1 parent a9d2d3c commit 5a33b82
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules
lerna-debug.log
dist
pack
.BUILD_COMPLETED
29 changes: 25 additions & 4 deletions packages/aws-cdk-toolkit/lib/api/util/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,46 @@ export class SDK {
private defaultAccountFetched = false;
private defaultAccountId?: string = undefined;
private credentialSources: CredentialProviderSource[];
private readonly userAgent: string;

constructor() {
this.credentialSources = PluginHost.instance.credentialProviderSources;

// Find the package.json from the main toolkit
const pkg = (require.main as any).require('../package.json');
this.userAgent = `${pkg.name}/${pkg.version}`;
}

public async cloudFormation(environment: Environment, mode: Mode): Promise<CloudFormation> {
return new CloudFormation({ region: environment.region, credentialProvider: await this.getCredentialProvider(environment.account, mode) });
return new CloudFormation({
region: environment.region,
credentialProvider: await this.getCredentialProvider(environment.account, mode),
customUserAgent: this.userAgent
});
}

public async ec2(awsAccountId: string | undefined, region: string | undefined, mode: Mode): Promise<EC2> {
return new EC2({ region, credentialProvider: await this.getCredentialProvider(awsAccountId, mode) });
return new EC2({
region,
credentialProvider: await this.getCredentialProvider(awsAccountId, mode),
customUserAgent: this.userAgent
});
}

public async ssm(awsAccountId: string | undefined, region: string | undefined, mode: Mode): Promise<SSM> {
return new SSM({ region, credentialProvider: await this.getCredentialProvider(awsAccountId, mode) });
return new SSM({
region,
credentialProvider: await this.getCredentialProvider(awsAccountId, mode),
customUserAgent: this.userAgent
});
}

public async s3(environment: Environment, mode: Mode): Promise<S3> {
return new S3({ region: environment.region, credentialProvider: await this.getCredentialProvider(environment.account, mode) });
return new S3({
region: environment.region,
credentialProvider: await this.getCredentialProvider(environment.account, mode),
customUserAgent: this.userAgent
});
}

public defaultRegion() {
Expand Down

0 comments on commit 5a33b82

Please sign in to comment.