@linzjs/cdk-tags 1.0.3 → 1.1.0

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.
@@ -0,0 +1,30 @@
1
+ interface GitBuildInfo {
2
+ /**
3
+ * Last git version tag
4
+ *
5
+ * @example
6
+ * "v6.45.0"
7
+ */
8
+ version: string;
9
+ /**
10
+ * Current git commit hash
11
+ *
12
+ * @example
13
+ * "e460a1bf611b9464f4c2c3feb48e4823277f14a4"
14
+ */
15
+ hash: string;
16
+ /**
17
+ * Github actions run id and attempt if it exists, otherwise ""
18
+ *
19
+ * @example
20
+ * "6228679664-1"
21
+ */
22
+ buildId: string;
23
+ }
24
+ /**
25
+ * Attempt to guess build information from the currently checked out version of the source code
26
+ *
27
+ * @returns Basic Git/Github build information
28
+ */
29
+ export declare function getGitBuildInfo(): GitBuildInfo;
30
+ export {};
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getGitBuildInfo = void 0;
4
+ const node_child_process_1 = require("node:child_process");
5
+ let buildInfo;
6
+ /**
7
+ * Attempt to guess build information from the currently checked out version of the source code
8
+ *
9
+ * @returns Basic Git/Github build information
10
+ */
11
+ function getGitBuildInfo() {
12
+ if (buildInfo == null) {
13
+ buildInfo = {
14
+ version: (0, node_child_process_1.execFileSync)('git', ['describe', '--tags', '--always', '--match', 'v*']).toString().trim(),
15
+ hash: (0, node_child_process_1.execFileSync)('git', ['rev-parse', 'HEAD']).toString().trim(),
16
+ buildId: process.env['GITHUB_RUN_ID']
17
+ ? `${process.env['GITHUB_RUN_ID']}-${process.env['GITHUB_RUN_ATTEMPT']}`
18
+ : '',
19
+ };
20
+ }
21
+ return buildInfo;
22
+ }
23
+ exports.getGitBuildInfo = getGitBuildInfo;
24
+ //# sourceMappingURL=build.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/build.ts"],"names":[],"mappings":";;;AAAA,2DAAkD;AA0BlD,IAAI,SAAmC,CAAC;AAExC;;;;GAIG;AACH,SAAgB,eAAe;IAC7B,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;QACtB,SAAS,GAAG;YACV,OAAO,EAAE,IAAA,iCAAY,EAAC,KAAK,EAAE,CAAC,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE;YACnG,IAAI,EAAE,IAAA,iCAAY,EAAC,KAAK,EAAE,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE;YAClE,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC;gBACnC,CAAC,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,EAAE;gBACxE,CAAC,CAAC,EAAE;SACP,CAAC;IACJ,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAXD,0CAWC"}
@@ -0,0 +1,28 @@
1
+ export interface TagsData {
2
+ /**
3
+ * What is the highest importance data in this storage location
4
+ *
5
+ * For example a public master data archive s3://nz-imagery is `archive`
6
+ */
7
+ role: TagDataRole;
8
+ /**
9
+ * Is this data public,
10
+ *
11
+ * For example a public bucket such as `s3://nz-imagery`
12
+ *
13
+ * @defaultValue false
14
+ */
15
+ isPublic: boolean;
16
+ /**
17
+ * Does this construct contain the master source of data
18
+ *
19
+ * for example the public imagery archive `s3://nz-imagery`
20
+ *
21
+ * @defaultValue false
22
+ */
23
+ isMaster: boolean;
24
+ }
25
+ export declare enum TagDataRole {
26
+ Primary = "primary",
27
+ Archive = "archive"
28
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TagDataRole = void 0;
4
+ var TagDataRole;
5
+ (function (TagDataRole) {
6
+ TagDataRole["Primary"] = "primary";
7
+ TagDataRole["Archive"] = "archive";
8
+ })(TagDataRole || (exports.TagDataRole = TagDataRole = {}));
9
+ //# sourceMappingURL=data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data.js","sourceRoot":"","sources":["../../src/data.ts"],"names":[],"mappings":";;;AA0BA,IAAY,WAGX;AAHD,WAAY,WAAW;IACrB,kCAAmB,CAAA;IACnB,kCAAmB,CAAA;AACrB,CAAC,EAHW,WAAW,2BAAX,WAAW,QAGtB"}
@@ -0,0 +1,3 @@
1
+ export { getGitBuildInfo } from './build.js';
2
+ export { SecurityClassification } from './security.js';
3
+ export { applyTags, applyTagsData } from './tags.js';
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applyTagsData = exports.applyTags = exports.SecurityClassification = exports.getGitBuildInfo = void 0;
4
+ var build_js_1 = require("./build.js");
5
+ Object.defineProperty(exports, "getGitBuildInfo", { enumerable: true, get: function () { return build_js_1.getGitBuildInfo; } });
6
+ var security_js_1 = require("./security.js");
7
+ Object.defineProperty(exports, "SecurityClassification", { enumerable: true, get: function () { return security_js_1.SecurityClassification; } });
8
+ var tags_js_1 = require("./tags.js");
9
+ Object.defineProperty(exports, "applyTags", { enumerable: true, get: function () { return tags_js_1.applyTags; } });
10
+ Object.defineProperty(exports, "applyTagsData", { enumerable: true, get: function () { return tags_js_1.applyTagsData; } });
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,uCAA6C;AAApC,2GAAA,eAAe,OAAA;AACxB,6CAAuD;AAA9C,qHAAA,sBAAsB,OAAA;AAC/B,qCAAqD;AAA5C,oGAAA,SAAS,OAAA;AAAE,wGAAA,aAAa,OAAA"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * NZ Security classification
3
+ * @see https://www.digital.govt.nz/standards-and-guidance/governance/managing-online-channels/security-and-privacy-for-websites/foundations/classify-information/
4
+ */
5
+ export declare enum SecurityClassification {
6
+ Unclassified = "unclassified",
7
+ InConfidence = "in-confidence",
8
+ Sensitive = "sensitive",
9
+ Restricted = "restricted",
10
+ Confidential = "confidential",
11
+ Secret = "secret",
12
+ TopSecret = "top-secret"
13
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SecurityClassification = void 0;
4
+ /**
5
+ * NZ Security classification
6
+ * @see https://www.digital.govt.nz/standards-and-guidance/governance/managing-online-channels/security-and-privacy-for-websites/foundations/classify-information/
7
+ */
8
+ var SecurityClassification;
9
+ (function (SecurityClassification) {
10
+ SecurityClassification["Unclassified"] = "unclassified";
11
+ SecurityClassification["InConfidence"] = "in-confidence";
12
+ SecurityClassification["Sensitive"] = "sensitive";
13
+ SecurityClassification["Restricted"] = "restricted";
14
+ SecurityClassification["Confidential"] = "confidential";
15
+ SecurityClassification["Secret"] = "secret";
16
+ SecurityClassification["TopSecret"] = "top-secret";
17
+ })(SecurityClassification || (exports.SecurityClassification = SecurityClassification = {}));
18
+ //# sourceMappingURL=security.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"security.js","sourceRoot":"","sources":["../../src/security.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,IAAY,sBAQX;AARD,WAAY,sBAAsB;IAChC,uDAA6B,CAAA;IAC7B,wDAA8B,CAAA;IAC9B,iDAAuB,CAAA;IACvB,mDAAyB,CAAA;IACzB,uDAA6B,CAAA;IAC7B,2CAAiB,CAAA;IACjB,kDAAwB,CAAA;AAC1B,CAAC,EARW,sBAAsB,sCAAtB,sBAAsB,QAQjC"}
@@ -0,0 +1,49 @@
1
+ import { IConstruct } from 'constructs';
2
+ import { TagsData } from './data.js';
3
+ import { SecurityClassification } from './security.js';
4
+ export interface TagsBase {
5
+ /**
6
+ * Environment of the resource
7
+ *
8
+ * @example 'prod'
9
+ *
10
+ * @see AwsEnv in @linz/accounts
11
+ */
12
+ environment: 'nonprod' | 'preprod' | 'prod';
13
+ /**
14
+ * Application name
15
+ *
16
+ * @example "basemaps"
17
+ */
18
+ application: string;
19
+ /**
20
+ * Human friendly name for LINZ group that the resources belong to
21
+ *
22
+ * @example "step" or "li"
23
+ */
24
+ group: string;
25
+ /**
26
+ * Git repository that this construct belongs to
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * "linz/basemaps"
31
+ * "linz/lds-cache"
32
+ * ```
33
+ *
34
+ * Uses the $GITHUB_REPOSITORY env var by default
35
+ *
36
+ * @default "$GITHUB_REPOSITORY"
37
+ */
38
+ repository?: string;
39
+ /**
40
+ * Security classification of the construct
41
+ *
42
+ * @see https://www.digital.govt.nz/standards-and-guidance/governance/managing-online-channels/security-and-privacy-for-websites/foundations/classify-information/
43
+ */
44
+ classification: SecurityClassification;
45
+ /** Data classification tags */
46
+ data?: TagsData;
47
+ }
48
+ export declare function applyTags(construct: IConstruct, ctx: TagsBase): void;
49
+ export declare function applyTagsData(construct: IConstruct, tags: TagsData): void;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applyTagsData = exports.applyTags = void 0;
4
+ const aws_cdk_lib_1 = require("aws-cdk-lib");
5
+ const build_js_1 = require("./build.js");
6
+ const security_js_1 = require("./security.js");
7
+ // Apply a tag but skip application of tag if the value is undefined or empty
8
+ function tag(construct, key, value) {
9
+ if (value == null)
10
+ return;
11
+ if (value === '')
12
+ return;
13
+ aws_cdk_lib_1.Tags.of(construct).add(key, value);
14
+ }
15
+ function applyTags(construct, ctx) {
16
+ // TODO is this check valid here?
17
+ if (ctx.data?.isPublic && ctx.classification !== security_js_1.SecurityClassification.Unclassified) {
18
+ throw new Error('Only unclassified constructs can be made public');
19
+ }
20
+ const buildInfo = (0, build_js_1.getGitBuildInfo)();
21
+ // applications tags
22
+ tag(construct, 'linz:app:name', ctx.application);
23
+ tag(construct, 'linz:app:version', buildInfo.version);
24
+ tag(construct, 'linz:environment', ctx.environment);
25
+ // Ownership tags
26
+ tag(construct, 'linz:group', ctx.group);
27
+ // Git Tags
28
+ tag(construct, 'linz:git:hash', buildInfo.hash);
29
+ tag(construct, 'linz:git:repository', process.env['GITHUB_REPOSITORY'] ?? ctx.repository);
30
+ // Github actions build information
31
+ tag(construct, 'linz:build:id', buildInfo.buildId);
32
+ // Security
33
+ tag(construct, 'linz:security:classification', ctx.classification);
34
+ if (ctx.data)
35
+ applyTagsData(construct, ctx.data);
36
+ }
37
+ exports.applyTags = applyTags;
38
+ function applyTagsData(construct, tags) {
39
+ tag(construct, 'linz:data:role', tags.role);
40
+ tag(construct, 'linz:data:is-master', String(tags.isMaster ?? false));
41
+ tag(construct, 'linz:data:is-public', String(tags.isPublic ?? false));
42
+ }
43
+ exports.applyTagsData = applyTagsData;
44
+ //# sourceMappingURL=tags.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tags.js","sourceRoot":"","sources":["../../src/tags.ts"],"names":[],"mappings":";;;AAAA,6CAAmC;AAGnC,yCAA6C;AAE7C,+CAAuD;AAoDvD,6EAA6E;AAC7E,SAAS,GAAG,CAAC,SAAqB,EAAE,GAAW,EAAE,KAAgC;IAC/E,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO;IAC1B,IAAI,KAAK,KAAK,EAAE;QAAE,OAAO;IAEzB,kBAAI,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;AACrC,CAAC;AAED,SAAgB,SAAS,CAAC,SAAqB,EAAE,GAAa;IAC5D,iCAAiC;IACjC,IAAI,GAAG,CAAC,IAAI,EAAE,QAAQ,IAAI,GAAG,CAAC,cAAc,KAAK,oCAAsB,CAAC,YAAY,EAAE,CAAC;QACrF,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACrE,CAAC;IACD,MAAM,SAAS,GAAG,IAAA,0BAAe,GA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