diff --git a/link2aws.js b/link2aws.js index 6e81bbc..5e0b774 100644 --- a/link2aws.js +++ b/link2aws.js @@ -12,6 +12,7 @@ class ARN { } // arn:partition:service:region:account-id:... + this.arn = text; this.prefix = tokens[0]; this.partition = tokens[1]; this.service = tokens[2]; @@ -187,14 +188,17 @@ class ARN { "workgroup": null, }, "autoscaling": { // Amazon EC2 Auto Scaling - "autoScalingGroup": null, + "autoScalingGroup": () => { + const groupName = this.resource.split('/')[1]; + return `https://${this.region}.${this.console}/ec2/home?region=${this.region}#AutoScalingGroupDetails:id=${groupName};view=details` + }, "launchConfiguration": null, }, "aws-marketplace": { // AWS Marketplace Catalog }, "backup": { // AWS Backup "backup-plan": null, - "backup-vault": null, + "backup-vault": () => `https://${this.console}/backup/home?region=${this.region}#/backupvaults/details/${this.resource}`, }, "batch": { // AWS Batch "job-definition": null, @@ -228,7 +232,7 @@ class ARN { "stackset": null, }, "cloudfront": { // Amazon CloudFront - "distribution": null, + "distribution": () => `https://${this.console}/cloudfront/v4/home#/distributions/${this.resource}`, "origin-access-identity": null, "streaming-distribution": null, }, @@ -449,9 +453,14 @@ class ARN { "task-set": null, }, "eks": { // Amazon Elastic Container Service for Kubernetes - "cluster": null, + "cluster": () => `https://${this.console}/eks/home?region=${this.region}#/clusters/${this.resource}`, "fargateprofile": null, - "nodegroup": null, + "nodegroup": () => { + const arr = this.resource.split('/'); + const clusterName = arr[0]; + const nodegroupName = arr[1]; + return `https://${this.console}/eks/home?region=${this.region}#/clusters/${clusterName}/nodegroups/${nodegroupName}` + }, }, "elastic-inference": { // Amazon Elastic Inference "elastic-inference-accelerator": null, @@ -494,7 +503,7 @@ class ARN { "execute-api": { // Amazon API Gateway }, "firehose": { // Amazon Kinesis Firehose - "deliverystream": null, + "deliverystream": () => `https://${this.console}/firehose/home?region=${this.region}#/details/${this.resource}/monitoring`, }, "fms": { // AWS Firewall Manager "policy": null, @@ -660,7 +669,7 @@ class ARN { }, "kms": { // AWS Key Management Service "alias": null, - "key": null, + "key": () => `https://${this.console}/kms/home?region=${this.region}#/kms/keys/${this.resource}`, }, "lambda": { // AWS Lambda "event-source-mapping": null, @@ -825,19 +834,19 @@ class ARN { "resource-share-invitation": null, }, "rds": { // Amazon RDS - "cluster": null, + "cluster": () => `https://${this.console}/rds/home?region=${this.region}#database:id=${this.resource};is-cluster=true`, "cluster-endpoint": null, "cluster-pg": null, "cluster-snapshot": null, - "db": null, + "db": () => `https://${this.console}/rds/home?region=${this.region}#database:id=${this.resource}`, "db-proxy": null, "es": null, - "og": null, + "og": () => `https://${this.console}/rds/home?region=${this.region}#option-group-details:option-group-name=${this.resource}`, "pg": null, "ri": null, "secgrp": null, - "snapshot": null, - "subgrp": null, + "snapshot": () => `https://${this.console}/rds/home?region=${this.region}#db-snapshot:id=${this.resource}`, + "subgrp": () => `https://${this.console}/rds/home?region=${this.region}#db-subnet-group:id=${this.resource}`, "target": null, "target-group": null, }, @@ -969,6 +978,7 @@ class ARN { "": null, }, "sns": { // Amazon SNS + "": () => `https://${this.console}/sns/v3/home?region=${this.region}#/topic/${this.arn}`, }, "sqs": { // Amazon SQS "": () => `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 +1054,15 @@ class ARN { "webacl": null, "xssmatchset": null, }, - "wafv2": { // AWS WAF V2 + "wafv2": { // AWS WAF V2 + "global": () => { + const resource = this.resource.replace("webacl/", ""); + return `https://${this.console}/wafv2/homev2/web-acl/${resource}/overview?region=global` + }, + "regional": () => { + const resource = this.resource.replace("webacl/", ""); + return `https://${this.console}/wafv2/homev2/web-acl/${resource}/overview?region=${this.region}` + } }, "wellarchitected": { // AWS Well-Architected Tool "workload": null, diff --git a/test/test.js b/test/test.js index 464055d..aba2db9 100644 --- a/test/test.js +++ b/test/test.js @@ -13,6 +13,7 @@ describe('main.ARN', function () { it('should tokenize ARNs without resource-type', function () { var arn = new main.ARN('arn:partition:service:region:account-id:resource-id'); + assert.equal(arn.arn, 'arn:partition:service:region:account-id:resource-id'); assert.equal(arn.prefix, 'arn'); assert.equal(arn.partition, 'partition'); assert.equal(arn.service, 'service'); @@ -24,6 +25,7 @@ describe('main.ARN', function () { it('should tokenize ARNs with resource-type/resource-id', function () { var arn = new main.ARN('arn:partition:service:region:account-id:resource-type/resource-id'); + assert.equal(arn.arn, 'arn:partition:service:region:account-id:resource-type/resource-id') assert.equal(arn.prefix, 'arn'); assert.equal(arn.partition, 'partition'); assert.equal(arn.service, 'service'); @@ -35,6 +37,7 @@ describe('main.ARN', function () { it('should tokenize ARNs with resource-type:resource-id', function () { var arn = new main.ARN('arn:partition:service:region:account-id:resource-type:resource-id'); + assert.equal(arn.arn, 'arn:partition:service:region:account-id:resource-type:resource-id'); assert.equal(arn.prefix, 'arn'); assert.equal(arn.partition, 'partition'); assert.equal(arn.service, 'service'); @@ -47,6 +50,7 @@ describe('main.ARN', function () { it('should tokenize ARNs with resource-type:resource-id-qualifier-1:qualifier-2:qualifier-3', function () { var arn = new main.ARN('arn:partition:service:region:account-id:resource-type:resource-id-qualifier-1:qualifier-2:qualifier-3'); + assert.equal(arn.arn, 'arn:partition:service:region:account-id:resource-type:resource-id-qualifier-1:qualifier-2:qualifier-3'); assert.equal(arn.prefix, 'arn'); assert.equal(arn.partition, 'partition'); assert.equal(arn.service, 'service'); diff --git a/testcases/aws.json b/testcases/aws.json index a92d630..1f95c71 100644 --- a/testcases/aws.json +++ b/testcases/aws.json @@ -51,5 +51,29 @@ "arn:aws:amplify:sa-east-1:384862141196:apps/aaaaaaaaa/branches/master/jobs/00000001810": "https://sa-east-1.console.aws.amazon.com/amplify/home?region=sa-east-1#/aaaaaaaaa/master/1810", "arn:aws:amplify:sa-east-1:384862141196:apps/test-null-path": null, - "arn:aws:codepipeline:us-east-1:115131055398:my-pipeline": "https://us-east-1.console.aws.amazon.com/codesuite/codepipeline/pipelines/my-pipeline/view?region=us-east-1" + "arn:aws:codepipeline:us-east-1:115131055398:my-pipeline": "https://us-east-1.console.aws.amazon.com/codesuite/codepipeline/pipelines/my-pipeline/view?region=us-east-1", + + "arn:aws:cloudfront::123456789012:distribution/E2YDLZ26QPSF11": "https://console.aws.amazon.com/cloudfront/v4/home#/distributions/E2YDLZ26QPSF11", + + "arn:aws:autoscaling:us-east-1:123456789012:autoScalingGroup:034d7396-90f3-r8si-88f5-ff1dcc0eb80e:autoScalingGroupName/test": "https://us-east-1.console.aws.amazon.com/ec2/home?region=us-east-1#AutoScalingGroupDetails:id=test;view=details", + + "arn:aws:wafv2:us-east-1:123456789012:global/webacl/test/f8234ecc-8990-4e63-b25a-ec36764b7701": "https://console.aws.amazon.com/wafv2/homev2/web-acl/test/f8234ecc-8990-4e63-b25a-ec36764b7701/overview?region=global", + "arn:aws:wafv2:us-east-1:123456789012:regional/webacl/test/0089db7f-b629-4ba6-bdad-8b2f3ec31c86": "https://console.aws.amazon.com/wafv2/homev2/web-acl/test/0089db7f-b629-4ba6-bdad-8b2f3ec31c86/overview?region=us-east-1", + + "arn:aws:sns:us-east-1:123456789012:sns-topic": "https://console.aws.amazon.com/sns/v3/home?region=us-east-1#/topic/arn:aws:sns:us-east-1:123456789012:sns-topic", + + "arn:aws:rds:us-east-1:123456789012:db:test-db": "https://console.aws.amazon.com/rds/home?region=us-east-1#database:id=test-db", + "arn:aws:rds:us-east-1:123456789012:snapshot:rds:test-db-2024-02-04-22-12": "https://console.aws.amazon.com/rds/home?region=us-east-1#db-snapshot:id=rds:test-db-2024-02-04-22-12", + "arn:aws:rds:us-east-1:123456789012:subgrp:test-db": "https://console.aws.amazon.com/rds/home?region=us-east-1#db-subnet-group:id=test-db", + "arn:aws:rds:us-east-1:123456789012:og:test-db": "https://console.aws.amazon.com/rds/home?region=us-east-1#option-group-details:option-group-name=test-db", + "arn:aws:rds:us-east-1:123456789012:cluster:test-cluster": "https://console.aws.amazon.com/rds/home?region=us-east-1#database:id=test-cluster;is-cluster=true", + + "arn:aws:kms:us-east-1:123456789012:key/4bd42b4b-af95-4698-b685-58d3296890fe": "https://console.aws.amazon.com/kms/home?region=us-east-1#/kms/keys/4bd42b4b-af95-4698-b685-58d3296890fe", + + "arn:aws:eks:us-east-1:123456789012:cluster/test-cluster": "https://console.aws.amazon.com/eks/home?region=us-east-1#/clusters/test-cluster", + "arn:aws:eks:us-east-1:123456789012:nodegroup/test-cluster/test-workers/a2c51527-da50-031f-1130-c5d5d77be06c": "https://console.aws.amazon.com/eks/home?region=us-east-1#/clusters/test-cluster/nodegroups/test-workers", + + "arn:aws:backup:us-east-1:123456789012:backup-vault:backups-primary": "https://console.aws.amazon.com/backup/home?region=us-east-1#/backupvaults/details/backups-primary", + + "arn:aws:firehose:us-east-1:123456789012:deliverystream/test-stream": "https://console.aws.amazon.com/firehose/home?region=us-east-1#/details/test-stream/monitoring" } \ No newline at end of file