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"
12
12
13
13
var arnEc2InstanceRe = regexp .MustCompile (`^arn:aws:ec2:.+/([^/]+)` )
14
14
var arnEcsTaskToClusterRe = regexp .MustCompile (`^(arn:aws:ecs:[^:]+:\d+):task/([^/]+)/.*` )
15
+ var arnCloudFrontDistributionRe = regexp .MustCompile (`^arn:aws:cloudfront::\d+:distribution/([^/]+)` )
15
16
16
17
func Ec2InstanceIdFromArn (arn string ) string {
17
18
return arnEc2InstanceRe .ReplaceAllString (arn , "${1}" )
@@ -20,3 +21,7 @@ func Ec2InstanceIdFromArn(arn string) string {
20
21
func EcsTaskArnToClusterArn (arn string ) string {
21
22
return arnEcsTaskToClusterRe .ReplaceAllString (arn , "${1}:cluster/${2}" )
22
23
}
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) {
27
27
result := EcsTaskArnToClusterArn (arn )
28
28
assert .Equal (t , arn , result )
29
29
}
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