@dsmrt/axiom-aws-sdk 0.1.1 → 0.2.1
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/CHANGELOG.md +12 -0
- package/package.json +3 -3
- package/lib/index.js +0 -18
- package/lib/ssm-parameter-collection.js +0 -49
- package/lib/ssm-parameters.js +0 -84
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @dsmrt/axiom-aws-sdk
|
|
2
2
|
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- c61c468: aws sdk issue with missing fast xml parser dep
|
|
8
|
+
|
|
9
|
+
## 0.2.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 7aa81f2: fixing issues with publishing the package with changesets
|
|
14
|
+
|
|
3
15
|
## 0.1.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dsmrt/axiom-aws-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "AWS sdk library for working with axiom cli",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -28,13 +28,13 @@
|
|
|
28
28
|
"@types/node": "^20.9.0",
|
|
29
29
|
"@typescript-eslint/eslint-plugin": "^6.12.0",
|
|
30
30
|
"@typescript-eslint/parser": "^6.12.0",
|
|
31
|
-
"@vitest/coverage-v8": "^0.34.6",
|
|
32
31
|
"eslint": "^8.54.0",
|
|
33
32
|
"prettier": "^3.1.0",
|
|
34
33
|
"ts-node": "^10.9.1",
|
|
35
34
|
"tsup": "^8.0.1",
|
|
36
35
|
"typescript": "^5.2.2",
|
|
37
|
-
"vitest": "^
|
|
36
|
+
"@vitest/coverage-v8": "^1.2.1",
|
|
37
|
+
"vitest": "^1.2.1"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@aws-sdk/client-ssm": "^3.451.0",
|
package/lib/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./ssm-parameters"), exports);
|
|
18
|
-
__exportStar(require("./ssm-parameter-collection"), exports);
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ParameterCollection = void 0;
|
|
4
|
-
const ssm_parameters_1 = require("./ssm-parameters");
|
|
5
|
-
class ParameterCollection {
|
|
6
|
-
path;
|
|
7
|
-
client;
|
|
8
|
-
map = new Map();
|
|
9
|
-
constructor(path, client) {
|
|
10
|
-
this.path = path;
|
|
11
|
-
this.client = client;
|
|
12
|
-
}
|
|
13
|
-
async hasParam(param) {
|
|
14
|
-
if (this.map.size < 1) {
|
|
15
|
-
await this.loadParameters();
|
|
16
|
-
}
|
|
17
|
-
return this.map.has(param);
|
|
18
|
-
}
|
|
19
|
-
async findParam(param) {
|
|
20
|
-
if (this.map.size < 1) {
|
|
21
|
-
await this.loadParameters();
|
|
22
|
-
}
|
|
23
|
-
return this.map.get(param);
|
|
24
|
-
}
|
|
25
|
-
async getParam(param) {
|
|
26
|
-
if (!(await this.hasParam(param))) {
|
|
27
|
-
throw new Error(`Parameter '${param.toString()}' does not exist'`);
|
|
28
|
-
}
|
|
29
|
-
return this.map.get(param);
|
|
30
|
-
}
|
|
31
|
-
async get() {
|
|
32
|
-
if (this.map.size < 1) {
|
|
33
|
-
await this.loadParameters();
|
|
34
|
-
}
|
|
35
|
-
return this.map;
|
|
36
|
-
}
|
|
37
|
-
async loadParameters() {
|
|
38
|
-
if (!this.path) {
|
|
39
|
-
throw new Error(`Parameter path is not set or is undefined`);
|
|
40
|
-
}
|
|
41
|
-
const params = await (0, ssm_parameters_1.getParametersByPath)(this.path, undefined, undefined, this.client);
|
|
42
|
-
params.forEach((param) => {
|
|
43
|
-
const fullName = param.Name;
|
|
44
|
-
const name = fullName.replace(`${this.path}/`, "");
|
|
45
|
-
this.map.set(name, param);
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
exports.ParameterCollection = ParameterCollection;
|
package/lib/ssm-parameters.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractParamValue = exports.getParameters = exports.getParametersByPath = exports.ssmClient = void 0;
|
|
4
|
-
const client_ssm_1 = require("@aws-sdk/client-ssm");
|
|
5
|
-
exports.ssmClient = new client_ssm_1.SSMClient({});
|
|
6
|
-
// to use this, you need to give the lambda function permission to the
|
|
7
|
-
// ** CloudFormation Example **
|
|
8
|
-
// Resources:
|
|
9
|
-
// LambdaPolicies:
|
|
10
|
-
// Type: AWS::IAM::Policy
|
|
11
|
-
// Properties:
|
|
12
|
-
// PolicyName: LambdaRole
|
|
13
|
-
// PolicyDocument:
|
|
14
|
-
// Statement:
|
|
15
|
-
// - Effect: Allow
|
|
16
|
-
// Action:
|
|
17
|
-
// - "ssm:GetParameters"
|
|
18
|
-
// - "ssm:GetParametersByPath"
|
|
19
|
-
// Resource: !Sub 'arn:aws:ssm:*:*:parameter/${PARAMETER_PATH}/*'
|
|
20
|
-
const getParametersByPath = async (path, parameters, nextToken, client) => {
|
|
21
|
-
client ??= exports.ssmClient;
|
|
22
|
-
let returnParams = parameters || [];
|
|
23
|
-
const command = new client_ssm_1.GetParametersByPathCommand({
|
|
24
|
-
Path: path,
|
|
25
|
-
Recursive: true,
|
|
26
|
-
WithDecryption: true,
|
|
27
|
-
NextToken: nextToken,
|
|
28
|
-
});
|
|
29
|
-
const output = await client.send(command);
|
|
30
|
-
// merge parameters
|
|
31
|
-
if (output.Parameters !== undefined) {
|
|
32
|
-
returnParams = [...returnParams, ...output.Parameters];
|
|
33
|
-
}
|
|
34
|
-
if (output.NextToken !== undefined) {
|
|
35
|
-
return (0, exports.getParametersByPath)(path, returnParams, output.NextToken, client);
|
|
36
|
-
}
|
|
37
|
-
// return all
|
|
38
|
-
return returnParams;
|
|
39
|
-
};
|
|
40
|
-
exports.getParametersByPath = getParametersByPath;
|
|
41
|
-
// ** CloudFormation Example **
|
|
42
|
-
// Resources:
|
|
43
|
-
// LambdaPolicies:
|
|
44
|
-
// Type: AWS::IAM::Policy
|
|
45
|
-
// Properties:
|
|
46
|
-
// PolicyName: LambdaRole
|
|
47
|
-
// PolicyDocument:
|
|
48
|
-
// Statement:
|
|
49
|
-
// - Effect: Allow
|
|
50
|
-
// Action:
|
|
51
|
-
// - "ssm:GetParameters"
|
|
52
|
-
// - "ssm:GetParametersByPath"
|
|
53
|
-
// Resource:
|
|
54
|
-
// - ${name1}
|
|
55
|
-
// - ${name2}
|
|
56
|
-
// - ${name3
|
|
57
|
-
const getParameters = async (names, client) => {
|
|
58
|
-
client ??= exports.ssmClient;
|
|
59
|
-
const command = new client_ssm_1.GetParametersCommand({
|
|
60
|
-
Names: names,
|
|
61
|
-
WithDecryption: true,
|
|
62
|
-
});
|
|
63
|
-
const result = await client.send(command);
|
|
64
|
-
if (result.Parameters === undefined) {
|
|
65
|
-
return [];
|
|
66
|
-
}
|
|
67
|
-
return result.Parameters;
|
|
68
|
-
};
|
|
69
|
-
exports.getParameters = getParameters;
|
|
70
|
-
/**
|
|
71
|
-
* Extract a single parameter from an array of params (typically from params by path)
|
|
72
|
-
*
|
|
73
|
-
* @param name
|
|
74
|
-
* @param params
|
|
75
|
-
*/
|
|
76
|
-
const extractParamValue = (path, name, params) => {
|
|
77
|
-
const fullName = `${path.replace(/\/$/, "")}/${name}`;
|
|
78
|
-
const item = params.find((item) => item.Name === fullName);
|
|
79
|
-
if (!item || !item.Value) {
|
|
80
|
-
throw new Error(`Parameter '${fullName}' is not set.`);
|
|
81
|
-
}
|
|
82
|
-
return item.Value;
|
|
83
|
-
};
|
|
84
|
-
exports.extractParamValue = extractParamValue;
|