@fy-stack/database-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
+ # database-construct
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build database-construct` to build the library.
@@ -0,0 +1,2 @@
1
+ export { DatabaseConstruct } from './lib/database-construct';
2
+ //# 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,iBAAiB,EAAE,MAAM,0BAA0B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DatabaseConstruct = void 0;
4
+ var database_construct_1 = require("./lib/database-construct");
5
+ Object.defineProperty(exports, "DatabaseConstruct", { enumerable: true, get: function () { return database_construct_1.DatabaseConstruct; } });
@@ -0,0 +1,19 @@
1
+ import { Attachable, Grantable } from '@fy-stack/types';
2
+ import { IGrantable } from 'aws-cdk-lib/aws-iam';
3
+ import * as rds from 'aws-cdk-lib/aws-rds';
4
+ import * as secretsManager from 'aws-cdk-lib/aws-secretsmanager';
5
+ import { Construct } from 'constructs';
6
+ export declare class DatabaseConstruct extends Construct implements Attachable, Grantable {
7
+ dbSecrets: secretsManager.ISecret;
8
+ db: rds.IDatabaseCluster;
9
+ dbName: string;
10
+ constructor(scope: Construct, id: string);
11
+ grantable(grant: IGrantable): void;
12
+ attachable(): {
13
+ arn: string;
14
+ name: string;
15
+ secretsArn: string;
16
+ secretsName: string;
17
+ };
18
+ }
19
+ //# sourceMappingURL=database-construct.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database-construct.d.ts","sourceRoot":"","sources":["../../src/lib/database-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,GAAG,MAAM,qBAAqB,CAAC;AAC3C,OAAO,KAAK,cAAc,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,qBAAa,iBACX,SAAQ,SACR,YAAW,UAAU,EAAE,SAAS;IAEzB,SAAS,EAAE,cAAc,CAAC,OAAO,CAAC;IAClC,EAAE,EAAE,GAAG,CAAC,gBAAgB,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;gBAEV,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM;IAsBxC,SAAS,CAAC,KAAK,EAAE,UAAU;IAkB3B,UAAU;;;;;;CAQX"}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DatabaseConstruct = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const iam = tslib_1.__importStar(require("aws-cdk-lib/aws-iam"));
6
+ const rds = tslib_1.__importStar(require("aws-cdk-lib/aws-rds"));
7
+ const constructs_1 = require("constructs");
8
+ class DatabaseConstruct extends constructs_1.Construct {
9
+ dbSecrets;
10
+ db;
11
+ dbName;
12
+ constructor(scope, id) {
13
+ super(scope, id);
14
+ const db = rds.DatabaseCluster.fromDatabaseClusterAttributes(this, 'DatabaseCluster', { clusterIdentifier: 'dev-db-instance' });
15
+ this.dbName = `${this.node.id}-db`;
16
+ const dbSecret = new rds.DatabaseSecret(this, 'DatabaseSecret', {
17
+ username: this.node.id,
18
+ dbname: this.dbName,
19
+ });
20
+ dbSecret.attach(db);
21
+ this.db = db;
22
+ this.dbSecrets = dbSecret;
23
+ }
24
+ grantable(grant) {
25
+ const principals = [grant.grantPrincipal];
26
+ new iam.PolicyStatement({
27
+ effect: iam.Effect.ALLOW,
28
+ actions: ['rds-data:*'],
29
+ resources: [this.db.clusterArn],
30
+ principals,
31
+ });
32
+ new iam.PolicyStatement({
33
+ effect: iam.Effect.ALLOW,
34
+ actions: ['secretsmanager:GetSecretValue'],
35
+ resources: [this.dbSecrets.secretArn],
36
+ principals,
37
+ });
38
+ }
39
+ attachable() {
40
+ return {
41
+ arn: this.db.clusterArn,
42
+ name: this.dbName,
43
+ secretsArn: this.dbSecrets.secretArn,
44
+ secretsName: this.dbSecrets.secretName,
45
+ };
46
+ }
47
+ }
48
+ exports.DatabaseConstruct = DatabaseConstruct;
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@fy-stack/database-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": "database-construct"
21
+ }
22
+ }