link2aws 1.0.17 → 1.0.19

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.
Files changed (2) hide show
  1. package/link2aws.js +60 -13
  2. package/package.json +1 -1
package/link2aws.js CHANGED
@@ -2,8 +2,30 @@
2
2
  // https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/resource-ids.html
3
3
  class ARN {
4
4
  constructor(text) {
5
+ if (typeof(text) != 'string') {
6
+ throw Error("ARN must be a string");
7
+ }
8
+
5
9
  text = text.trim();
6
10
 
11
+ // length limit
12
+ // There is no documented limit for ARNs in general.
13
+ // For IAM User, the documented limit is 2048.
14
+ // Please file an issue if you can find a resource type
15
+ // with a higher documented limit.
16
+ if (text.length > 2048) {
17
+ throw Error("ARN too long");
18
+ }
19
+
20
+ // Check for invalid characters.
21
+ // This is meant to catch malicious inputs. This will not
22
+ // catch all invalid ARNs, as some resource types have
23
+ // stricter rules. Please file an issue if you are aware
24
+ // of a valid ARN that is rejected by this check.
25
+ if (!/^[a-zA-Z0-9:/+=,.@_*#\-]*$/.test(text)) {
26
+ throw Error("ARN contains invalid characters");
27
+ }
28
+
7
29
  // split into tokens; leaving resource-id with colons together
8
30
  var firstTokens = text.split(':');
9
31
  var tokens = firstTokens.splice(0, 6);
@@ -12,6 +34,7 @@ class ARN {
12
34
  }
13
35
 
14
36
  // arn:partition:service:region:account-id:...
37
+ this.arn = text;
15
38
  this.prefix = tokens[0];
16
39
  this.partition = tokens[1];
17
40
  this.service = tokens[2];
@@ -53,6 +76,13 @@ class ARN {
53
76
  throw Error("Bad number of tokens");
54
77
  }
55
78
 
79
+ // region must have valid format.
80
+ // This is security relevant as it is used as a subdomain
81
+ // before the console domain.
82
+ if (this.region != '' && !/^[a-z0-9-]*$/.test(this.region)) {
83
+ throw Error(`Bad region: "${this.region}"`);
84
+ }
85
+
56
86
  this._linkTemplates = this._getLinkTemplates();
57
87
  }
58
88
 
@@ -187,14 +217,17 @@ class ARN {
187
217
  "workgroup": null,
188
218
  },
189
219
  "autoscaling": { // Amazon EC2 Auto Scaling
190
- "autoScalingGroup": null,
220
+ "autoScalingGroup": () => {
221
+ const groupName = this.resource.split('/')[1];
222
+ return `https://${this.region}.${this.console}/ec2/home?region=${this.region}#AutoScalingGroupDetails:id=${groupName};view=details`
223
+ },
191
224
  "launchConfiguration": null,
192
225
  },
193
226
  "aws-marketplace": { // AWS Marketplace Catalog
194
227
  },
195
228
  "backup": { // AWS Backup
196
229
  "backup-plan": null,
197
- "backup-vault": null,
230
+ "backup-vault": () => `https://${this.console}/backup/home?region=${this.region}#/backupvaults/details/${this.resource}`,
198
231
  },
199
232
  "batch": { // AWS Batch
200
233
  "job-definition": null,
@@ -228,7 +261,7 @@ class ARN {
228
261
  "stackset": null,
229
262
  },
230
263
  "cloudfront": { // Amazon CloudFront
231
- "distribution": null,
264
+ "distribution": () => `https://${this.console}/cloudfront/v4/home#/distributions/${this.resource}`,
232
265
  "origin-access-identity": null,
233
266
  "streaming-distribution": null,
234
267
  },
@@ -449,9 +482,14 @@ class ARN {
449
482
  "task-set": null,
450
483
  },
451
484
  "eks": { // Amazon Elastic Container Service for Kubernetes
452
- "cluster": null,
485
+ "cluster": () => `https://${this.console}/eks/home?region=${this.region}#/clusters/${this.resource}`,
453
486
  "fargateprofile": null,
454
- "nodegroup": null,
487
+ "nodegroup": () => {
488
+ const arr = this.resource.split('/');
489
+ const clusterName = arr[0];
490
+ const nodegroupName = arr[1];
491
+ return `https://${this.console}/eks/home?region=${this.region}#/clusters/${clusterName}/nodegroups/${nodegroupName}`
492
+ },
455
493
  },
456
494
  "elastic-inference": { // Amazon Elastic Inference
457
495
  "elastic-inference-accelerator": null,
@@ -494,7 +532,7 @@ class ARN {
494
532
  "execute-api": { // Amazon API Gateway
495
533
  },
496
534
  "firehose": { // Amazon Kinesis Firehose
497
- "deliverystream": null,
535
+ "deliverystream": () => `https://${this.console}/firehose/home?region=${this.region}#/details/${this.resource}/monitoring`,
498
536
  },
499
537
  "fms": { // AWS Firewall Manager
500
538
  "policy": null,
@@ -660,7 +698,7 @@ class ARN {
660
698
  },
661
699
  "kms": { // AWS Key Management Service
662
700
  "alias": null,
663
- "key": null,
701
+ "key": () => `https://${this.console}/kms/home?region=${this.region}#/kms/keys/${this.resource}`,
664
702
  },
665
703
  "lambda": { // AWS Lambda
666
704
  "event-source-mapping": null,
@@ -825,19 +863,19 @@ class ARN {
825
863
  "resource-share-invitation": null,
826
864
  },
827
865
  "rds": { // Amazon RDS
828
- "cluster": null,
866
+ "cluster": () => `https://${this.console}/rds/home?region=${this.region}#database:id=${this.resource};is-cluster=true`,
829
867
  "cluster-endpoint": null,
830
868
  "cluster-pg": null,
831
869
  "cluster-snapshot": null,
832
- "db": null,
870
+ "db": () => `https://${this.console}/rds/home?region=${this.region}#database:id=${this.resource}`,
833
871
  "db-proxy": null,
834
872
  "es": null,
835
- "og": null,
873
+ "og": () => `https://${this.console}/rds/home?region=${this.region}#option-group-details:option-group-name=${this.resource}`,
836
874
  "pg": null,
837
875
  "ri": null,
838
876
  "secgrp": null,
839
- "snapshot": null,
840
- "subgrp": null,
877
+ "snapshot": () => `https://${this.console}/rds/home?region=${this.region}#db-snapshot:id=${this.resource}`,
878
+ "subgrp": () => `https://${this.console}/rds/home?region=${this.region}#db-subnet-group:id=${this.resource}`,
841
879
  "target": null,
842
880
  "target-group": null,
843
881
  },
@@ -969,6 +1007,7 @@ class ARN {
969
1007
  "": null,
970
1008
  },
971
1009
  "sns": { // Amazon SNS
1010
+ "": () => `https://${this.console}/sns/v3/home?region=${this.region}#/topic/${this.arn}`,
972
1011
  },
973
1012
  "sqs": { // Amazon SQS
974
1013
  "": () => `https://${this.region}.${this.console}/sqs/v2/home?region=${this.region}#/queues/https%3A%2F%2Fsqs.${this.region}.amazonaws.com%2F${this.account}%2F${this.resource}`
@@ -1044,7 +1083,15 @@ class ARN {
1044
1083
  "webacl": null,
1045
1084
  "xssmatchset": null,
1046
1085
  },
1047
- "wafv2": { // AWS WAF V2
1086
+ "wafv2": { // AWS WAF V2
1087
+ "global": () => {
1088
+ const resource = this.resource.replace("webacl/", "");
1089
+ return `https://${this.console}/wafv2/homev2/web-acl/${resource}/overview?region=global`
1090
+ },
1091
+ "regional": () => {
1092
+ const resource = this.resource.replace("webacl/", "");
1093
+ return `https://${this.console}/wafv2/homev2/web-acl/${resource}/overview?region=${this.region}`
1094
+ }
1048
1095
  },
1049
1096
  "wellarchitected": { // AWS Well-Architected Tool
1050
1097
  "workload": null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "link2aws",
3
- "version": "1.0.17",
3
+ "version": "1.0.19",
4
4
  "description": "Convert ARN (Amazon Resource Name) to AWS Console link",
5
5
  "main": "link2aws.js",
6
6
  "directories": {