-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
executable file
·64 lines (58 loc) · 1.82 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env node
const AWS = require("aws-sdk");
const program = require("commander");
const open = require("open");
const package = require("./package.json");
require("@mhlabs/aws-sdk-sso");
const tagCommand = require("./src/TagCommand");
const prefixCommand = require("./src/PrefixCommand");
process.env.AWS_SDK_LOAD_CONFIG = 1;
AWS.config.credentialProvider.providers.unshift(
new AWS.SingleSignOnCredentials()
);
program.version(package.version, "-v, --version", "output the current version");
program
.command("insights")
.alias("i")
.option(
"-t, --tag [tag]",
"Tag to filter on. Format: tagName:value1,value2. Optional. If omitted you will get prompted by available tags",
false
)
.option(
"-p, --prefix [prefix]",
"Log group prefix. I.e /aws/lambda/. The more granular this is specified, the faster the command will run"
)
.option(
"--pattern [pattern]",
"Regex pattern used to filter the log group names"
)
.option(
"--region [region]",
"AWS region. Defaults to environment variable AWS_REGION"
)
.option(
"--profile [profile]",
"AWS profile. Defaults to environment variable AWS_PROFILE"
)
.description(
"Opens a CloudWatch Logs console with multiple log groups matching a tag or prefix"
)
.action(async (cmd) => {
AWS.config.region = cmd.region || process.env.AWS_REGION;
process.env.AWS_PROFILE = cmd.profile || process.env.AWS_PROFILE;
const args = cmd.parent.args;
let url;
if (args.includes("--tag") || args.includes("-t")) {
url = await tagCommand.generateUrl(cmd.tag, cmd.pattern);
}
if (args.includes("--prefix") || args.includes("-p")) {
url = await prefixCommand.generateUrl(cmd.prefix, cmd.pattern);
}
if (url) {
open(url);
} else {
program.help();
}
});
program.parse(process.argv);