Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions link2aws.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,13 @@ class ARN {
}
}

// ...:resource-type/resource-id (resource-id can contain slashes!)
else if (typeof (tokens[5]) != 'undefined' && tokens[5].indexOf('/') > 0) {
// ...:resource-type/resource-id (common case)
// ...:/resource-type/resource-id (apigateway)
// resource-id can contain slashes.
else if (typeof (tokens[5]) != 'undefined' && tokens[5].slice(1).indexOf('/') >= 0) {
if (tokens[5].startsWith('/')) {
tokens[5] = tokens[5].slice(1);
}
this.resource_type = tokens[5].slice(0, tokens[5].indexOf('/'));
this.resource = tokens[5].slice(tokens[5].indexOf('/') + 1, tokens[5].length);
this.hasPath = true;
Expand Down Expand Up @@ -182,7 +187,7 @@ class ARN {
},
},
"apigateway": { // Manage Amazon API Gateway
"": null,
"restapis": () => `https://${this.region}.${this.console}/apigateway/main/apis/${this.resource}/resources?api=${this.resource}&region=${this.region}`,
},
"appconfig": { // AWS AppConfig
"application": null,
Expand Down
14 changes: 13 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,19 @@ describe('main.ARN', function () {
assert.equal(arn.account, 'account-id');
assert.equal(arn.resource, 'resource-id');
assert.equal(arn.resource_type, 'resource-type');
});
});

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');
assert.equal(arn.region, 'region');
assert.equal(arn.account, 'account-id');
assert.equal(arn.resource, 'resource-id');
assert.equal(arn.resource_type, 'resource-type');
});

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');
Expand Down
2 changes: 2 additions & 0 deletions testcases/aws.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

"arn:aws:acm:us-east-1:123456789012:certificate/1f6ee793-4064-4a10-9567-f03875640b35": "https://console.aws.amazon.com/acm/home?region=us-east-1#/?id=1f6ee793-4064-4a10-9567-f03875640b35",

"arn:aws:apigateway:us-west-1::/restapis/abc123defg": "https://us-west-1.console.aws.amazon.com/apigateway/main/apis/abc123defg/resources?api=abc123defg&region=us-west-1",

"arn:aws:ec2:us-west-1:136693071363:image/ami-0851c4af3ebd71c35": "https://us-west-1.console.aws.amazon.com/ec2/home?region=us-west-1#ImageDetails:imageId=ami-0851c4af3ebd71c35",
"arn:aws:ec2:us-east-1:123456789012:instance/1234": "https://us-east-1.console.aws.amazon.com/ec2/home?region=us-east-1#InstanceDetails:instanceId=1234",
"arn:aws:ec2:us-east-1:123456789012:natgateway/nat-123456": "https://us-east-1.console.aws.amazon.com/vpcconsole/home?region=us-east-1#NatGatewayDetails:natGatewayId=nat-123456",
Expand Down