Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit c5592a3

Browse files
authored
add X-Ray resources (#638)
support for sampling rules & groups.
1 parent eab5b39 commit c5592a3

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed

resources/xray-group.go

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package resources
2+
3+
import (
4+
"github.com/aws/aws-sdk-go/aws/session"
5+
"github.com/aws/aws-sdk-go/service/xray"
6+
"github.com/rebuy-de/aws-nuke/pkg/types"
7+
)
8+
9+
type XRayGroup struct {
10+
svc *xray.XRay
11+
groupName *string
12+
groupARN *string
13+
}
14+
15+
func init() {
16+
register("XRayGroup", ListXRayGroups)
17+
}
18+
19+
func ListXRayGroups(sess *session.Session) ([]Resource, error) {
20+
svc := xray.New(sess)
21+
resources := []Resource{}
22+
23+
// Get X-Ray Groups
24+
var xrayGroups []*xray.GroupSummary
25+
err := svc.GetGroupsPages(
26+
&xray.GetGroupsInput{},
27+
func(page *xray.GetGroupsOutput, lastPage bool) bool {
28+
for _, group := range page.Groups {
29+
if *group.GroupName != "Default" { // Ignore the Default group as it cannot be removed
30+
xrayGroups = append(xrayGroups, group)
31+
}
32+
}
33+
return true
34+
},
35+
)
36+
if err != nil {
37+
return nil, err
38+
}
39+
40+
for _, group := range xrayGroups {
41+
resources = append(resources, &XRayGroup{
42+
svc: svc,
43+
groupName: group.GroupName,
44+
groupARN: group.GroupARN,
45+
})
46+
}
47+
48+
return resources, nil
49+
}
50+
51+
func (f *XRayGroup) Remove() error {
52+
_, err := f.svc.DeleteGroup(&xray.DeleteGroupInput{
53+
GroupARN: f.groupARN, // Only allowed to pass GroupARN _or_ GroupName to delete request
54+
})
55+
56+
return err
57+
}
58+
59+
func (f *XRayGroup) Properties() types.Properties {
60+
properties := types.NewProperties()
61+
properties.
62+
Set("GroupName", f.groupName).
63+
Set("GroupARN", f.groupARN)
64+
65+
return properties
66+
}

resources/xray-samplingrule.go

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package resources
2+
3+
import (
4+
"github.com/aws/aws-sdk-go/aws/session"
5+
"github.com/aws/aws-sdk-go/service/xray"
6+
"github.com/rebuy-de/aws-nuke/pkg/types"
7+
)
8+
9+
type XRaySamplingRule struct {
10+
svc *xray.XRay
11+
ruleName *string
12+
ruleARN *string
13+
}
14+
15+
func init() {
16+
register("XRaySamplingRule", ListXRaySamplingRules)
17+
}
18+
19+
func ListXRaySamplingRules(sess *session.Session) ([]Resource, error) {
20+
svc := xray.New(sess)
21+
resources := []Resource{}
22+
23+
var xraySamplingRules []*xray.SamplingRule
24+
err := svc.GetSamplingRulesPages(
25+
&xray.GetSamplingRulesInput{},
26+
func(page *xray.GetSamplingRulesOutput, lastPage bool) bool {
27+
for _, rule := range page.SamplingRuleRecords {
28+
if *rule.SamplingRule.RuleName != "Default" {
29+
xraySamplingRules = append(xraySamplingRules, rule.SamplingRule)
30+
}
31+
}
32+
return true
33+
},
34+
)
35+
if err != nil {
36+
return nil, err
37+
}
38+
39+
for _, rule := range xraySamplingRules {
40+
resources = append(resources, &XRaySamplingRule{
41+
svc: svc,
42+
ruleName: rule.RuleName,
43+
ruleARN: rule.RuleARN,
44+
})
45+
}
46+
47+
return resources, nil
48+
}
49+
50+
func (f *XRaySamplingRule) Remove() error {
51+
_, err := f.svc.DeleteSamplingRule(&xray.DeleteSamplingRuleInput{
52+
RuleARN: f.ruleARN, // Specify ruleARN or ruleName, not both
53+
})
54+
55+
return err
56+
}
57+
58+
func (f *XRaySamplingRule) Properties() types.Properties {
59+
properties := types.NewProperties()
60+
properties.
61+
Set("RuleName", f.ruleName).
62+
Set("RuleARN", f.ruleARN)
63+
64+
return properties
65+
}

0 commit comments

Comments
 (0)