Skip to content

Commit 718f9b4

Browse files
authored
feat(amp): add support for AMP scraper (#736)
* feat(amp): add support for AMP scraper * chore(amp): migrate AMP workspace to AWS SDK V2 * chore(amp): rename AMP workspace to reflect v2 service name * fix(amp): props of AMP workspace should not change * chore(amp): workspace and scraper support tags * fix(amp): keep property names consistent * docs(amp): generate docs and add descriptions where missing
1 parent 3482db2 commit 718f9b4

File tree

8 files changed

+200
-81
lines changed

8 files changed

+200
-81
lines changed

docs/resources/amp-scraper.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
generated: true
3+
---
4+
5+
# AMPScraper
6+
7+
8+
## Resource
9+
10+
```text
11+
AMPScraper
12+
```
13+
14+
## Properties
15+
16+
17+
- `Alias`: The alias of the AMP Scraper
18+
- `ScraperID`: The ID of the AMP Scraper
19+
- `tag:<key>:`: This resource has tags with property `Tags`. These are key/value pairs that are
20+
added as their own property with the prefix of `tag:` (e.g. [tag:example: "value"])
21+
22+
!!! note - Using Properties
23+
Properties are what [Filters](../config-filtering.md) are written against in your configuration. You use the property
24+
names to write filters for what you want to **keep** and omit from the nuke process.
25+
26+
### String Property
27+
28+
The string representation of a resource is generally the value of the Name, ID or ARN field of the resource. Not all
29+
resources support properties. To write a filter against the string representation, simply omit the `property` field in
30+
the filter.
31+
32+
The string value is always what is used in the output of the log format when a resource is identified.
33+

docs/resources/amp-workspace.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,24 @@ generated: true
1111
AMPWorkspace
1212
```
1313

14+
## Properties
1415

1516

17+
- `WorkspaceARN`: The ARN of the AMP Workspace
18+
- `WorkspaceAlias`: The alias of the AMP Workspace
19+
- `WorkspaceId`: The ID of the AMP Workspace
20+
- `tag:<key>:`: This resource has tags with property `Tags`. These are key/value pairs that are
21+
added as their own property with the prefix of `tag:` (e.g. [tag:example: "value"])
22+
23+
!!! note - Using Properties
24+
Properties are what [Filters](../config-filtering.md) are written against in your configuration. You use the property
25+
names to write filters for what you want to **keep** and omit from the nuke process.
26+
27+
### String Property
28+
29+
The string representation of a resource is generally the value of the Name, ID or ARN field of the resource. Not all
30+
resources support properties. To write a filter against the string representation, simply omit the `property` field in
31+
the filter.
32+
33+
The string value is always what is used in the output of the log format when a resource is identified.
34+

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/aws/aws-sdk-go-v2 v1.38.3
1010
github.com/aws/aws-sdk-go-v2/config v1.28.11
1111
github.com/aws/aws-sdk-go-v2/credentials v1.17.68
12+
github.com/aws/aws-sdk-go-v2/service/amp v1.36.0
1213
github.com/aws/aws-sdk-go-v2/service/apigateway v1.28.12
1314
github.com/aws/aws-sdk-go-v2/service/appsync v1.42.3
1415
github.com/aws/aws-sdk-go-v2/service/cloudfront v1.44.12

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 h1:VaRN3TlFdd6KxX1x3ILT5ynH6HvK
2424
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1/go.mod h1:FbtygfRFze9usAadmnGJNc8KsP346kEe+y2/oyhGAGc=
2525
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.27 h1:AmB5QxnD+fBFrg9LcqzkgF/CaYvMyU/BTlejG4t1S7Q=
2626
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.27/go.mod h1:Sai7P3xTiyv9ZUYO3IFxMnmiIP759/67iQbU4kdmkyU=
27+
github.com/aws/aws-sdk-go-v2/service/amp v1.36.0 h1:bkMWckc+0CtmzdUls0WxNMgJW+FfVFBWXbI8gaD8xts=
28+
github.com/aws/aws-sdk-go-v2/service/amp v1.36.0/go.mod h1:LJjtJRt+mqjs4D8JRKGEYjW4w4XNd7s5oXjivdbPXfc=
2729
github.com/aws/aws-sdk-go-v2/service/apigateway v1.28.12 h1:m7O0X55xKIbwUnGcHOs3AMdPN7ZN6wFA8fyL0wIH1vM=
2830
github.com/aws/aws-sdk-go-v2/service/apigateway v1.28.12/go.mod h1:n1JY79L1AAtLhKJXIRv9pACaj9IAuoOOAz6cekbTEkk=
2931
github.com/aws/aws-sdk-go-v2/service/appsync v1.42.3 h1:Q903rtU9x/OmFMqXGm3033459yx/M1F9UcOWwoowH+s=

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ nav:
132132
- Access Analyzer Archive Rule: resources/access-analyzer-archive-rule.md
133133
- Access Analyzer: resources/access-analyzer.md
134134
- Amg Workspace: resources/amg-workspace.md
135+
- Amp Scraper: resources/amp-scraper.md
135136
- Amp Workspace: resources/amp-workspace.md
136137
- Amplify App: resources/amplify-app.md
137138
- Api Gateway Api Key: resources/api-gateway-api-key.md

resources/amp-scraper.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package resources
2+
3+
import (
4+
"context"
5+
6+
"github.com/aws/aws-sdk-go-v2/service/amp"
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 AMPScraperResource = "AMPScraper"
16+
17+
func init() {
18+
registry.Register(&registry.Registration{
19+
Name: AMPScraperResource,
20+
Scope: nuke.Account,
21+
Resource: &AMPScraper{},
22+
Lister: &AMPScraperLister{},
23+
})
24+
}
25+
26+
type AMPScraperLister struct{}
27+
28+
func (l *AMPScraperLister) List(ctx context.Context, o interface{}) ([]resource.Resource, error) {
29+
opts := o.(*nuke.ListerOpts)
30+
31+
svc := amp.NewFromConfig(*opts.Config)
32+
resources := make([]resource.Resource, 0)
33+
34+
paginator := amp.NewListScrapersPaginator(svc, &amp.ListScrapersInput{})
35+
for paginator.HasMorePages() {
36+
page, err := paginator.NextPage(ctx)
37+
if err != nil {
38+
return nil, err
39+
}
40+
41+
for _, ws := range page.Scrapers {
42+
resources = append(resources, &AMPScraper{
43+
svc: svc,
44+
ScraperID: ws.ScraperId,
45+
Alias: ws.Alias,
46+
Tags: ws.Tags,
47+
})
48+
}
49+
}
50+
51+
return resources, nil
52+
}
53+
54+
type AMPScraper struct {
55+
svc *amp.Client
56+
ScraperID *string `description:"The ID of the AMP Scraper"`
57+
Alias *string `description:"The alias of the AMP Scraper"`
58+
Tags map[string]string `description:"The tags of the AMP Scraper"`
59+
}
60+
61+
func (f *AMPScraper) Remove(ctx context.Context) error {
62+
_, err := f.svc.DeleteScraper(ctx, &amp.DeleteScraperInput{
63+
ScraperId: f.ScraperID,
64+
})
65+
66+
return err
67+
}
68+
69+
func (f *AMPScraper) Properties() types.Properties {
70+
return types.NewPropertiesFromStruct(f)
71+
}

resources/amp-workspace.go

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+
6+
"github.com/aws/aws-sdk-go-v2/service/amp"
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 AMPWorkspaceResource = "AMPWorkspace"
16+
17+
func init() {
18+
registry.Register(&registry.Registration{
19+
Name: AMPWorkspaceResource,
20+
Scope: nuke.Account,
21+
Resource: &AMPWorkspace{},
22+
Lister: &AMPWorkspaceLister{},
23+
})
24+
}
25+
26+
type AMPWorkspaceLister struct{}
27+
28+
func (l *AMPWorkspaceLister) List(ctx context.Context, o interface{}) ([]resource.Resource, error) {
29+
opts := o.(*nuke.ListerOpts)
30+
31+
svc := amp.NewFromConfig(*opts.Config)
32+
resources := make([]resource.Resource, 0)
33+
34+
paginator := amp.NewListWorkspacesPaginator(svc, &amp.ListWorkspacesInput{})
35+
for paginator.HasMorePages() {
36+
page, err := paginator.NextPage(ctx)
37+
if err != nil {
38+
return nil, err
39+
}
40+
41+
for _, ws := range page.Workspaces {
42+
resources = append(resources, &AMPWorkspace{
43+
svc: svc,
44+
WorkspaceAlias: ws.Alias,
45+
WorkspaceARN: ws.Arn,
46+
WorkspaceId: ws.WorkspaceId,
47+
Tags: ws.Tags,
48+
})
49+
}
50+
}
51+
52+
return resources, nil
53+
}
54+
55+
type AMPWorkspace struct {
56+
svc *amp.Client
57+
WorkspaceAlias *string `description:"The alias of the AMP Workspace"`
58+
WorkspaceARN *string `description:"The ARN of the AMP Workspace"`
59+
WorkspaceId *string `description:"The ID of the AMP Workspace"`
60+
Tags map[string]string `description:"The tags of the AMP Workspace"`
61+
}
62+
63+
func (f *AMPWorkspace) Remove(ctx context.Context) error {
64+
_, err := f.svc.DeleteWorkspace(ctx, &amp.DeleteWorkspaceInput{
65+
WorkspaceId: f.WorkspaceId,
66+
})
67+
68+
return err
69+
}
70+
71+
func (f *AMPWorkspace) Properties() types.Properties {
72+
return types.NewPropertiesFromStruct(f)
73+
}

resources/prometheusservice-workspace.go

Lines changed: 0 additions & 81 deletions
This file was deleted.

0 commit comments

Comments
 (0)