Skip to content

Commit

Permalink
secretsmanager enforce suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
dleavitt committed Aug 29, 2024
1 parent 18436fe commit 4980e53
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
11 changes: 4 additions & 7 deletions link2aws.js
Original file line number Diff line number Diff line change
Expand Up @@ -979,14 +979,11 @@ class ARN {
},
"secretsmanager": { // AWS Secrets Manager
"secret": () => {
if (this.resource.indexOf("-") === -1) {
// all the secrets I've seen have a "-" delimited suffix
// in the ARN that isn't part of the secret name. For
// now just throwing if the suffix is missing, please
// update if needed.
throw Error(`Secret ARN for ${this.resource} missing suffix`);
const arnSuffix = /-\w{6}$/;
if (!arnSuffix.test(this.resource)) {
throw Error(`Secret ARN for "${this.resource}" appears invalid, should end with ${arnSuffix}`);
}
const name = this.resource.split('-').slice(0, -1).join('-');
const name = this.resource.replace(arnSuffix, "");
return `https://${this.region}.${this.console}/${this.service}/${this.resource_type}?name=${name}`;
},
},
Expand Down
2 changes: 1 addition & 1 deletion testcases/aws-negative.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@
"arn:aws:ec2:us-ea*st-1:123456789012:instance/asdf",
"arn:aws:ec2:us-ea#st-1:123456789012:instance/asdf",
"arn:aws:ec2:us-ea\\st-1:123456789012:instance/asdf",
"arn:aws:secretsmanager:us-west-2:123456789012:secret:MySecret9A3F29"
"arn:aws:secretsmanager:us-west-2:123456789012:secret:MySecret9A3F29-adf"
]

0 comments on commit 4980e53

Please sign in to comment.