Skip to content

Commit d63711a

Browse files
style: prettier config applied
1 parent 2579043 commit d63711a

32 files changed

+7304
-7198
lines changed

package-lock.json

Lines changed: 5920 additions & 5920 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
{
2-
"name": "aws-resource-discovery-tool",
3-
"version": "0.0.1",
4-
"main": "dist/index.js",
5-
"scripts": {
6-
"start": "node dist/index.js",
7-
"build": "tsc",
8-
"dev": "ts-node src/index.ts"
9-
},
10-
"license": "MIT",
11-
"devDependencies": {
12-
"@types/node": "^20.12.7",
13-
"@types/yargs": "^17.0.32",
14-
"ts-node": "^10.9.2",
15-
"typescript": "^5.4.5"
16-
},
17-
"dependencies": {
18-
"@aws-sdk/client-auto-scaling": "^3.556.0",
19-
"@aws-sdk/client-cloudfront": "^3.569.0",
20-
"@aws-sdk/client-cloudtrail": "^3.556.0",
21-
"@aws-sdk/client-dynamodb": "^3.556.0",
22-
"@aws-sdk/client-ec2": "^3.557.0",
23-
"@aws-sdk/client-ecs": "^3.569.0",
24-
"@aws-sdk/client-efs": "^3.569.0",
25-
"@aws-sdk/client-eks": "^3.569.0",
26-
"@aws-sdk/client-lambda": "^3.556.0",
27-
"@aws-sdk/client-rds": "^3.556.0",
28-
"@aws-sdk/client-s3": "^3.556.0",
29-
"@aws-sdk/client-sts": "^3.577.0",
30-
"@aws-sdk/smithy-client": "^3.374.0",
31-
"@aws-sdk/util-arn-parser": "^3.568.0",
32-
"@mirohq/prettier-config": "^2.0.0",
33-
"yargs": "^17.7.2"
34-
}
35-
}
2+
"name": "aws-resource-discovery-tool",
3+
"version": "0.0.1",
4+
"main": "dist/index.js",
5+
"scripts": {
6+
"start": "node dist/index.js",
7+
"build": "tsc",
8+
"dev": "ts-node src/index.ts"
9+
},
10+
"license": "MIT",
11+
"devDependencies": {
12+
"@types/node": "^20.12.7",
13+
"@types/yargs": "^17.0.32",
14+
"ts-node": "^10.9.2",
15+
"typescript": "^5.4.5"
16+
},
17+
"dependencies": {
18+
"@aws-sdk/client-auto-scaling": "^3.556.0",
19+
"@aws-sdk/client-cloudfront": "^3.569.0",
20+
"@aws-sdk/client-cloudtrail": "^3.556.0",
21+
"@aws-sdk/client-dynamodb": "^3.556.0",
22+
"@aws-sdk/client-ec2": "^3.557.0",
23+
"@aws-sdk/client-ecs": "^3.569.0",
24+
"@aws-sdk/client-efs": "^3.569.0",
25+
"@aws-sdk/client-eks": "^3.569.0",
26+
"@aws-sdk/client-lambda": "^3.556.0",
27+
"@aws-sdk/client-rds": "^3.556.0",
28+
"@aws-sdk/client-s3": "^3.556.0",
29+
"@aws-sdk/client-sts": "^3.577.0",
30+
"@aws-sdk/smithy-client": "^3.374.0",
31+
"@aws-sdk/util-arn-parser": "^3.568.0",
32+
"@mirohq/prettier-config": "^2.0.0",
33+
"yargs": "^17.7.2"
34+
}
35+
}

prettier.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = require('@mirohq/prettier-config')
1+
module.exports = require('@mirohq/prettier-config')

src/app/args.ts

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,49 @@
1-
import yargs from 'yargs';
2-
import { hideBin } from 'yargs/helpers';
3-
import { Config } from '../types';
4-
import { awsRegionIds } from '../constants';
1+
import yargs from 'yargs'
2+
import {hideBin} from 'yargs/helpers'
3+
import {Config} from '../types'
4+
import {awsRegionIds} from '../constants'
55

66
export const config = yargs(hideBin(process.argv))
7-
.option('regions', {
8-
alias: 'r',
9-
type: 'array',
10-
description: 'List of regions to scan',
11-
demandOption: true,
12-
coerce: (arg: string[]) => {
13-
const invalidRegions = arg.filter(region => !awsRegionIds.includes(region));
14-
if (invalidRegions.length > 0) {
15-
throw new Error(`Invalid region(s): ${invalidRegions.join(', ')}. Valid regions are: ${awsRegionIds.join(', ')}`);
16-
}
17-
return arg;
18-
}
19-
})
20-
.option('output', {
21-
alias: 'o',
22-
type: 'string',
23-
description: 'Output file path (must be .json)',
24-
demandOption: true,
25-
coerce: (arg: string | string[]) => {
26-
if (Array.isArray(arg)) {
27-
arg = arg.filter(Boolean)[0] || '';
28-
}
29-
if (!arg.endsWith('.json')) {
30-
throw new Error('Output file must have a .json extension');
31-
}
32-
return arg;
33-
}
34-
})
35-
.option('compressed', {
36-
alias: 'c',
37-
type: 'boolean',
38-
description: 'Compress the output',
39-
default: false
40-
})
41-
.option('regional-only', {
42-
alias: 'ro',
43-
type: 'boolean',
44-
description: 'Only scan regional services and ignore global services',
45-
default: false
46-
})
47-
.strict()
48-
.argv as unknown as Config;
7+
.option('regions', {
8+
alias: 'r',
9+
type: 'array',
10+
description: 'List of regions to scan',
11+
demandOption: true,
12+
coerce: (arg: string[]) => {
13+
const invalidRegions = arg.filter((region) => !awsRegionIds.includes(region))
14+
if (invalidRegions.length > 0) {
15+
throw new Error(
16+
`Invalid region(s): ${invalidRegions.join(', ')}. Valid regions are: ${awsRegionIds.join(', ')}`,
17+
)
18+
}
19+
return arg
20+
},
21+
})
22+
.option('output', {
23+
alias: 'o',
24+
type: 'string',
25+
description: 'Output file path (must be .json)',
26+
demandOption: true,
27+
coerce: (arg: string | string[]) => {
28+
if (Array.isArray(arg)) {
29+
arg = arg.filter(Boolean)[0] || ''
30+
}
31+
if (!arg.endsWith('.json')) {
32+
throw new Error('Output file must have a .json extension')
33+
}
34+
return arg
35+
},
36+
})
37+
.option('compressed', {
38+
alias: 'c',
39+
type: 'boolean',
40+
description: 'Compress the output',
41+
default: false,
42+
})
43+
.option('regional-only', {
44+
alias: 'ro',
45+
type: 'boolean',
46+
description: 'Only scan regional services and ignore global services',
47+
default: false,
48+
})
49+
.strict().argv as unknown as Config

src/app/getCredentials.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import { STSClient, GetCallerIdentityCommand } from "@aws-sdk/client-sts";
2-
import { Config, Credentials } from "../types";
1+
import {STSClient, GetCallerIdentityCommand} from '@aws-sdk/client-sts'
2+
import {Config, Credentials} from '../types'
33

4-
export const NO_ASSUME_ROLE_ERROR = "NO_ASSUMED_ROLE_ERROR";
4+
export const NO_ASSUME_ROLE_ERROR = 'NO_ASSUMED_ROLE_ERROR'
55

66
export async function getCredentials(_: Config): Promise<Credentials> {
7-
const client = new STSClient({});
7+
const client = new STSClient({})
88

9-
try {
10-
// Check if a role is already assumed in the terminal session
11-
const command = new GetCallerIdentityCommand({});
12-
const response = await client.send(command);
9+
try {
10+
// Check if a role is already assumed in the terminal session
11+
const command = new GetCallerIdentityCommand({})
12+
const response = await client.send(command)
1313

14-
if (response.Arn) {
15-
return {};
16-
} else {
17-
throw new Error(NO_ASSUME_ROLE_ERROR);
18-
}
19-
} catch (error) {
20-
throw new Error(NO_ASSUME_ROLE_ERROR);
21-
}
14+
if (response.Arn) {
15+
return {}
16+
} else {
17+
throw new Error(NO_ASSUME_ROLE_ERROR)
18+
}
19+
} catch (error) {
20+
throw new Error(NO_ASSUME_ROLE_ERROR)
21+
}
2222
}

src/app/hooks/Logger.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import { Resources, ScannerLifecycleHook } from "../../types";
1+
import {Resources, ScannerLifecycleHook} from '../../types'
22

33
export class Logger implements ScannerLifecycleHook {
4-
getLegend(service: string, region?: string): string {
5-
const timestamp = new Date().toISOString();
6-
const regionInfo = region ? ` in ${region}` : '';
7-
return `[${timestamp}] [${service}${regionInfo}]`;
8-
}
4+
getLegend(service: string, region?: string): string {
5+
const timestamp = new Date().toISOString()
6+
const regionInfo = region ? ` in ${region}` : ''
7+
return `[${timestamp}] [${service}${regionInfo}]`
8+
}
99

10-
onStart(service: string, region?: string): void {
11-
console.info(`🆕 ${this.getLegend(service, region)}: scanning...`);
12-
}
13-
14-
onComplete(resources: Resources, service: string, region?: string): void {
15-
console.info(`✅ ${this.getLegend(service, region)}: discovered ${Object.keys(resources).length} resources.`);
16-
}
17-
18-
onError(error: Error, service: string, region?: string): void {
19-
console.error(`❌ ${this.getLegend(service, region)}: ${error.message}`);
20-
}
10+
onStart(service: string, region?: string): void {
11+
console.info(`🆕 ${this.getLegend(service, region)}: scanning...`)
12+
}
13+
14+
onComplete(resources: Resources, service: string, region?: string): void {
15+
console.info(`✅ ${this.getLegend(service, region)}: discovered ${Object.keys(resources).length} resources.`)
16+
}
17+
18+
onError(error: Error, service: string, region?: string): void {
19+
console.error(`❌ ${this.getLegend(service, region)}: ${error.message}`)
20+
}
2121
}

src/app/scan-and-save-as-json.ts

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,57 @@
1-
import { config } from './args';
2-
import { Logger } from "./hooks/Logger";
3-
import { getAwsScanners } from "../scanners"
4-
import { StandardOutputSchema, ScannerError, Config } from "../types"
5-
import { saveAsJson } from "./utils/saveAsJson"
6-
import { NO_ASSUME_ROLE_ERROR, getCredentials } from "./getCredentials";
1+
import {config} from './args'
2+
import {Logger} from './hooks/Logger'
3+
import {getAwsScanners} from '../scanners'
4+
import {StandardOutputSchema, ScannerError, Config} from '../types'
5+
import {saveAsJson} from './utils/saveAsJson'
6+
import {NO_ASSUME_ROLE_ERROR, getCredentials} from './getCredentials'
77

88
export const scanAndSaveAsJson = async () => {
9-
// get STS credentials
10-
let credentials
11-
try {
12-
credentials = await getCredentials(config);
13-
} catch (error) {
14-
if ((error as Error).message === NO_ASSUME_ROLE_ERROR) {
15-
console.error("\n[ERROR] No role is assumed! Please run `assume` command to assume a role before running this script!\n");
16-
process.exit(1);
17-
}
18-
throw error;
19-
}
9+
// get STS credentials
10+
let credentials
11+
try {
12+
credentials = await getCredentials(config)
13+
} catch (error) {
14+
if ((error as Error).message === NO_ASSUME_ROLE_ERROR) {
15+
console.error(
16+
'\n[ERROR] No role is assumed! Please run `assume` command to assume a role before running this script!\n',
17+
)
18+
process.exit(1)
19+
}
20+
throw error
21+
}
2022

21-
// prepare scanners
22-
const shouldIncludeGlobalServices = !config['regional-only'];
23-
const scanners = getAwsScanners(credentials, config.regions, shouldIncludeGlobalServices, [
24-
new Logger(), // log scanning progress
25-
]);
23+
// prepare scanners
24+
const shouldIncludeGlobalServices = !config['regional-only']
25+
const scanners = getAwsScanners(credentials, config.regions, shouldIncludeGlobalServices, [
26+
new Logger(), // log scanning progress
27+
])
2628

27-
// run scanners
28-
const startedAt = new Date().toISOString()
29-
const result = await Promise.all(scanners.map(scanner => scanner()))
30-
const finishedAt = new Date().toISOString()
29+
// run scanners
30+
const startedAt = new Date().toISOString()
31+
const result = await Promise.all(scanners.map((scanner) => scanner()))
32+
const finishedAt = new Date().toISOString()
3133

32-
// aggregate resources
33-
const resources = result.reduce((acc, { resources }) => {
34-
return { ...acc, ...resources }
35-
}, {})
34+
// aggregate resources
35+
const resources = result.reduce((acc, {resources}) => {
36+
return {...acc, ...resources}
37+
}, {})
3638

37-
// aggregate errors
38-
const errors = result.reduce((acc, { errors }) => {
39-
return [...acc, ...errors]
40-
}, [] as ScannerError[])
39+
// aggregate errors
40+
const errors = result.reduce((acc, {errors}) => {
41+
return [...acc, ...errors]
42+
}, [] as ScannerError[])
4143

42-
// create output
43-
const output: StandardOutputSchema = {
44-
provider: 'aws',
45-
docVersion: '0.0.1',
46-
resources,
47-
errors,
48-
metadata: {
49-
startedAt,
50-
finishedAt,
51-
},
52-
}
44+
// create output
45+
const output: StandardOutputSchema = {
46+
provider: 'aws',
47+
docVersion: '0.0.1',
48+
resources,
49+
errors,
50+
metadata: {
51+
startedAt,
52+
finishedAt,
53+
},
54+
}
5355

54-
saveAsJson(config.output, output, config.compressed)
55-
}
56+
saveAsJson(config.output, output, config.compressed)
57+
}

src/app/utils/saveAsJson.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { promises } from "fs"
1+
import {promises} from 'fs'
22

33
export function saveAsJson(fileName: string, data: object, compressed: boolean = false) {
4-
return promises.writeFile(fileName, JSON.stringify(data, null, compressed ? 0 : 2))
5-
}
4+
return promises.writeFile(fileName, JSON.stringify(data, null, compressed ? 0 : 2))
5+
}

0 commit comments

Comments
 (0)