Skip to content

Commit cc5548a

Browse files
committed
feat: adding support for s3 access grants, grant, instance, location
1 parent bafba21 commit cc5548a

File tree

5 files changed

+241
-0
lines changed

5 files changed

+241
-0
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ require (
3636
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.4.7 // indirect
3737
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.7 // indirect
3838
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.7 // indirect
39+
github.com/aws/aws-sdk-go-v2/service/s3control v1.52.1 // indirect
3940
github.com/aws/aws-sdk-go-v2/service/ssmquicksetup v1.3.2 // indirect
4041
github.com/aws/aws-sdk-go-v2/service/sso v1.24.8 // indirect
4142
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.7 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.7 h1:Hi0KGbrnr57bEH
3030
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.7/go.mod h1:wKNgWgExdjjrm4qvfbTorkvocEstaoDl4WCvGfeCy9c=
3131
github.com/aws/aws-sdk-go-v2/service/s3 v1.71.1 h1:aOVVZJgWbaH+EJYPvEgkNhCEbXXvH7+oML36oaPK3zE=
3232
github.com/aws/aws-sdk-go-v2/service/s3 v1.71.1/go.mod h1:r+xl5yzMk9083rMR+sJ5TYj9Tihvf/l1oxzZXDgGj2Q=
33+
github.com/aws/aws-sdk-go-v2/service/s3control v1.52.1 h1:xxGbXbGtO/VMz2JqB1UwEDlSchryUss0KmQJSZ0oTUE=
34+
github.com/aws/aws-sdk-go-v2/service/s3control v1.52.1/go.mod h1:6BuUa52of67a+ri/poTH82XiL+rTGQWUPZCmf2cfVHI=
3335
github.com/aws/aws-sdk-go-v2/service/ssmquicksetup v1.3.2 h1:4siT1z3nEVxJq1jZYu1SRoct5xgbKen+ammCuZBZ2zI=
3436
github.com/aws/aws-sdk-go-v2/service/ssmquicksetup v1.3.2/go.mod h1:KSO1+erW2SUB6Mw/Qamu1fOT5fn/mzd9G79ENbYqyRQ=
3537
github.com/aws/aws-sdk-go-v2/service/sso v1.24.8 h1:CvuUmnXI7ebaUAhbJcDy9YQx8wHR69eZ9I7q5hszt/g=
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package resources
2+
3+
import (
4+
"context"
5+
"strings"
6+
"time"
7+
8+
"github.com/gotidy/ptr"
9+
10+
"github.com/aws/aws-sdk-go-v2/service/s3control"
11+
12+
"github.com/ekristen/libnuke/pkg/registry"
13+
"github.com/ekristen/libnuke/pkg/resource"
14+
"github.com/ekristen/libnuke/pkg/types"
15+
16+
"github.com/ekristen/aws-nuke/v3/pkg/nuke"
17+
)
18+
19+
const S3AccessGrantsGrantResource = "S3AccessGrantsGrant"
20+
21+
func init() {
22+
registry.Register(&registry.Registration{
23+
Name: S3AccessGrantsGrantResource,
24+
Scope: nuke.Account,
25+
Resource: &S3AccessGrantsGrant{},
26+
Lister: &S3AccessGrantsGrantLister{},
27+
})
28+
}
29+
30+
type S3AccessGrantsGrantLister struct{}
31+
32+
func (l *S3AccessGrantsGrantLister) List(ctx context.Context, o interface{}) ([]resource.Resource, error) {
33+
opts := o.(*nuke.ListerOpts)
34+
svc := s3control.NewFromConfig(*opts.Config)
35+
var resources []resource.Resource
36+
37+
res, err := svc.ListAccessGrants(ctx, &s3control.ListAccessGrantsInput{
38+
AccountId: opts.AccountID,
39+
})
40+
if err != nil {
41+
if strings.Contains(err.Error(), "AccessGrantsInstanceNotExistsError") {
42+
return resources, nil
43+
} else {
44+
return nil, err
45+
}
46+
}
47+
48+
for _, p := range res.AccessGrantsList {
49+
resources = append(resources, &S3AccessGrantsGrant{
50+
svc: svc,
51+
ID: p.AccessGrantId,
52+
GrantScope: p.GrantScope,
53+
GranteeType: ptr.String(string(p.Grantee.GranteeType)),
54+
GranteeID: p.Grantee.GranteeIdentifier,
55+
CreatedAt: p.CreatedAt,
56+
})
57+
}
58+
59+
return resources, nil
60+
}
61+
62+
type S3AccessGrantsGrant struct {
63+
svc *s3control.Client
64+
ID *string `description:"The ID of the access grant."`
65+
GrantScope *string `description:"The scope of the access grant."`
66+
GranteeType *string `description:"The type of the grantee, (e.g. IAM)."`
67+
GranteeID *string `description:"The ARN of the grantee."`
68+
CreatedAt *time.Time `description:"The date and time the access grant was created."`
69+
}
70+
71+
func (r *S3AccessGrantsGrant) Remove(ctx context.Context) error {
72+
_, err := r.svc.DeleteAccessGrant(ctx, &s3control.DeleteAccessGrantInput{
73+
AccessGrantId: r.ID,
74+
})
75+
return err
76+
}
77+
78+
func (r *S3AccessGrantsGrant) Properties() types.Properties {
79+
return types.NewPropertiesFromStruct(r)
80+
}
81+
82+
func (r *S3AccessGrantsGrant) String() string {
83+
return *r.ID
84+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package resources
2+
3+
import (
4+
"context"
5+
"time"
6+
7+
"github.com/aws/aws-sdk-go-v2/service/s3control"
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 S3AccessGrantsInstanceResource = "S3AccessGrantsInstance"
17+
18+
func init() {
19+
registry.Register(&registry.Registration{
20+
Name: S3AccessGrantsInstanceResource,
21+
Scope: nuke.Account,
22+
Resource: &S3AccessGrantsInstance{},
23+
Lister: &S3AccessGrantsInstanceLister{},
24+
})
25+
}
26+
27+
type S3AccessGrantsInstanceLister struct{}
28+
29+
func (l *S3AccessGrantsInstanceLister) List(ctx context.Context, o interface{}) ([]resource.Resource, error) {
30+
opts := o.(*nuke.ListerOpts)
31+
svc := s3control.NewFromConfig(*opts.Config)
32+
var resources []resource.Resource
33+
34+
res, err := svc.ListAccessGrantsInstances(ctx, &s3control.ListAccessGrantsInstancesInput{
35+
AccountId: opts.AccountID,
36+
})
37+
if err != nil {
38+
return nil, err
39+
}
40+
41+
for _, entity := range res.AccessGrantsInstancesList {
42+
resources = append(resources, &S3AccessGrantsInstance{
43+
svc: svc,
44+
accountID: opts.AccountID,
45+
ID: entity.AccessGrantsInstanceId,
46+
CreatedAt: entity.CreatedAt,
47+
})
48+
}
49+
50+
return resources, nil
51+
}
52+
53+
type S3AccessGrantsInstance struct {
54+
svc *s3control.Client
55+
accountID *string
56+
ID *string `description:"The ID of the access grants instance."`
57+
CreatedAt *time.Time `description:"The time the access grants instance was created."`
58+
}
59+
60+
func (r *S3AccessGrantsInstance) Remove(ctx context.Context) error {
61+
_, err := r.svc.DeleteAccessGrantsInstance(ctx, &s3control.DeleteAccessGrantsInstanceInput{
62+
AccountId: r.accountID,
63+
})
64+
return err
65+
}
66+
67+
func (r *S3AccessGrantsInstance) Properties() types.Properties {
68+
return types.NewPropertiesFromStruct(r)
69+
}
70+
71+
func (r *S3AccessGrantsInstance) String() string {
72+
return *r.ID
73+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package resources
2+
3+
import (
4+
"context"
5+
"strings"
6+
"time"
7+
8+
"github.com/aws/aws-sdk-go-v2/service/s3control"
9+
10+
"github.com/ekristen/libnuke/pkg/registry"
11+
"github.com/ekristen/libnuke/pkg/resource"
12+
"github.com/ekristen/libnuke/pkg/types"
13+
14+
"github.com/ekristen/aws-nuke/v3/pkg/nuke"
15+
)
16+
17+
const S3AccessGrantsLocationResource = "S3AccessGrantsLocation"
18+
19+
func init() {
20+
registry.Register(&registry.Registration{
21+
Name: S3AccessGrantsLocationResource,
22+
Scope: nuke.Account,
23+
Resource: &S3AccessGrantsLocation{},
24+
Lister: &S3AccessGrantsLocationLister{},
25+
})
26+
}
27+
28+
type S3AccessGrantsLocationLister struct{}
29+
30+
func (l *S3AccessGrantsLocationLister) List(ctx context.Context, o interface{}) ([]resource.Resource, error) {
31+
opts := o.(*nuke.ListerOpts)
32+
svc := s3control.NewFromConfig(*opts.Config)
33+
var resources []resource.Resource
34+
35+
res, err := svc.ListAccessGrantsLocations(ctx, &s3control.ListAccessGrantsLocationsInput{
36+
AccountId: opts.AccountID,
37+
})
38+
if err != nil {
39+
if strings.Contains(err.Error(), "AccessGrantsInstanceNotExistsError") {
40+
return resources, nil
41+
} else {
42+
return nil, err
43+
}
44+
}
45+
46+
for _, entity := range res.AccessGrantsLocationsList {
47+
resources = append(resources, &S3AccessGrantsLocation{
48+
svc: svc,
49+
accountID: opts.AccountID,
50+
ID: entity.AccessGrantsLocationId,
51+
LocationScope: entity.LocationScope,
52+
CreatedAt: entity.CreatedAt,
53+
})
54+
}
55+
56+
return resources, nil
57+
}
58+
59+
type S3AccessGrantsLocation struct {
60+
svc *s3control.Client
61+
accountID *string
62+
ID *string `description:"The ID of the access grants location."`
63+
LocationScope *string `description:"The scope of the access grants location."`
64+
CreatedAt *time.Time `description:"The time the access grants location was created."`
65+
}
66+
67+
func (r *S3AccessGrantsLocation) Remove(ctx context.Context) error {
68+
_, err := r.svc.DeleteAccessGrantsLocation(ctx, &s3control.DeleteAccessGrantsLocationInput{
69+
AccessGrantsLocationId: r.ID,
70+
AccountId: r.accountID,
71+
})
72+
return err
73+
}
74+
75+
func (r *S3AccessGrantsLocation) Properties() types.Properties {
76+
return types.NewPropertiesFromStruct(r)
77+
}
78+
79+
func (r *S3AccessGrantsLocation) String() string {
80+
return *r.ID
81+
}

0 commit comments

Comments
 (0)