Skip to content

Commit 35f9c11

Browse files
authored
Merge pull request #834 from roseo1/lakeformation
feat(lakeformation): add initial lakeformation resources
2 parents 0eca56c + f76a079 commit 35f9c11

File tree

10 files changed

+322
-2
lines changed

10 files changed

+322
-2
lines changed

docs/documentation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ first letter of the field name. The field name should match what the existing pr
4141
#### Generating Documentation for All Resources
4242

4343
```console
44-
go run tools/generate-docs/main.go --write
44+
go run tools/generate-docs/docs.go --write
4545
```
4646

4747
#### Generating Documentation for a Single Resource
4848

4949
```console
50-
go run tools/generate-docs/main.go --resource EC2Instance --write
50+
go run tools/generate-docs/docs.go --resource EC2Instance --write
5151
```
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
generated: true
3+
---
4+
5+
# LakeFormationLocation
6+
7+
8+
## Resource
9+
10+
```text
11+
LakeFormationLocation
12+
```
13+
14+
## Properties
15+
16+
17+
- `ResourceARN`: The ARN of the resource registered with Lake Formation
18+
19+
!!! note - Using Properties
20+
Properties are what [Filters](../config-filtering.md) are written against in your configuration. You use the property
21+
names to write filters for what you want to **keep** and omit from the nuke process.
22+
23+
### String Property
24+
25+
The string representation of a resource is generally the value of the Name, ID or ARN field of the resource. Not all
26+
resources support properties. To write a filter against the string representation, simply omit the `property` field in
27+
the filter.
28+
29+
The string value is always what is used in the output of the log format when a resource is identified.
30+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
generated: true
3+
---
4+
5+
# LakeFormationPermission
6+
7+
8+
## Resource
9+
10+
```text
11+
LakeFormationPermission
12+
```
13+
14+
## Properties
15+
16+
17+
- `Permissions`: The permissions to remove from the principal
18+
- `PrincipalARN`: The ARN of the principal to remove permissions from
19+
- `Resource`: -
20+
21+
!!! note - Using Properties
22+
Properties are what [Filters](../config-filtering.md) are written against in your configuration. You use the property
23+
names to write filters for what you want to **keep** and omit from the nuke process.
24+
25+
### String Property
26+
27+
The string representation of a resource is generally the value of the Name, ID or ARN field of the resource. Not all
28+
resources support properties. To write a filter against the string representation, simply omit the `property` field in
29+
the filter.
30+
31+
The string value is always what is used in the output of the log format when a resource is identified.
32+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
generated: true
3+
---
4+
5+
# LakeFormationTag
6+
7+
8+
## Resource
9+
10+
```text
11+
LakeFormationTag
12+
```
13+
14+
## Properties
15+
16+
17+
- `CatalogID`: The identifier for the Data Catalog. By default, the account ID.
18+
- `TagKey`: The key-name for the LF-tag
19+
20+
!!! note - Using Properties
21+
Properties are what [Filters](../config-filtering.md) are written against in your configuration. You use the property
22+
names to write filters for what you want to **keep** and omit from the nuke process.
23+
24+
### String Property
25+
26+
The string representation of a resource is generally the value of the Name, ID or ARN field of the resource. Not all
27+
resources support properties. To write a filter against the string representation, simply omit the `property` field in
28+
the filter.
29+
30+
The string value is always what is used in the output of the log format when a resource is identified.
31+

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ require (
6161
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.4.8 // indirect
6262
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.1 // indirect
6363
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.10 // indirect
64+
github.com/aws/aws-sdk-go-v2/service/lakeformation v1.46.4 // indirect
6465
github.com/aws/aws-sdk-go-v2/service/sso v1.25.6 // indirect
6566
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.30.4 // indirect
6667
github.com/benbjohnson/clock v1.3.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.1 h1:ky79ysLMx
7676
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.1/go.mod h1:+2MmkvFvPYM1vsozBWduoLJUi5maxFk5B7KJFECujhY=
7777
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.10 h1:fXoWC2gi7tdJYNTPnnlSGzEVwewUchOi8xVq/dkg8Qs=
7878
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.10/go.mod h1:cvzBApD5dVazHU8C2rbBQzzzsKc8m5+wNJ9mCRZLKPc=
79+
github.com/aws/aws-sdk-go-v2/service/lakeformation v1.46.4 h1:/FGGegoEL5Kt7GmRG6fezeyTKDKF5SkIfAZplTmEd7c=
80+
github.com/aws/aws-sdk-go-v2/service/lakeformation v1.46.4/go.mod h1:UItZ8YQ8PcPAEVdk1/1tZwAsLmOZS4SiYLdvM4jde2g=
7981
github.com/aws/aws-sdk-go-v2/service/mgn v1.37.5 h1:BMu425Ntx40waGQ0/g6BeX1F/sYvKdIcO+ABys5Jv9s=
8082
github.com/aws/aws-sdk-go-v2/service/mgn v1.37.5/go.mod h1:F3YMviBP/8gRnYBh8j+6MUw/c3ID0l3IMS37kHAo22Y=
8183
github.com/aws/aws-sdk-go-v2/service/mgn v1.37.6 h1:ITYqWof2FxKHKTmxsjkwvgTjD14gajRXJYenLIeg1qA=

mkdocs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,9 @@ nav:
473473
- Kinesis Analytics Application: resources/kinesis-analytics-application.md
474474
- Kinesis Stream: resources/kinesis-stream.md
475475
- Kinesis Video Project: resources/kinesis-video-project.md
476+
- Lake Formation Location: resources/lake-formation-location.md
477+
- Lake Formation Permission: resources/lake-formation-permission.md
478+
- Lake Formation Tag: resources/lake-formation-tag.md
476479
- Lambda Event Source Mapping: resources/lambda-event-source-mapping.md
477480
- Lambda Function: resources/lambda-function.md
478481
- Lambda Layer: resources/lambda-layer.md
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package resources
2+
3+
import (
4+
"context"
5+
6+
"github.com/aws/aws-sdk-go-v2/service/lakeformation"
7+
8+
"github.com/ekristen/libnuke/pkg/registry"
9+
"github.com/ekristen/libnuke/pkg/resource"
10+
"github.com/ekristen/libnuke/pkg/types"
11+
12+
"github.com/ekristen/aws-nuke/v3/pkg/nuke"
13+
)
14+
15+
const LakeFormationLocationResource = "LakeFormationLocation"
16+
17+
func init() {
18+
registry.Register(&registry.Registration{
19+
Name: LakeFormationLocationResource,
20+
Scope: nuke.Account,
21+
Resource: &LakeFormationLocation{},
22+
Lister: &LakeFormationLocationLister{},
23+
})
24+
}
25+
26+
type LakeFormationLocationLister struct{}
27+
28+
func (l *LakeFormationLocationLister) List(ctx context.Context, o interface{}) ([]resource.Resource, error) {
29+
opts := o.(*nuke.ListerOpts)
30+
31+
svc := lakeformation.NewFromConfig(*opts.Config)
32+
resources := make([]resource.Resource, 0)
33+
34+
paginator := lakeformation.NewListResourcesPaginator(svc, &lakeformation.ListResourcesInput{})
35+
for paginator.HasMorePages() {
36+
page, err := paginator.NextPage(ctx)
37+
if err != nil {
38+
return nil, err
39+
}
40+
41+
for _, ri := range page.ResourceInfoList {
42+
resources = append(resources, &LakeFormationLocation{
43+
svc: svc,
44+
ResourceARN: ri.ResourceArn,
45+
})
46+
}
47+
}
48+
49+
return resources, nil
50+
}
51+
52+
type LakeFormationLocation struct {
53+
svc *lakeformation.Client
54+
ResourceARN *string `description:"The ARN of the resource registered with Lake Formation"`
55+
}
56+
57+
func (f *LakeFormationLocation) Remove(ctx context.Context) error {
58+
_, err := f.svc.DeregisterResource(ctx, &lakeformation.DeregisterResourceInput{
59+
ResourceArn: f.ResourceARN,
60+
})
61+
62+
return err
63+
}
64+
65+
func (f *LakeFormationLocation) Properties() types.Properties {
66+
return types.NewPropertiesFromStruct(f)
67+
}
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+
"fmt"
6+
7+
"github.com/aws/aws-sdk-go-v2/service/lakeformation"
8+
lakeformationtypes "github.com/aws/aws-sdk-go-v2/service/lakeformation/types"
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 LakeFormationPermissionResource = "LakeFormationPermission"
18+
19+
func init() {
20+
registry.Register(&registry.Registration{
21+
Name: LakeFormationPermissionResource,
22+
Scope: nuke.Account,
23+
Resource: &LakeFormationPermission{},
24+
Lister: &LakeFormationPermissionLister{},
25+
})
26+
}
27+
28+
type LakeFormationPermissionLister struct{}
29+
30+
func (l *LakeFormationPermissionLister) List(ctx context.Context, o interface{}) ([]resource.Resource, error) {
31+
opts := o.(*nuke.ListerOpts)
32+
33+
svc := lakeformation.NewFromConfig(*opts.Config)
34+
resources := make([]resource.Resource, 0)
35+
36+
paginator := lakeformation.NewListPermissionsPaginator(svc, &lakeformation.ListPermissionsInput{})
37+
for paginator.HasMorePages() {
38+
page, err := paginator.NextPage(ctx)
39+
if err != nil {
40+
return nil, err
41+
}
42+
43+
for _, prp := range page.PrincipalResourcePermissions {
44+
resources = append(resources, &LakeFormationPermission{
45+
svc: svc,
46+
PrincipalARN: prp.Principal.DataLakePrincipalIdentifier,
47+
Resource: prp.Resource,
48+
Permissions: prp.Permissions,
49+
})
50+
}
51+
}
52+
53+
return resources, nil
54+
}
55+
56+
type LakeFormationPermission struct {
57+
svc *lakeformation.Client
58+
PrincipalARN *string `description:"The ARN of the principal to remove permissions from"`
59+
Permissions []lakeformationtypes.Permission `description:"The permissions to remove from the principal"`
60+
Resource *lakeformationtypes.Resource `description:"-"`
61+
}
62+
63+
func (f *LakeFormationPermission) Remove(ctx context.Context) error {
64+
_, err := f.svc.RevokePermissions(ctx, &lakeformation.RevokePermissionsInput{
65+
Principal: &lakeformationtypes.DataLakePrincipal{
66+
DataLakePrincipalIdentifier: f.PrincipalARN,
67+
},
68+
Resource: f.Resource,
69+
Permissions: f.Permissions,
70+
})
71+
72+
return err
73+
}
74+
75+
func (r *LakeFormationPermission) Filter() error {
76+
if *r.PrincipalARN == "IAM_ALLOWED_PRINCIPALS" {
77+
return fmt.Errorf("cannot delete default setting group permissions")
78+
}
79+
return nil
80+
}
81+
82+
func (f *LakeFormationPermission) Properties() types.Properties {
83+
return types.NewPropertiesFromStruct(f)
84+
}

resources/lakeformation-tag.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package resources
2+
3+
import (
4+
"context"
5+
6+
"github.com/aws/aws-sdk-go-v2/service/lakeformation"
7+
8+
"github.com/ekristen/libnuke/pkg/registry"
9+
"github.com/ekristen/libnuke/pkg/resource"
10+
"github.com/ekristen/libnuke/pkg/types"
11+
12+
"github.com/ekristen/aws-nuke/v3/pkg/nuke"
13+
)
14+
15+
const LakeFormationTagResource = "LakeFormationTag"
16+
17+
func init() {
18+
registry.Register(&registry.Registration{
19+
Name: LakeFormationTagResource,
20+
Scope: nuke.Account,
21+
Resource: &LakeFormationTag{},
22+
Lister: &LakeFormationTagLister{},
23+
})
24+
}
25+
26+
type LakeFormationTagLister struct{}
27+
28+
func (l *LakeFormationTagLister) List(ctx context.Context, o interface{}) ([]resource.Resource, error) {
29+
opts := o.(*nuke.ListerOpts)
30+
31+
svc := lakeformation.NewFromConfig(*opts.Config)
32+
resources := make([]resource.Resource, 0)
33+
34+
paginator := lakeformation.NewListLFTagsPaginator(svc, &lakeformation.ListLFTagsInput{})
35+
for paginator.HasMorePages() {
36+
page, err := paginator.NextPage(ctx)
37+
if err != nil {
38+
return nil, err
39+
}
40+
41+
for _, t := range page.LFTags {
42+
resources = append(resources, &LakeFormationTag{
43+
svc: svc,
44+
TagKey: t.TagKey,
45+
CatalogID: t.CatalogId,
46+
})
47+
}
48+
}
49+
50+
return resources, nil
51+
}
52+
53+
type LakeFormationTag struct {
54+
svc *lakeformation.Client
55+
TagKey *string `description:"The key-name for the LF-tag"`
56+
CatalogID *string `description:"The identifier for the Data Catalog. By default, the account ID."`
57+
}
58+
59+
func (f *LakeFormationTag) Remove(ctx context.Context) error {
60+
_, err := f.svc.DeleteLFTag(ctx, &lakeformation.DeleteLFTagInput{
61+
TagKey: f.TagKey,
62+
CatalogId: f.CatalogID,
63+
})
64+
65+
return err
66+
}
67+
68+
func (f *LakeFormationTag) Properties() types.Properties {
69+
return types.NewPropertiesFromStruct(f)
70+
}

0 commit comments

Comments
 (0)