@infrascan/aws-cloudwatch-logs-scanner 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/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # @infrascan/aws-cloudwatch-logs-scanner
2
+
3
+ A scanner module for AWS Cloudwatch Logs, designed to be used with the [@infrascan/sdk](../../packages/sdk).
4
+
5
+ This module pulls information about the Cloudwatch Logs resources in an AWS account by calling: `DescribeLogGroups` and `DescribeSubscriptionFilters`.
6
+
7
+ ## Quickstart
8
+
9
+ ```javascript
10
+ import CloudwatchLogsScanner from "@infrascan/aws-cloudwatch-logs-scanner";
11
+ import Infrascan from "@infrascan/sdk";
12
+
13
+ const infrascanClient = new Infrascan();
14
+ infrascanClient.registerScanner(CloudwatchLogsScanner);
15
+ ```
16
+
17
+ If you plan on scanning all of an AWS account, you should use the [@infrascan/aws](../../packages/aws) package.
18
+
19
+ ## Contributing
20
+
21
+ The majority of the scanner modules are autogenerated from their [config.ts](./config.ts) file.
22
+
23
+ Changes such as adding a new function/endpoint in the service to scan can be done within the config file.
24
+
25
+ More significant changes will likely need to take place in the [aws-codegen](../codegen) package.
@@ -0,0 +1,6 @@
1
+ import { CloudWatchLogsClient } from '@aws-sdk/client-cloudwatch-logs';
2
+ import { ServiceModule } from '@infrascan/shared-types';
3
+
4
+ declare const CloudWatchLogsScanner: ServiceModule<CloudWatchLogsClient, "aws">;
5
+
6
+ export { CloudWatchLogsScanner as default };
@@ -0,0 +1,6 @@
1
+ import { CloudWatchLogsClient } from '@aws-sdk/client-cloudwatch-logs';
2
+ import { ServiceModule } from '@infrascan/shared-types';
3
+
4
+ declare const CloudWatchLogsScanner: ServiceModule<CloudWatchLogsClient, "aws">;
5
+
6
+ export = CloudWatchLogsScanner;
package/dist/index.js ADDED
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ default: () => src_default
24
+ });
25
+ module.exports = __toCommonJS(src_exports);
26
+
27
+ // src/generated/client.ts
28
+ var import_client_cloudwatch_logs = require("@aws-sdk/client-cloudwatch-logs");
29
+ function getClient(credentials, context) {
30
+ return new import_client_cloudwatch_logs.CloudWatchLogsClient({ credentials, region: context.region });
31
+ }
32
+
33
+ // src/generated/getters.ts
34
+ var import_client_cloudwatch_logs2 = require("@aws-sdk/client-cloudwatch-logs");
35
+ var import_core = require("@infrascan/core");
36
+ async function DescribeLogGroups(client, stateConnector, context) {
37
+ const state = [];
38
+ console.log("cloudwatch-logs DescribeLogGroups");
39
+ let pagingToken = void 0;
40
+ do {
41
+ const preparedParams = {};
42
+ preparedParams.nextToken = pagingToken;
43
+ try {
44
+ const cmd = new import_client_cloudwatch_logs2.DescribeLogGroupsCommand(preparedParams);
45
+ const result = await client.send(cmd);
46
+ state.push({
47
+ _metadata: { account: context.account, region: context.region },
48
+ _parameters: preparedParams,
49
+ _result: result
50
+ });
51
+ pagingToken = result.nextToken;
52
+ } catch (err) {
53
+ if (err instanceof import_client_cloudwatch_logs2.CloudWatchLogsServiceException) {
54
+ if (err?.$retryable) {
55
+ console.log("Encountered retryable error", err);
56
+ } else {
57
+ console.log("Encountered unretryable error", err);
58
+ }
59
+ } else {
60
+ console.log("Encountered unexpected error", err);
61
+ }
62
+ pagingToken = void 0;
63
+ }
64
+ } while (pagingToken != null);
65
+ await stateConnector.onServiceScanCompleteCallback(
66
+ context.account,
67
+ context.region,
68
+ "CloudWatchLogs",
69
+ "DescribeLogGroups",
70
+ state
71
+ );
72
+ }
73
+ async function DescribeSubscriptionFilters(client, stateConnector, context) {
74
+ const state = [];
75
+ console.log("cloudwatch-logs DescribeSubscriptionFilters");
76
+ const resolvers = [
77
+ {
78
+ Key: "logGroupName",
79
+ Selector: "CloudWatchLogs|DescribeLogGroups|[]._result.logGroups[].logGroupName"
80
+ }
81
+ ];
82
+ const parameterQueue = await (0, import_core.resolveFunctionCallParameters)(
83
+ context.account,
84
+ context.region,
85
+ resolvers,
86
+ stateConnector
87
+ );
88
+ for (const parameters of parameterQueue) {
89
+ let pagingToken = void 0;
90
+ do {
91
+ const preparedParams = parameters;
92
+ preparedParams.nextToken = pagingToken;
93
+ try {
94
+ const cmd = new import_client_cloudwatch_logs2.DescribeSubscriptionFiltersCommand(preparedParams);
95
+ const result = await client.send(cmd);
96
+ state.push({
97
+ _metadata: { account: context.account, region: context.region },
98
+ _parameters: preparedParams,
99
+ _result: result
100
+ });
101
+ pagingToken = result.nextToken;
102
+ } catch (err) {
103
+ if (err instanceof import_client_cloudwatch_logs2.CloudWatchLogsServiceException) {
104
+ if (err?.$retryable) {
105
+ console.log("Encountered retryable error", err);
106
+ } else {
107
+ console.log("Encountered unretryable error", err);
108
+ }
109
+ } else {
110
+ console.log("Encountered unexpected error", err);
111
+ }
112
+ pagingToken = void 0;
113
+ }
114
+ } while (pagingToken != null);
115
+ }
116
+ await stateConnector.onServiceScanCompleteCallback(
117
+ context.account,
118
+ context.region,
119
+ "CloudWatchLogs",
120
+ "DescribeSubscriptionFilters",
121
+ state
122
+ );
123
+ }
124
+
125
+ // src/generated/graph.ts
126
+ var import_core2 = require("@infrascan/core");
127
+ async function getNodes(stateConnector, context) {
128
+ const state = [];
129
+ const DescribeSubscriptionFiltersNodes = await (0, import_core2.evaluateSelector)(
130
+ context.account,
131
+ context.region,
132
+ "CloudWatchLogs|DescribeSubscriptionFilters|[]._result.subscriptionFilters[].{id:logGroupName,name:logGroupName}",
133
+ stateConnector
134
+ );
135
+ state.push(...DescribeSubscriptionFiltersNodes);
136
+ return state.map(
137
+ (node) => (0, import_core2.formatNode)(node, "cloudwatch-logs", "CloudWatchLogs", context, true)
138
+ );
139
+ }
140
+ async function getEdges(stateConnector) {
141
+ const edges = [];
142
+ const DescribeSubscriptionFiltersState1 = await (0, import_core2.evaluateSelectorGlobally)(
143
+ "CloudWatchLogs|DescribeSubscriptionFilters|[]._result.subscriptionFilters[]",
144
+ stateConnector
145
+ );
146
+ const DescribeSubscriptionFiltersEdges1 = DescribeSubscriptionFiltersState1.flatMap((state) => {
147
+ const source = (0, import_core2.filterState)(state, "logGroupName");
148
+ const target = (0, import_core2.filterState)(
149
+ state,
150
+ "{target:destinationArn}"
151
+ );
152
+ if (!target || !source) {
153
+ return [];
154
+ }
155
+ if (Array.isArray(target)) {
156
+ return target.map((edgeTarget) => (0, import_core2.formatEdge)(source, edgeTarget));
157
+ }
158
+ return (0, import_core2.formatEdge)(source, target);
159
+ });
160
+ edges.push(...DescribeSubscriptionFiltersEdges1);
161
+ return edges;
162
+ }
163
+
164
+ // src/index.ts
165
+ var CloudWatchLogsScanner = {
166
+ provider: "aws",
167
+ service: "cloudwatch-logs",
168
+ key: "CloudWatchLogs",
169
+ arnLabel: "logs",
170
+ getClient,
171
+ callPerRegion: true,
172
+ getters: [DescribeLogGroups, DescribeSubscriptionFilters],
173
+ getNodes,
174
+ getEdges
175
+ };
176
+ var src_default = CloudWatchLogsScanner;
package/dist/index.mjs ADDED
@@ -0,0 +1,163 @@
1
+ // src/generated/client.ts
2
+ import { CloudWatchLogsClient } from "@aws-sdk/client-cloudwatch-logs";
3
+ function getClient(credentials, context) {
4
+ return new CloudWatchLogsClient({ credentials, region: context.region });
5
+ }
6
+
7
+ // src/generated/getters.ts
8
+ import {
9
+ DescribeLogGroupsCommand,
10
+ DescribeSubscriptionFiltersCommand,
11
+ CloudWatchLogsServiceException
12
+ } from "@aws-sdk/client-cloudwatch-logs";
13
+ import { resolveFunctionCallParameters } from "@infrascan/core";
14
+ async function DescribeLogGroups(client, stateConnector, context) {
15
+ const state = [];
16
+ console.log("cloudwatch-logs DescribeLogGroups");
17
+ let pagingToken = void 0;
18
+ do {
19
+ const preparedParams = {};
20
+ preparedParams.nextToken = pagingToken;
21
+ try {
22
+ const cmd = new DescribeLogGroupsCommand(preparedParams);
23
+ const result = await client.send(cmd);
24
+ state.push({
25
+ _metadata: { account: context.account, region: context.region },
26
+ _parameters: preparedParams,
27
+ _result: result
28
+ });
29
+ pagingToken = result.nextToken;
30
+ } catch (err) {
31
+ if (err instanceof CloudWatchLogsServiceException) {
32
+ if (err?.$retryable) {
33
+ console.log("Encountered retryable error", err);
34
+ } else {
35
+ console.log("Encountered unretryable error", err);
36
+ }
37
+ } else {
38
+ console.log("Encountered unexpected error", err);
39
+ }
40
+ pagingToken = void 0;
41
+ }
42
+ } while (pagingToken != null);
43
+ await stateConnector.onServiceScanCompleteCallback(
44
+ context.account,
45
+ context.region,
46
+ "CloudWatchLogs",
47
+ "DescribeLogGroups",
48
+ state
49
+ );
50
+ }
51
+ async function DescribeSubscriptionFilters(client, stateConnector, context) {
52
+ const state = [];
53
+ console.log("cloudwatch-logs DescribeSubscriptionFilters");
54
+ const resolvers = [
55
+ {
56
+ Key: "logGroupName",
57
+ Selector: "CloudWatchLogs|DescribeLogGroups|[]._result.logGroups[].logGroupName"
58
+ }
59
+ ];
60
+ const parameterQueue = await resolveFunctionCallParameters(
61
+ context.account,
62
+ context.region,
63
+ resolvers,
64
+ stateConnector
65
+ );
66
+ for (const parameters of parameterQueue) {
67
+ let pagingToken = void 0;
68
+ do {
69
+ const preparedParams = parameters;
70
+ preparedParams.nextToken = pagingToken;
71
+ try {
72
+ const cmd = new DescribeSubscriptionFiltersCommand(preparedParams);
73
+ const result = await client.send(cmd);
74
+ state.push({
75
+ _metadata: { account: context.account, region: context.region },
76
+ _parameters: preparedParams,
77
+ _result: result
78
+ });
79
+ pagingToken = result.nextToken;
80
+ } catch (err) {
81
+ if (err instanceof CloudWatchLogsServiceException) {
82
+ if (err?.$retryable) {
83
+ console.log("Encountered retryable error", err);
84
+ } else {
85
+ console.log("Encountered unretryable error", err);
86
+ }
87
+ } else {
88
+ console.log("Encountered unexpected error", err);
89
+ }
90
+ pagingToken = void 0;
91
+ }
92
+ } while (pagingToken != null);
93
+ }
94
+ await stateConnector.onServiceScanCompleteCallback(
95
+ context.account,
96
+ context.region,
97
+ "CloudWatchLogs",
98
+ "DescribeSubscriptionFilters",
99
+ state
100
+ );
101
+ }
102
+
103
+ // src/generated/graph.ts
104
+ import {
105
+ evaluateSelector,
106
+ formatNode,
107
+ evaluateSelectorGlobally,
108
+ filterState,
109
+ formatEdge
110
+ } from "@infrascan/core";
111
+ async function getNodes(stateConnector, context) {
112
+ const state = [];
113
+ const DescribeSubscriptionFiltersNodes = await evaluateSelector(
114
+ context.account,
115
+ context.region,
116
+ "CloudWatchLogs|DescribeSubscriptionFilters|[]._result.subscriptionFilters[].{id:logGroupName,name:logGroupName}",
117
+ stateConnector
118
+ );
119
+ state.push(...DescribeSubscriptionFiltersNodes);
120
+ return state.map(
121
+ (node) => formatNode(node, "cloudwatch-logs", "CloudWatchLogs", context, true)
122
+ );
123
+ }
124
+ async function getEdges(stateConnector) {
125
+ const edges = [];
126
+ const DescribeSubscriptionFiltersState1 = await evaluateSelectorGlobally(
127
+ "CloudWatchLogs|DescribeSubscriptionFilters|[]._result.subscriptionFilters[]",
128
+ stateConnector
129
+ );
130
+ const DescribeSubscriptionFiltersEdges1 = DescribeSubscriptionFiltersState1.flatMap((state) => {
131
+ const source = filterState(state, "logGroupName");
132
+ const target = filterState(
133
+ state,
134
+ "{target:destinationArn}"
135
+ );
136
+ if (!target || !source) {
137
+ return [];
138
+ }
139
+ if (Array.isArray(target)) {
140
+ return target.map((edgeTarget) => formatEdge(source, edgeTarget));
141
+ }
142
+ return formatEdge(source, target);
143
+ });
144
+ edges.push(...DescribeSubscriptionFiltersEdges1);
145
+ return edges;
146
+ }
147
+
148
+ // src/index.ts
149
+ var CloudWatchLogsScanner = {
150
+ provider: "aws",
151
+ service: "cloudwatch-logs",
152
+ key: "CloudWatchLogs",
153
+ arnLabel: "logs",
154
+ getClient,
155
+ callPerRegion: true,
156
+ getters: [DescribeLogGroups, DescribeSubscriptionFilters],
157
+ getNodes,
158
+ getEdges
159
+ };
160
+ var src_default = CloudWatchLogsScanner;
161
+ export {
162
+ src_default as default
163
+ };
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@infrascan/aws-cloudwatch-logs-scanner",
3
+ "version": "0.2.1",
4
+ "description": "Infrascan scanner definition for AWS Cloudwatch Logs",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "require": "./dist/index.js",
11
+ "import": "./dist/index.mjs",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "tsup": {
19
+ "clean": true,
20
+ "cjsInterop": true,
21
+ "dts": true,
22
+ "splitting": false,
23
+ "sourcemap": false,
24
+ "entry": [
25
+ "src/index.ts"
26
+ ],
27
+ "format": [
28
+ "cjs",
29
+ "esm"
30
+ ],
31
+ "target": "node18"
32
+ },
33
+ "scripts": {
34
+ "codegen": "npx ts-node ./codegen.ts ; npm run lint:fix ; npm run fmt",
35
+ "build": "rm -rf dist ; tsup",
36
+ "prepublish": "rm -rf dist ; tsup",
37
+ "test": "tap test/*.test.ts --allow-incomplete-coverage -- --typescript",
38
+ "lint": "tsc --noEmit ; prettier src/**/*.ts -c ; eslint .",
39
+ "lint:fix": "eslint . --fix",
40
+ "fmt": "prettier src/**/*.ts -w",
41
+ "clean": "rm -rf dist node_modules"
42
+ },
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "git+https://github.com/infrascan/infrascan.git"
46
+ },
47
+ "keywords": [],
48
+ "author": "Liam Farrelly <liam@l3f7.dev> (https://whoisli.am/)",
49
+ "license": "MPL-2.0",
50
+ "bugs": {
51
+ "url": "https://github.com/infrascan/infrascan/issues"
52
+ },
53
+ "homepage": "https://github.com/infrascan/infrascan#readme",
54
+ "devDependencies": {
55
+ "@aws-sdk/credential-providers": "^3.428.0",
56
+ "@infrascan/aws-codegen": "^0.1.0",
57
+ "@infrascan/fs-connector": "^0.2.1",
58
+ "@infrascan/shared-types": "^0.2.1",
59
+ "aws-sdk-client-mock": "^3.0.0",
60
+ "eslint-config-codegen": "^1.0.0",
61
+ "tsconfig": "^0.0.0"
62
+ },
63
+ "dependencies": {
64
+ "@aws-sdk/client-cloudwatch-logs": "3.428.0",
65
+ "@infrascan/core": "0.2.1"
66
+ }
67
+ }