@pristine-ts/aws 0.0.275 → 0.0.276
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/cjs/clients/clients.js +1 -0
- package/dist/lib/cjs/clients/clients.js.map +1 -1
- package/dist/lib/cjs/clients/secrets-manager.client.js +100 -0
- package/dist/lib/cjs/clients/secrets-manager.client.js.map +1 -0
- package/dist/lib/cjs/errors/errors.js +1 -0
- package/dist/lib/cjs/errors/errors.js.map +1 -1
- package/dist/lib/cjs/errors/get-secret-secrets-manager.error.js +22 -0
- package/dist/lib/cjs/errors/get-secret-secrets-manager.error.js.map +1 -0
- package/dist/lib/cjs/interfaces/interfaces.js +1 -0
- package/dist/lib/cjs/interfaces/interfaces.js.map +1 -1
- package/dist/lib/cjs/interfaces/secrets-manager-client.interface.js +3 -0
- package/dist/lib/cjs/interfaces/secrets-manager-client.interface.js.map +1 -0
- package/dist/lib/esm/clients/clients.js +1 -0
- package/dist/lib/esm/clients/clients.js.map +1 -1
- package/dist/lib/esm/clients/secrets-manager.client.js +97 -0
- package/dist/lib/esm/clients/secrets-manager.client.js.map +1 -0
- package/dist/lib/esm/errors/errors.js +1 -0
- package/dist/lib/esm/errors/errors.js.map +1 -1
- package/dist/lib/esm/errors/get-secret-secrets-manager.error.js +18 -0
- package/dist/lib/esm/errors/get-secret-secrets-manager.error.js.map +1 -0
- package/dist/lib/esm/interfaces/interfaces.js +1 -0
- package/dist/lib/esm/interfaces/interfaces.js.map +1 -1
- package/dist/lib/esm/interfaces/secrets-manager-client.interface.js +2 -0
- package/dist/lib/esm/interfaces/secrets-manager-client.interface.js.map +1 -0
- package/dist/types/clients/clients.d.ts +1 -0
- package/dist/types/clients/secrets-manager.client.d.ts +29 -0
- package/dist/types/errors/errors.d.ts +1 -0
- package/dist/types/errors/get-secret-secrets-manager.error.d.ts +11 -0
- package/dist/types/interfaces/interfaces.d.ts +1 -0
- package/dist/types/interfaces/secrets-manager-client.interface.d.ts +27 -0
- package/package.json +8 -7
|
@@ -19,6 +19,7 @@ __exportStar(require("./cloudfront.client"), exports);
|
|
|
19
19
|
__exportStar(require("./dynamodb.client"), exports);
|
|
20
20
|
__exportStar(require("./event-bridge.client"), exports);
|
|
21
21
|
__exportStar(require("./s3.client"), exports);
|
|
22
|
+
__exportStar(require("./secrets-manager.client"), exports);
|
|
22
23
|
__exportStar(require("./ses.client"), exports);
|
|
23
24
|
__exportStar(require("./sqs.client"), exports);
|
|
24
25
|
//# sourceMappingURL=clients.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clients.js","sourceRoot":"","sources":["../../../../src/clients/clients.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAwC;AACxC,sDAAoC;AACpC,oDAAkC;AAClC,wDAAsC;AACtC,8CAA4B;AAC5B,+CAA6B;AAC7B,+CAA6B"}
|
|
1
|
+
{"version":3,"file":"clients.js","sourceRoot":"","sources":["../../../../src/clients/clients.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAwC;AACxC,sDAAoC;AACpC,oDAAkC;AAClC,wDAAsC;AACtC,8CAA4B;AAC5B,2DAAyC;AACzC,+CAA6B;AAC7B,+CAA6B"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.SecretsManagerClient = void 0;
|
|
25
|
+
const aws_module_keyname_1 = require("../aws.module.keyname");
|
|
26
|
+
const common_1 = require("@pristine-ts/common");
|
|
27
|
+
const tsyringe_1 = require("tsyringe");
|
|
28
|
+
const client_secrets_manager_1 = require("@aws-sdk/client-secrets-manager");
|
|
29
|
+
const get_secret_secrets_manager_error_1 = require("../errors/get-secret-secrets-manager.error");
|
|
30
|
+
let SecretsManagerClient = class SecretsManagerClient {
|
|
31
|
+
/**
|
|
32
|
+
* The client to use to interact with AWS SES. It is a wrapper around the SESClient of @aws-sdk/client-ses.
|
|
33
|
+
* @param logHandler The log handler used to output logs.
|
|
34
|
+
* @param region The aws region for which the client will be used.
|
|
35
|
+
*/
|
|
36
|
+
constructor(logHandler, region) {
|
|
37
|
+
this.logHandler = logHandler;
|
|
38
|
+
this.region = region;
|
|
39
|
+
}
|
|
40
|
+
getClient(endpoint) {
|
|
41
|
+
return new client_secrets_manager_1.SecretsManagerClient({
|
|
42
|
+
region: this.region,
|
|
43
|
+
endpoint: endpoint !== null && endpoint !== void 0 ? endpoint : undefined,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* This retrieves a secret from the secret manager
|
|
48
|
+
*
|
|
49
|
+
* @param secretName
|
|
50
|
+
*/
|
|
51
|
+
getSecret(secretName) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
const command = new client_secrets_manager_1.GetSecretValueCommand({
|
|
54
|
+
SecretId: secretName,
|
|
55
|
+
});
|
|
56
|
+
const response = yield this.getClient().send(command);
|
|
57
|
+
const secretString = response.SecretString;
|
|
58
|
+
if (!secretString) {
|
|
59
|
+
const message = `No value for this parameter: '${secretName}'.`;
|
|
60
|
+
this.logHandler.error(message, { secretName });
|
|
61
|
+
throw new get_secret_secrets_manager_error_1.GetSecretSecretsManagerError(message);
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
return JSON.parse(secretString);
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
const message = `Couldn't parse the secret as a JSON object: '${secretName}'.`;
|
|
68
|
+
this.logHandler.error(message, { secretName });
|
|
69
|
+
throw new get_secret_secrets_manager_error_1.GetSecretSecretsManagerError(message);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* This retrieves a secret key from a secret from the secret manager
|
|
75
|
+
*
|
|
76
|
+
* @param secretName
|
|
77
|
+
* @param key The key in the JSON object of the secret
|
|
78
|
+
*/
|
|
79
|
+
getSecretKey(secretName, key) {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
const secret = yield this.getSecret(secretName);
|
|
82
|
+
if (secret.hasOwnProperty(key) === false) {
|
|
83
|
+
const message = `Cannot find jsonKey '${key}' in the secret: '${secretName}'.`;
|
|
84
|
+
this.logHandler.error(message, { secretName, key });
|
|
85
|
+
throw new get_secret_secrets_manager_error_1.GetSecretSecretsManagerError(message);
|
|
86
|
+
}
|
|
87
|
+
return secret[key];
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
exports.SecretsManagerClient = SecretsManagerClient;
|
|
92
|
+
exports.SecretsManagerClient = SecretsManagerClient = __decorate([
|
|
93
|
+
(0, common_1.tag)("SecretsManagerClientInterface"),
|
|
94
|
+
(0, common_1.moduleScoped)(aws_module_keyname_1.AwsModuleKeyname),
|
|
95
|
+
(0, tsyringe_1.injectable)(),
|
|
96
|
+
__param(0, (0, tsyringe_1.inject)("LogHandlerInterface")),
|
|
97
|
+
__param(1, (0, tsyringe_1.inject)("%pristine.aws.region%")),
|
|
98
|
+
__metadata("design:paramtypes", [Object, String])
|
|
99
|
+
], SecretsManagerClient);
|
|
100
|
+
//# sourceMappingURL=secrets-manager.client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets-manager.client.js","sourceRoot":"","sources":["../../../../src/clients/secrets-manager.client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,8DAAuD;AACvD,gDAAsD;AACtD,uCAA4C;AAG5C,4EAAuH;AACvH,iGAAwF;AAKjF,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAC7B;;;;OAIG;IACH,YACoD,UAA+B,EAC7B,MAAc;QADhB,eAAU,GAAV,UAAU,CAAqB;QAC7B,WAAM,GAAN,MAAM,CAAQ;IAEpE,CAAC;IAED,SAAS,CAAC,QAAiB;QACvB,OAAO,IAAI,6CAAuB,CAAC;YAC/B,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,QAAQ,EAAE,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,SAAS;SAClC,CAAC,CAAC;IACP,CAAC;IAED;;;;OAIG;IACG,SAAS,CAAC,UAAkB;;YAC9B,MAAM,OAAO,GAA0B,IAAI,8CAAqB,CAAC;gBAC7D,QAAQ,EAAE,UAAU;aACvB,CAA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A+B,CAAC;IACpC,IAAA,qBAAY,EAAC,qCAAgB,CAAC;IAC9B,IAAA,qBAAU,GAAE;IAQJ,WAAA,IAAA,iBAAM,EAAC,qBAAqB,CAAC,CAAA;IAC7B,WAAA,IAAA,iBAAM,EAAC,uBAAuB,CAAC,CAAA;;GAR3B,oBAAoB,CAoEhC"}
|
|
@@ -18,6 +18,7 @@ __exportStar(require("./dynamodb.error"), exports);
|
|
|
18
18
|
__exportStar(require("./dynamodb-item-already-exists.error"), exports);
|
|
19
19
|
// We do not export dynamodb-item-not-found.error as it should not be used outside of this module
|
|
20
20
|
// export * from "./dynamodb-item-not-found.error";
|
|
21
|
+
__exportStar(require("./get-secret-secrets-manager.error"), exports);
|
|
21
22
|
__exportStar(require("./dynamodb-table-not-found.error"), exports);
|
|
22
23
|
__exportStar(require("./dynamodb-validation.error"), exports);
|
|
23
24
|
__exportStar(require("./event-bridge-send-message.error"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../src/errors/errors.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,uEAAqD;AACrD,iGAAiG;AACjG,mDAAmD;AACnD,mEAAiD;AACjD,8DAA4C;AAC5C,oEAAkD;AAClD,uDAAqC;AACrC,mDAAiC;AACjC,2DAAyC"}
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../src/errors/errors.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,uEAAqD;AACrD,iGAAiG;AACjG,mDAAmD;AACnD,qEAAmD;AACnD,mEAAiD;AACjD,8DAA4C;AAC5C,oEAAkD;AAClD,uDAAqC;AACrC,mDAAiC;AACjC,2DAAyC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetSecretSecretsManagerError = void 0;
|
|
4
|
+
const common_1 = require("@pristine-ts/common");
|
|
5
|
+
/**
|
|
6
|
+
* This Error represents an error when trying to get a secret from Secrets Manager
|
|
7
|
+
*/
|
|
8
|
+
class GetSecretSecretsManagerError extends common_1.LoggableError {
|
|
9
|
+
/**
|
|
10
|
+
* This Error represents an error when trying to get a secret from Secrets Manager
|
|
11
|
+
* @param message The message to throw
|
|
12
|
+
*/
|
|
13
|
+
constructor(message) {
|
|
14
|
+
super(message);
|
|
15
|
+
// Set the prototype explicitly.
|
|
16
|
+
// As specified in the documentation in TypeScript
|
|
17
|
+
// https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work
|
|
18
|
+
Object.setPrototypeOf(this, GetSecretSecretsManagerError.prototype);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.GetSecretSecretsManagerError = GetSecretSecretsManagerError;
|
|
22
|
+
//# sourceMappingURL=get-secret-secrets-manager.error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-secret-secrets-manager.error.js","sourceRoot":"","sources":["../../../../src/errors/get-secret-secrets-manager.error.ts"],"names":[],"mappings":";;;AAAA,gDAAkD;AAElD;;GAEG;AACH,MAAa,4BAA6B,SAAQ,sBAAa;IAE3D;;;OAGG;IACH,YAAmB,OAAe;QAC9B,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,gCAAgC;QAChC,kDAAkD;QAClD,gIAAgI;QAChI,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,4BAA4B,CAAC,SAAS,CAAC,CAAC;IACxE,CAAC;CACJ;AAdD,oEAcC"}
|
|
@@ -19,6 +19,7 @@ __exportStar(require("./cloudfront-client.interface"), exports);
|
|
|
19
19
|
__exportStar(require("./dynamodb-client.interface"), exports);
|
|
20
20
|
__exportStar(require("./event-bridge-client.interface"), exports);
|
|
21
21
|
__exportStar(require("./s3-client.interface"), exports);
|
|
22
|
+
__exportStar(require("./secrets-manager-client.interface"), exports);
|
|
22
23
|
__exportStar(require("./ses-client.interface"), exports);
|
|
23
24
|
__exportStar(require("./sqs-client.interface"), exports);
|
|
24
25
|
//# sourceMappingURL=interfaces.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../src/interfaces/interfaces.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oEAAkD;AAClD,gEAA8C;AAC9C,8DAA4C;AAC5C,kEAAgD;AAChD,wDAAsC;AACtC,yDAAuC;AACvC,yDAAuC"}
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../src/interfaces/interfaces.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oEAAkD;AAClD,gEAA8C;AAC9C,8DAA4C;AAC5C,kEAAgD;AAChD,wDAAsC;AACtC,qEAAmD;AACnD,yDAAuC;AACvC,yDAAuC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets-manager-client.interface.js","sourceRoot":"","sources":["../../../../src/interfaces/secrets-manager-client.interface.ts"],"names":[],"mappings":""}
|
|
@@ -3,6 +3,7 @@ export * from "./cloudfront.client";
|
|
|
3
3
|
export * from "./dynamodb.client";
|
|
4
4
|
export * from "./event-bridge.client";
|
|
5
5
|
export * from "./s3.client";
|
|
6
|
+
export * from "./secrets-manager.client";
|
|
6
7
|
export * from "./ses.client";
|
|
7
8
|
export * from "./sqs.client";
|
|
8
9
|
//# sourceMappingURL=clients.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clients.js","sourceRoot":"","sources":["../../../../src/clients/clients.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"clients.js","sourceRoot":"","sources":["../../../../src/clients/clients.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,0BAA0B,CAAC;AACzC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
import { AwsModuleKeyname } from "../aws.module.keyname";
|
|
23
|
+
import { moduleScoped, tag } from "@pristine-ts/common";
|
|
24
|
+
import { inject, injectable } from "tsyringe";
|
|
25
|
+
import { GetSecretValueCommand, SecretsManagerClient as AWSSecretsManagerClient } from "@aws-sdk/client-secrets-manager";
|
|
26
|
+
import { GetSecretSecretsManagerError } from "../errors/get-secret-secrets-manager.error";
|
|
27
|
+
let SecretsManagerClient = class SecretsManagerClient {
|
|
28
|
+
/**
|
|
29
|
+
* The client to use to interact with AWS SES. It is a wrapper around the SESClient of @aws-sdk/client-ses.
|
|
30
|
+
* @param logHandler The log handler used to output logs.
|
|
31
|
+
* @param region The aws region for which the client will be used.
|
|
32
|
+
*/
|
|
33
|
+
constructor(logHandler, region) {
|
|
34
|
+
this.logHandler = logHandler;
|
|
35
|
+
this.region = region;
|
|
36
|
+
}
|
|
37
|
+
getClient(endpoint) {
|
|
38
|
+
return new AWSSecretsManagerClient({
|
|
39
|
+
region: this.region,
|
|
40
|
+
endpoint: endpoint !== null && endpoint !== void 0 ? endpoint : undefined,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* This retrieves a secret from the secret manager
|
|
45
|
+
*
|
|
46
|
+
* @param secretName
|
|
47
|
+
*/
|
|
48
|
+
getSecret(secretName) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
const command = new GetSecretValueCommand({
|
|
51
|
+
SecretId: secretName,
|
|
52
|
+
});
|
|
53
|
+
const response = yield this.getClient().send(command);
|
|
54
|
+
const secretString = response.SecretString;
|
|
55
|
+
if (!secretString) {
|
|
56
|
+
const message = `No value for this parameter: '${secretName}'.`;
|
|
57
|
+
this.logHandler.error(message, { secretName });
|
|
58
|
+
throw new GetSecretSecretsManagerError(message);
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
return JSON.parse(secretString);
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
const message = `Couldn't parse the secret as a JSON object: '${secretName}'.`;
|
|
65
|
+
this.logHandler.error(message, { secretName });
|
|
66
|
+
throw new GetSecretSecretsManagerError(message);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* This retrieves a secret key from a secret from the secret manager
|
|
72
|
+
*
|
|
73
|
+
* @param secretName
|
|
74
|
+
* @param key The key in the JSON object of the secret
|
|
75
|
+
*/
|
|
76
|
+
getSecretKey(secretName, key) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
const secret = yield this.getSecret(secretName);
|
|
79
|
+
if (secret.hasOwnProperty(key) === false) {
|
|
80
|
+
const message = `Cannot find jsonKey '${key}' in the secret: '${secretName}'.`;
|
|
81
|
+
this.logHandler.error(message, { secretName, key });
|
|
82
|
+
throw new GetSecretSecretsManagerError(message);
|
|
83
|
+
}
|
|
84
|
+
return secret[key];
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
SecretsManagerClient = __decorate([
|
|
89
|
+
tag("SecretsManagerClientInterface"),
|
|
90
|
+
moduleScoped(AwsModuleKeyname),
|
|
91
|
+
injectable(),
|
|
92
|
+
__param(0, inject("LogHandlerInterface")),
|
|
93
|
+
__param(1, inject("%pristine.aws.region%")),
|
|
94
|
+
__metadata("design:paramtypes", [Object, String])
|
|
95
|
+
], SecretsManagerClient);
|
|
96
|
+
export { SecretsManagerClient };
|
|
97
|
+
//# sourceMappingURL=secrets-manager.client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets-manager.client.js","sourceRoot":"","sources":["../../../../src/clients/secrets-manager.client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,uBAAuB,CAAC;AACvD,OAA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,UAAU,IAAI,CAAC;gBAC/E,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,EAAE,EAAC,UAAU,EAAC,CAAC,CAAC;gBAE7C,MAAM,IAAI,4BAA4B,CAAC,OAAO,CAAC,CAAC;aACnD;QACL,CAAC;KAAA;IAED;;;;;OAKG;IACG,YAAY,CAAC,UAAkB,EAAE,GAAW;;YAC9C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;YAEhD,IAAI,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,KAAK,EAAE;gBACtC,MAAM,OAAO,GAAG,wBAAwB,GAAG,qBAAqB,UAAU,IAAI,CAAC;gBAC/E,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,EAAE,EAAC,UAAU,EAAE,GAAG,EAAC,CAAC,CAAC;gBAClD,MAAM,IAAI,4BAA4B,CAAC,OAAO,CAAC,CAAC;aACnD;YAED,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;KAAA;CAEJ,CAAA;AApEY,oBAAoB;IAHhC,GAAG,CAAC,+BAA+B,CAAC;IACpC,YAAY,CAAC,gBAAgB,CAAC;IAC9B,UAAU,EAAE;IAQJ,WAAA,MAAM,CAAC,qBAAqB,CAAC,CAAA;IAC7B,WAAA,MAAM,CAAC,uBAAuB,CAAC,CAAA;;GAR3B,oBAAoB,CAoEhC"}
|
|
@@ -2,6 +2,7 @@ export * from "./dynamodb.error";
|
|
|
2
2
|
export * from "./dynamodb-item-already-exists.error";
|
|
3
3
|
// We do not export dynamodb-item-not-found.error as it should not be used outside of this module
|
|
4
4
|
// export * from "./dynamodb-item-not-found.error";
|
|
5
|
+
export * from "./get-secret-secrets-manager.error";
|
|
5
6
|
export * from "./dynamodb-table-not-found.error";
|
|
6
7
|
export * from "./dynamodb-validation.error";
|
|
7
8
|
export * from "./event-bridge-send-message.error";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../src/errors/errors.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,sCAAsC,CAAC;AACrD,iGAAiG;AACjG,mDAAmD;AACnD,cAAc,kCAAkC,CAAC;AACjD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mCAAmC,CAAC;AAClD,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC"}
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../src/errors/errors.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,sCAAsC,CAAC;AACrD,iGAAiG;AACjG,mDAAmD;AACnD,cAAc,oCAAoC,CAAC;AACnD,cAAc,kCAAkC,CAAC;AACjD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mCAAmC,CAAC;AAClD,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { LoggableError } from "@pristine-ts/common";
|
|
2
|
+
/**
|
|
3
|
+
* This Error represents an error when trying to get a secret from Secrets Manager
|
|
4
|
+
*/
|
|
5
|
+
export class GetSecretSecretsManagerError extends LoggableError {
|
|
6
|
+
/**
|
|
7
|
+
* This Error represents an error when trying to get a secret from Secrets Manager
|
|
8
|
+
* @param message The message to throw
|
|
9
|
+
*/
|
|
10
|
+
constructor(message) {
|
|
11
|
+
super(message);
|
|
12
|
+
// Set the prototype explicitly.
|
|
13
|
+
// As specified in the documentation in TypeScript
|
|
14
|
+
// https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work
|
|
15
|
+
Object.setPrototypeOf(this, GetSecretSecretsManagerError.prototype);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=get-secret-secrets-manager.error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-secret-secrets-manager.error.js","sourceRoot":"","sources":["../../../../src/errors/get-secret-secrets-manager.error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,qBAAqB,CAAC;AAElD;;GAEG;AACH,MAAM,OAAO,4BAA6B,SAAQ,aAAa;IAE3D;;;OAGG;IACH,YAAmB,OAAe;QAC9B,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,gCAAgC;QAChC,kDAAkD;QAClD,gIAAgI;QAChI,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,4BAA4B,CAAC,SAAS,CAAC,CAAC;IACxE,CAAC;CACJ"}
|
|
@@ -3,6 +3,7 @@ export * from "./cloudfront-client.interface";
|
|
|
3
3
|
export * from "./dynamodb-client.interface";
|
|
4
4
|
export * from "./event-bridge-client.interface";
|
|
5
5
|
export * from "./s3-client.interface";
|
|
6
|
+
export * from "./secrets-manager-client.interface";
|
|
6
7
|
export * from "./ses-client.interface";
|
|
7
8
|
export * from "./sqs-client.interface";
|
|
8
9
|
//# sourceMappingURL=interfaces.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../src/interfaces/interfaces.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAC;AAClD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC"}
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../src/interfaces/interfaces.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAC;AAClD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC;AACtC,cAAc,oCAAoC,CAAC;AACnD,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets-manager-client.interface.js","sourceRoot":"","sources":["../../../../src/interfaces/secrets-manager-client.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { LogHandlerInterface } from "@pristine-ts/logging";
|
|
2
|
+
import { SecretsManagerClientInterface } from "../interfaces/secrets-manager-client.interface";
|
|
3
|
+
import { SecretsManagerClient as AWSSecretsManagerClient } from "@aws-sdk/client-secrets-manager";
|
|
4
|
+
export declare class SecretsManagerClient implements SecretsManagerClientInterface {
|
|
5
|
+
private readonly logHandler;
|
|
6
|
+
private readonly region;
|
|
7
|
+
/**
|
|
8
|
+
* The client to use to interact with AWS SES. It is a wrapper around the SESClient of @aws-sdk/client-ses.
|
|
9
|
+
* @param logHandler The log handler used to output logs.
|
|
10
|
+
* @param region The aws region for which the client will be used.
|
|
11
|
+
*/
|
|
12
|
+
constructor(logHandler: LogHandlerInterface, region: string);
|
|
13
|
+
getClient(endpoint?: string): AWSSecretsManagerClient;
|
|
14
|
+
/**
|
|
15
|
+
* This retrieves a secret from the secret manager
|
|
16
|
+
*
|
|
17
|
+
* @param secretName
|
|
18
|
+
*/
|
|
19
|
+
getSecret(secretName: string): Promise<{
|
|
20
|
+
[key in string]: string;
|
|
21
|
+
}>;
|
|
22
|
+
/**
|
|
23
|
+
* This retrieves a secret key from a secret from the secret manager
|
|
24
|
+
*
|
|
25
|
+
* @param secretName
|
|
26
|
+
* @param key The key in the JSON object of the secret
|
|
27
|
+
*/
|
|
28
|
+
getSecretKey(secretName: string, key: string): Promise<string>;
|
|
29
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from "./dynamodb.error";
|
|
2
2
|
export * from "./dynamodb-item-already-exists.error";
|
|
3
|
+
export * from "./get-secret-secrets-manager.error";
|
|
3
4
|
export * from "./dynamodb-table-not-found.error";
|
|
4
5
|
export * from "./dynamodb-validation.error";
|
|
5
6
|
export * from "./event-bridge-send-message.error";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { LoggableError } from "@pristine-ts/common";
|
|
2
|
+
/**
|
|
3
|
+
* This Error represents an error when trying to get a secret from Secrets Manager
|
|
4
|
+
*/
|
|
5
|
+
export declare class GetSecretSecretsManagerError extends LoggableError {
|
|
6
|
+
/**
|
|
7
|
+
* This Error represents an error when trying to get a secret from Secrets Manager
|
|
8
|
+
* @param message The message to throw
|
|
9
|
+
*/
|
|
10
|
+
constructor(message: string);
|
|
11
|
+
}
|
|
@@ -3,5 +3,6 @@ export * from "./cloudfront-client.interface";
|
|
|
3
3
|
export * from "./dynamodb-client.interface";
|
|
4
4
|
export * from "./event-bridge-client.interface";
|
|
5
5
|
export * from "./s3-client.interface";
|
|
6
|
+
export * from "./secrets-manager-client.interface";
|
|
6
7
|
export * from "./ses-client.interface";
|
|
7
8
|
export * from "./sqs-client.interface";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SESClient } from "@aws-sdk/client-ses";
|
|
2
|
+
/**
|
|
3
|
+
* The SecretsManager Interface defines the methods that a Secrets Manager client must implement.
|
|
4
|
+
* When injecting the SecretsManager client the 'SecretsManagerClientInterface' tag should be used.
|
|
5
|
+
*/
|
|
6
|
+
export interface SecretsManagerClientInterface {
|
|
7
|
+
/**
|
|
8
|
+
* Returns the instantiated SecretsManagerClientInterface from the @aws-sdk/client-secrets-manager library.
|
|
9
|
+
* @param endpoint The endpoint for which the Secrets Manager client is created.
|
|
10
|
+
*/
|
|
11
|
+
getClient(endpoint?: string): SESClient;
|
|
12
|
+
/**
|
|
13
|
+
* This retrieves a secret from the secret manager
|
|
14
|
+
*
|
|
15
|
+
* @param secretName
|
|
16
|
+
*/
|
|
17
|
+
getSecret(secretName: string): Promise<{
|
|
18
|
+
[key in string]: string;
|
|
19
|
+
}>;
|
|
20
|
+
/**
|
|
21
|
+
* This retrieves a secret key from a secret from the secret manager
|
|
22
|
+
*
|
|
23
|
+
* @param secretName
|
|
24
|
+
* @param key The key in the JSON object of the secret
|
|
25
|
+
*/
|
|
26
|
+
getSecretKey(secretName: string, key: string): Promise<string>;
|
|
27
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pristine-ts/aws",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.276",
|
|
4
4
|
"description": "",
|
|
5
5
|
"module": "dist/lib/esm/aws.module.js",
|
|
6
6
|
"main": "dist/lib/cjs/aws.module.js",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"@aws-sdk/client-dynamodb": "^3.441.0",
|
|
23
23
|
"@aws-sdk/client-eventbridge": "^3.441.0",
|
|
24
24
|
"@aws-sdk/client-s3": "^3.441.0",
|
|
25
|
+
"@aws-sdk/client-secrets-manager": "^3.441.0",
|
|
25
26
|
"@aws-sdk/client-ses": "^3.441.0",
|
|
26
27
|
"@aws-sdk/client-sqs": "^3.441.0",
|
|
27
28
|
"@aws-sdk/client-ssm": "^3.441.0",
|
|
@@ -29,11 +30,11 @@
|
|
|
29
30
|
"@awslabs-community-fork/dynamodb-data-mapper": "^0.7.13",
|
|
30
31
|
"@awslabs-community-fork/dynamodb-data-marshaller": "^0.7.13",
|
|
31
32
|
"@awslabs-community-fork/dynamodb-expressions": "^0.7.13",
|
|
32
|
-
"@pristine-ts/common": "^0.0.
|
|
33
|
-
"@pristine-ts/core": "^0.0.
|
|
34
|
-
"@pristine-ts/logging": "^0.0.
|
|
35
|
-
"@pristine-ts/networking": "^0.0.
|
|
36
|
-
"@pristine-ts/security": "^0.0.
|
|
33
|
+
"@pristine-ts/common": "^0.0.276",
|
|
34
|
+
"@pristine-ts/core": "^0.0.276",
|
|
35
|
+
"@pristine-ts/logging": "^0.0.276",
|
|
36
|
+
"@pristine-ts/networking": "^0.0.276",
|
|
37
|
+
"@pristine-ts/security": "^0.0.276"
|
|
37
38
|
},
|
|
38
39
|
"publishConfig": {
|
|
39
40
|
"access": "public"
|
|
@@ -72,5 +73,5 @@
|
|
|
72
73
|
"src/*.{js,ts}"
|
|
73
74
|
]
|
|
74
75
|
},
|
|
75
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "728907e178ed7007242fa7535c6e3ed4ac12e22c"
|
|
76
77
|
}
|