Skip to content

Commit 9f67c8d

Browse files
ekristencorybekk
authored andcommitted
feat(resource): add new OSPipeline resource for opensearch service pipelines
1 parent ef68c7b commit 9f67c8d

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package resources
2+
3+
import (
4+
"context"
5+
"time"
6+
7+
"github.com/aws/aws-sdk-go/service/osis"
8+
9+
"github.com/ekristen/libnuke/pkg/registry"
10+
"github.com/ekristen/libnuke/pkg/resource"
11+
"github.com/ekristen/libnuke/pkg/types"
12+
13+
"github.com/ekristen/aws-nuke/v3/pkg/nuke"
14+
)
15+
16+
const OSPipelineResource = "OSPipeline"
17+
18+
func init() {
19+
registry.Register(&registry.Registration{
20+
Name: OSPipelineResource,
21+
Scope: nuke.Account,
22+
Lister: &OSPipelineLister{},
23+
})
24+
}
25+
26+
type OSPipelineLister struct{}
27+
28+
func (l *OSPipelineLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) {
29+
opts := o.(*nuke.ListerOpts)
30+
var resources []resource.Resource
31+
32+
svc := osis.New(opts.Session)
33+
34+
params := &osis.ListPipelinesInput{}
35+
36+
for {
37+
res, err := svc.ListPipelines(params)
38+
if err != nil {
39+
return nil, err
40+
}
41+
42+
for _, p := range res.Pipelines {
43+
resources = append(resources, &OSPipeline{
44+
svc: svc,
45+
Name: p.PipelineName,
46+
Tags: p.Tags,
47+
Status: p.Status,
48+
CreatedAt: p.CreatedAt,
49+
})
50+
}
51+
52+
if res.NextToken == nil {
53+
break
54+
}
55+
56+
params.NextToken = res.NextToken
57+
}
58+
59+
return resources, nil
60+
}
61+
62+
type OSPipeline struct {
63+
svc *osis.OSIS
64+
Name *string
65+
Status *string
66+
CreatedAt *time.Time
67+
Tags []*osis.Tag
68+
}
69+
70+
func (r *OSPipeline) Remove(_ context.Context) error {
71+
_, err := r.svc.DeletePipeline(&osis.DeletePipelineInput{
72+
PipelineName: r.Name,
73+
})
74+
return err
75+
}
76+
77+
func (r *OSPipeline) Properties() types.Properties {
78+
return types.NewPropertiesFromStruct(r)
79+
}
80+
81+
func (r *OSPipeline) String() string {
82+
return *r.Name
83+
}

0 commit comments

Comments
 (0)