Skip to content

Commit

Permalink
Merge pull request #209 from BenjiTheC/main
Browse files Browse the repository at this point in the history
feat: add custom user agent header string in AWS SDK clients
  • Loading branch information
BenjiTheC authored May 9, 2024
2 parents 4ae0e18 + ea3dea3 commit 2d96c7e
Show file tree
Hide file tree
Showing 34 changed files with 315 additions and 47 deletions.
173 changes: 138 additions & 35 deletions source/common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion source/common/config/rush/repo-state.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// DO NOT MODIFY THIS FILE MANUALLY BUT DO COMMIT IT. It is generated and used by Rush.
{
"pnpmShrinkwrapHash": "f85cc14f59c4c9b6abdd1cf80944d1105fcb45bf",
"pnpmShrinkwrapHash": "fa2b3bdcf3e13e230c0ca3e9c6f094f5f0042c31",
"preferredVersionsHash": "14c05a7722342014cec64c4bef7d9bed0d0b7b7f"
}
4 changes: 4 additions & 0 deletions source/packages/libraries/core/attribution/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: ["@awssolutions/eslint-config-custom"],
};
25 changes: 25 additions & 0 deletions source/packages/libraries/core/attribution/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "@awssolutions/cdf-attribution",
"version": "0.0.0",
"description": "",
"main": "dist/index.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"clean": "npx shx rm -rf dist *.tsbuildinfo .rush .nyc_output *.log",
"lint": "npx eslint . --ext '.ts'",
"build": "npx tsc -p tsconfig.json",
"test": "rushx lint"
},
"devDependencies": {
"@awssolutions/eslint-config-custom": "workspace:~0.0.0",
"@types/node": "^18.17.0",
"typescript": "4.2.4",
"@typescript-eslint/eslint-plugin": "6.2.0"
},
"license": "ISC",
"dependencies": {
"@awssolutions/cdf-version": "workspace:~0.0.0",
"@types/node": "^18.17.0"
}
}
7 changes: 7 additions & 0 deletions source/packages/libraries/core/attribution/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { version } from '@awssolutions/cdf-version';

const ATTRIBUTION_ID = '99CF47E5-1F4E-4DB2-AB43-0E975D0C7888';

export function getCustomUserAgent(suffix: string): string {
return `awssolutions/${ATTRIBUTION_ID}_${version}_${suffix}`;
}
10 changes: 10 additions & 0 deletions source/packages/libraries/core/attribution/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.libraries.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
},
"references": [],
"include": ["src"],
"exclude": ["node_modules", "dist"]
}
5 changes: 3 additions & 2 deletions source/packages/libraries/core/version/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
"clean": "npx shx rm -rf dist *.tsbuildinfo .rush .nyc_output *.log",
"lint": "npx eslint . --ext '.ts'",
"build": "npx ts-node --swc scripts/compile.ts",
"test": "rushx lint && jest --silent --passWithNoTests --maxWorkers=$JEST_MAX_WORKERS"
"test": "rushx lint"
},
"devDependencies": {
"@awssolutions/eslint-config-custom": "workspace:~0.0.0",
"@types/node": "^18.17.0",
"typescript": "4.2.4",
"ts-morph": "~22.0.0"
"ts-morph": "~22.0.0",
"@typescript-eslint/eslint-plugin": "6.2.0"
},
"license": "ISC",
"dependencies": {
Expand Down
3 changes: 3 additions & 0 deletions source/packages/services/assetlibrary-export/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,8 @@
"typescript": "4.2.4",
"winston": "3.2.1",
"winston-transport": "4.3.0"
},
"dependencies": {
"@awssolutions/cdf-attribution": "workspace:~0.0.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import 'reflect-metadata';

import '@awssolutions/cdf-config-inject';
import { getCustomUserAgent } from '@awssolutions/cdf-attribution';
import { Container, decorate, injectable, interfaces } from 'inversify';

import AWS from 'aws-sdk';
Expand Down Expand Up @@ -89,7 +90,10 @@ decorate(injectable(), AWS.S3);
container.bind<interfaces.Factory<AWS.S3>>(TYPES.S3Factory).toFactory<AWS.S3>(() => {
return () => {
if (!container.isBound(TYPES.S3)) {
const s3 = new AWS.S3({ region: process.env.AWS_REGION });
const s3 = new AWS.S3({
region: process.env.AWS_REGION,
customUserAgent: getCustomUserAgent('ale'),
});
container.bind<AWS.S3>(TYPES.S3).toConstantValue(s3);
}
return container.get<AWS.S3>(TYPES.S3);
Expand Down
3 changes: 3 additions & 0 deletions source/packages/services/assetlibrary/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,8 @@
"typescript": "4.2.4",
"winston": "3.3.3",
"winston-transport": "4.4.0"
},
"dependencies": {
"@awssolutions/cdf-attribution": "workspace:~0.0.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'reflect-metadata';

import '@awssolutions/cdf-config-inject';

import { getCustomUserAgent } from '@awssolutions/cdf-attribution';
import { Container, decorate, injectable, interfaces } from 'inversify';

import { NodeAssembler } from '../data/assembler';
Expand Down Expand Up @@ -66,6 +67,7 @@ container
const iotData = new AWS.IotData({
region: process.env.AWS_REGION,
endpoint: `https://${process.env.AWS_IOT_ENDPOINT}`,
customUserAgent: getCustomUserAgent('asl'),
});
container.bind<AWS.IotData>(TYPES.IotData).toConstantValue(iotData);
}
Expand Down
3 changes: 3 additions & 0 deletions source/packages/services/assetlibraryhistory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,8 @@
"typescript": "4.2.4",
"winston": "3.3.3",
"winston-transport": "4.4.0"
},
"dependencies": {
"@awssolutions/cdf-attribution": "workspace:~0.0.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'reflect-metadata';

import '@awssolutions/cdf-config-inject';

import { getCustomUserAgent } from '@awssolutions/cdf-attribution';
import { Container, decorate, injectable, interfaces } from 'inversify';

// Note: importing @controller's carries out a one time inversify metadata generation...
Expand Down Expand Up @@ -75,7 +76,10 @@ container
.toFactory<AWS.DynamoDB.DocumentClient>(() => {
return () => {
if (!container.isBound(TYPES.DocumentClient)) {
const dc = new AWS.DynamoDB.DocumentClient({ region: process.env.AWS_REGION });
const dc = new AWS.DynamoDB.DocumentClient({
region: process.env.AWS_REGION,
customUserAgent: getCustomUserAgent('alh'),
});
container
.bind<AWS.DynamoDB.DocumentClient>(TYPES.DocumentClient)
.toConstantValue(dc);
Expand Down
3 changes: 3 additions & 0 deletions source/packages/services/bulkcerts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,8 @@
"uuid": "8.3.2",
"winston": "3.3.3",
"winston-transport": "4.4.0"
},
"dependencies": {
"@awssolutions/cdf-attribution": "workspace:~0.0.0"
}
}
5 changes: 5 additions & 0 deletions source/packages/services/bulkcerts/src/di/inversify.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import 'reflect-metadata';

import '@awssolutions/cdf-config-inject';
import { getCustomUserAgent } from '@awssolutions/cdf-attribution';
import { Container, decorate, injectable, interfaces } from 'inversify';

import '../certificates/certificates.controller';
Expand Down Expand Up @@ -85,6 +86,10 @@ container
.to(CertificatesTaskDao)
.inSingletonScope();

AWS.config.update({
customUserAgent: getCustomUserAgent('bct'),
});

// for 3rd party objects, we need to use factory injectors
// DynamoDB
decorate(injectable(), AWS.DynamoDB);
Expand Down
3 changes: 3 additions & 0 deletions source/packages/services/certificateactivator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,8 @@
"typescript": "4.2.4",
"winston": "3.3.3",
"winston-transport": "4.4.0"
},
"dependencies": {
"@awssolutions/cdf-attribution": "workspace:~0.0.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import 'reflect-metadata';

import '@awssolutions/cdf-config-inject';
import { getCustomUserAgent } from '@awssolutions/cdf-attribution';
import { Container, decorate, injectable, interfaces } from 'inversify';

import { assetLibraryContainerModule } from '@awssolutions/cdf-assetlibrary-client';
Expand All @@ -34,6 +35,10 @@ container.bind<string>('aws.s3.crl.key').toConstantValue(process.env.AWS_S3_CRL_

container.bind<ActivationService>(TYPES.ActivationService).to(ActivationService);

AWS.config.update({
customUserAgent: getCustomUserAgent('cta'),
});

// for 3rd party objects, we need to use factory injectors
decorate(injectable(), AWS.Iot);
container.bind<interfaces.Factory<AWS.Iot>>(TYPES.IotFactory).toFactory<AWS.Iot>(() => {
Expand Down
3 changes: 3 additions & 0 deletions source/packages/services/certificatevendor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,8 @@
"typescript": "4.2.4",
"winston": "3.3.3",
"winston-transport": "4.4.0"
},
"dependencies": {
"@awssolutions/cdf-attribution": "workspace:~0.0.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'reflect-metadata';

import '@awssolutions/cdf-config-inject';

import { getCustomUserAgent } from '@awssolutions/cdf-attribution';
import { Container, decorate, injectable, interfaces } from 'inversify';

import { assetLibraryContainerModule } from '@awssolutions/cdf-assetlibrary-client';
Expand Down Expand Up @@ -100,6 +101,10 @@ if (registry === 'AssetLibrary') {

container.bind<CertificateService>(TYPES.CertificateService).to(CertificateService);

AWS.config.update({
customUserAgent: getCustomUserAgent('ctv'),
});

// for 3rd party objects, we need to use factory injectors
decorate(injectable(), AWS.Iot);
container.bind<interfaces.Factory<AWS.Iot>>(TYPES.IotFactory).toFactory<AWS.Iot>(() => {
Expand Down
3 changes: 3 additions & 0 deletions source/packages/services/command-and-control/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,8 @@
"typescript": "4.2.4",
"winston": "3.3.3",
"winston-transport": "4.4.0"
},
"dependencies": {
"@awssolutions/cdf-attribution": "workspace:~0.0.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import AWS from 'aws-sdk';
import { assetLibraryContainerModule } from '@awssolutions/cdf-assetlibrary-client';
import { provisioningContainerModule } from '@awssolutions/cdf-provisioning-client';
import { thingListBuilderContainerModule } from '@awssolutions/cdf-thing-list-builder';
import { getCustomUserAgent } from '@awssolutions/cdf-attribution';
import { Container, decorate, injectable, interfaces } from 'inversify';
import { CommandsAssembler } from '../commands/commands.assembler';
import { CommandsDao } from '../commands/commands.dao';
Expand Down Expand Up @@ -112,7 +113,10 @@ container.bind<CheckBulkProvisioningAction>(TYPES.CheckBulkProvisioningAction).t

container.bind<DynamoDbUtils>(TYPES.DynamoDbUtils).to(DynamoDbUtils);

AWS.config.update({ region: process.env.AWS_REGION });
AWS.config.update({
region: process.env.AWS_REGION,
customUserAgent: getCustomUserAgent('cnc'),
});

// for 3rd party objects, we need to use factory injectors
decorate(injectable(), AWS.DynamoDB.DocumentClient);
Expand Down
3 changes: 3 additions & 0 deletions source/packages/services/device-patcher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,8 @@
"uuid": "8.3.2",
"winston": "3.3.3",
"winston-transport": "4.4.0"
},
"dependencies": {
"@awssolutions/cdf-attribution": "workspace:~0.0.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* and limitations under the License. *
*********************************************************************************************************************/
import '@awssolutions/cdf-config-inject';
import { getCustomUserAgent } from '@awssolutions/cdf-attribution';
import { Container, decorate, injectable, interfaces } from 'inversify';
import 'reflect-metadata';

Expand Down Expand Up @@ -98,6 +99,10 @@ container.bind<ActivationDao>(TYPES.ActivationDao).to(ActivationDao).inSingleton
container.bind<DynamoDbUtils>(TYPES.DynamoDbUtils).to(DynamoDbUtils).inSingletonScope();
container.bind<ExpressionParser>(TYPES.ExpressionParser).to(ExpressionParser).inSingletonScope();

AWS.config.update({
customUserAgent: getCustomUserAgent('dvp'),
});

// for 3rd party objects, we need to use factory injectors
// DynamoDB
decorate(injectable(), AWS.DynamoDB.DocumentClient);
Expand Down
3 changes: 3 additions & 0 deletions source/packages/services/events-alerts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,8 @@
"uuid": "8.3.2",
"winston": "3.3.3",
"winston-transport": "4.4.0"
},
"dependencies": {
"@awssolutions/cdf-attribution": "workspace:~0.0.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'reflect-metadata';

import '@awssolutions/cdf-config-inject';

import { getCustomUserAgent } from '@awssolutions/cdf-attribution';
import { Container, decorate, injectable, interfaces } from 'inversify';

import { AlertAssembler } from '../alerts/assembler';
Expand Down Expand Up @@ -58,6 +59,10 @@ container

container.bind<AlertAssembler>(TYPES.AlertAssembler).to(AlertAssembler).inSingletonScope();

AWS.config.update({
customUserAgent: getCustomUserAgent('ntfa'),
});

// for 3rd party objects, we need to use factory injectors

decorate(injectable(), AWS.SNS);
Expand Down
3 changes: 3 additions & 0 deletions source/packages/services/events-processor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,8 @@
"uuid": "8.3.2",
"winston": "3.3.3",
"winston-transport": "4.4.0"
},
"dependencies": {
"@awssolutions/cdf-attribution": "workspace:~0.0.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'reflect-metadata';

import '@awssolutions/cdf-config-inject';

import { getCustomUserAgent } from '@awssolutions/cdf-attribution';
import { Container, decorate, injectable, interfaces } from 'inversify';

// Note: importing @controller's carries out a one time inversify metadata generation...
Expand Down Expand Up @@ -153,6 +154,10 @@ container.bind<PushTarget>(TYPES.PushTarget).to(PushTarget).inSingletonScope();

container.bind<DynamoDbUtils>(TYPES.DynamoDbUtils).to(DynamoDbUtils).inSingletonScope();

AWS.config.update({
customUserAgent: getCustomUserAgent('ntfp'),
});

// for 3rd party objects, we need to use factory injectors

decorate(injectable(), AWS.DynamoDB);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,8 @@
"typescript": "4.2.4",
"winston": "3.3.3",
"winston-transport": "4.4.0"
},
"dependencies": {
"@awssolutions/cdf-attribution": "workspace:~0.0.0"
}
}
Loading

0 comments on commit 2d96c7e

Please sign in to comment.