File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import "regexp"
1212
1313var arnEc2InstanceRe = regexp .MustCompile (`^arn:aws:ec2:.+/([^/]+)` )
1414var arnEcsTaskToClusterRe = regexp .MustCompile (`^(arn:aws:ecs:[^:]+:\d+):task/([^/]+)/.*` )
15+ var arnCloudFrontDistributionRe = regexp .MustCompile (`^arn:aws:cloudfront::\d+:distribution/([^/]+)` )
1516
1617func Ec2InstanceIdFromArn (arn string ) string {
1718 return arnEc2InstanceRe .ReplaceAllString (arn , "${1}" )
@@ -20,3 +21,7 @@ func Ec2InstanceIdFromArn(arn string) string {
2021func EcsTaskArnToClusterArn (arn string ) string {
2122 return arnEcsTaskToClusterRe .ReplaceAllString (arn , "${1}:cluster/${2}" )
2223}
24+
25+ func CloudFrontDistributionIdFromArn (arn string ) string {
26+ return arnCloudFrontDistributionRe .ReplaceAllString (arn , "${1}" )
27+ }
Original file line number Diff line number Diff line change @@ -27,3 +27,14 @@ func TestEcsTaskArnToClusterArnErr(t *testing.T) {
2727 result := EcsTaskArnToClusterArn (arn )
2828 assert .Equal (t , arn , result )
2929}
30+
31+ func TestCloudFrontDistributionIdFromArn (t * testing.T ) {
32+ result := CloudFrontDistributionIdFromArn ("arn:aws:cloudfront::1234567890:distribution/E1234567890ABC" )
33+ assert .Equal (t , "E1234567890ABC" , result )
34+ }
35+
36+ func TestCloudFrontDistributionIdFromArnErr (t * testing.T ) {
37+ arn := "invalid-arn"
38+ result := CloudFrontDistributionIdFromArn (arn )
39+ assert .Equal (t , arn , result )
40+ }
You can’t perform that action at this time.
0 commit comments