@fy-stack/secret-construct 0.0.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/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # secret-construct
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build secret-construct` to build the library.
@@ -0,0 +1,3 @@
1
+ export { SecretsConstruct } from './lib/secret-construct';
2
+ export type { SecretConstructProps } from "./lib/type";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,YAAY,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SecretsConstruct = void 0;
4
+ var secret_construct_1 = require("./lib/secret-construct");
5
+ Object.defineProperty(exports, "SecretsConstruct", { enumerable: true, get: function () { return secret_construct_1.SecretsConstruct; } });
@@ -0,0 +1,15 @@
1
+ import { Attachable, Grantable } from '@fy-stack/types';
2
+ import { IGrantable } from 'aws-cdk-lib/aws-iam';
3
+ import * as secretsManager from 'aws-cdk-lib/aws-secretsmanager';
4
+ import { Construct } from 'constructs';
5
+ import type { SecretConstructProps } from './type';
6
+ export declare class SecretsConstruct extends Construct implements Attachable, Grantable {
7
+ readonly secrets: secretsManager.Secret;
8
+ constructor(scope: Construct, id: string, props: SecretConstructProps);
9
+ attachable(): {
10
+ arn: string;
11
+ name: string;
12
+ };
13
+ grantable(grant: IGrantable): void;
14
+ }
15
+ //# sourceMappingURL=secret-construct.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secret-construct.d.ts","sourceRoot":"","sources":["../../src/lib/secret-construct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,KAAK,cAAc,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAEnD,qBAAa,gBAAiB,SAAQ,SAAU,YAAW,UAAU,EAAE,SAAS;IAC9E,SAAgB,OAAO,EAAE,cAAc,CAAC,MAAM,CAAC;gBAEnC,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,oBAAoB;IAgCrE,UAAU;;;;IAOV,SAAS,CAAC,KAAK,EAAE,UAAU;CAG5B"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SecretsConstruct = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const cdk = tslib_1.__importStar(require("aws-cdk-lib"));
6
+ const secretsManager = tslib_1.__importStar(require("aws-cdk-lib/aws-secretsmanager"));
7
+ const constructs_1 = require("constructs");
8
+ class SecretsConstruct extends constructs_1.Construct {
9
+ secrets;
10
+ constructor(scope, id, props) {
11
+ super(scope, id);
12
+ const secretObjectValue = {
13
+ region: cdk.Stack.of(this).region,
14
+ };
15
+ Object.assign(secretObjectValue, ...Object.entries(props.resources ?? {}).map(([key, val]) => {
16
+ return Object.fromEntries(Object.entries(val?.attachable() ?? {}).map(([subKey, subVal]) => [
17
+ `${key}.${subKey}`,
18
+ subVal,
19
+ ]));
20
+ }));
21
+ if (props.secrets) {
22
+ Object.assign(secretObjectValue, props.secrets);
23
+ }
24
+ this.secrets = new secretsManager.Secret(this, 'AppSecrets', {
25
+ secretObjectValue: Object.fromEntries(Object.entries(secretObjectValue).map(([key, val]) => [
26
+ key,
27
+ cdk.SecretValue.unsafePlainText(val ?? ''),
28
+ ])),
29
+ });
30
+ }
31
+ attachable() {
32
+ return {
33
+ arn: this.secrets.secretArn,
34
+ name: this.secrets.secretName,
35
+ };
36
+ }
37
+ grantable(grant) {
38
+ this.secrets.grantRead(grant);
39
+ }
40
+ }
41
+ exports.SecretsConstruct = SecretsConstruct;
@@ -0,0 +1,6 @@
1
+ import { Attachable } from '@fy-stack/types';
2
+ export interface SecretConstructProps {
3
+ secrets?: Record<string, string | undefined>;
4
+ resources?: Record<string, Attachable | undefined>;
5
+ }
6
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../src/lib/type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,MAAM,WAAW,oBAAoB;IACnC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IAC7C,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,SAAS,CAAC,CAAA;CACnD"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@fy-stack/secret-construct",
3
+ "version": "0.0.1",
4
+ "dependencies": {
5
+ "tslib": "^2.3.0"
6
+ },
7
+ "peerDependencies": {
8
+ "aws-cdk-lib": "2.164.1",
9
+ "constructs": "10.4.2",
10
+ "@fy-stack/types": "0.0.1"
11
+ },
12
+ "type": "commonjs",
13
+ "main": "./dist/index.js",
14
+ "typings": "./dist/index.d.ts",
15
+ "files": [
16
+ "dist",
17
+ "!**/*.tsbuildinfo"
18
+ ],
19
+ "nx": {
20
+ "name": "secret-construct"
21
+ }
22
+ }