-
-
Notifications
You must be signed in to change notification settings - Fork 102
feat: add support for s3vectors resources #775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
miguelslemos
wants to merge
2
commits into
ekristen:main
Choose a base branch
from
miguelslemos:add-resource-s3-vectors
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| --- | ||
| generated: true | ||
| --- | ||
|
|
||
| # S3VectorsBucket | ||
|
|
||
|
|
||
| ## Resource | ||
|
|
||
| ```text | ||
| S3VectorsBucket | ||
| ``` | ||
|
|
||
| ## Properties | ||
|
|
||
|
|
||
| - `ARN`: No Description | ||
| - `Name`: No Description | ||
|
|
||
| !!! note - Using Properties | ||
| Properties are what [Filters](../config-filtering.md) are written against in your configuration. You use the property | ||
| names to write filters for what you want to **keep** and omit from the nuke process. | ||
|
|
||
| ### String Property | ||
|
|
||
| The string representation of a resource is generally the value of the Name, ID or ARN field of the resource. Not all | ||
| resources support properties. To write a filter against the string representation, simply omit the `property` field in | ||
| the filter. | ||
|
|
||
| The string value is always what is used in the output of the log format when a resource is identified. | ||
|
|
||
| ### DependsOn | ||
|
|
||
| !!! important - Experimental Feature | ||
| This resource depends on a resource using the experimental feature. This means that the resource will | ||
| only be deleted if all the resources of a particular type are deleted first or reach a terminal state. | ||
|
|
||
| - [S3VectorsIndex](./s3-vectors-index.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| --- | ||
| generated: true | ||
| --- | ||
|
|
||
| # S3VectorsIndex | ||
|
|
||
|
|
||
| ## Resource | ||
|
|
||
| ```text | ||
| S3VectorsIndex | ||
| ``` | ||
|
|
||
| ## Properties | ||
|
|
||
|
|
||
| - `BucketName`: No Description | ||
| - `IndexARN`: No Description | ||
| - `IndexName`: No Description | ||
|
|
||
| !!! note - Using Properties | ||
| Properties are what [Filters](../config-filtering.md) are written against in your configuration. You use the property | ||
| names to write filters for what you want to **keep** and omit from the nuke process. | ||
|
|
||
| ### String Property | ||
|
|
||
| The string representation of a resource is generally the value of the Name, ID or ARN field of the resource. Not all | ||
| resources support properties. To write a filter against the string representation, simply omit the `property` field in | ||
| the filter. | ||
|
|
||
| The string value is always what is used in the output of the log format when a resource is identified. | ||
|
|
||
| ### DependsOn | ||
|
|
||
| !!! important - Experimental Feature | ||
| This resource depends on a resource using the experimental feature. This means that the resource will | ||
| only be deleted if all the resources of a particular type are deleted first or reach a terminal state. | ||
|
|
||
| - [S3VectorsVector](./s3-vectors-vector.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| --- | ||
| generated: true | ||
| --- | ||
|
|
||
| # S3VectorsVector | ||
|
|
||
|
|
||
| ## Resource | ||
|
|
||
| ```text | ||
| S3VectorsVector | ||
| ``` | ||
|
|
||
| ## Properties | ||
|
|
||
|
|
||
| - `IndexName`: No Description | ||
| - `Key`: No Description | ||
| - `VectorBucketName`: No Description | ||
|
|
||
| !!! note - Using Properties | ||
| Properties are what [Filters](../config-filtering.md) are written against in your configuration. You use the property | ||
| names to write filters for what you want to **keep** and omit from the nuke process. | ||
|
|
||
| ### String Property | ||
|
|
||
| The string representation of a resource is generally the value of the Name, ID or ARN field of the resource. Not all | ||
| resources support properties. To write a filter against the string representation, simply omit the `property` field in | ||
| the filter. | ||
|
|
||
| The string value is always what is used in the output of the log format when a resource is identified. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package resources | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/aws/aws-sdk-go-v2/service/s3vectors" | ||
|
|
||
| "github.com/ekristen/libnuke/pkg/registry" | ||
| "github.com/ekristen/libnuke/pkg/resource" | ||
| "github.com/ekristen/libnuke/pkg/types" | ||
|
|
||
| "github.com/ekristen/aws-nuke/v3/pkg/nuke" | ||
| ) | ||
|
|
||
| const S3VectorsBucketResource = "S3VectorsBucket" | ||
|
|
||
| func init() { | ||
| registry.Register(®istry.Registration{ | ||
| Name: S3VectorsBucketResource, | ||
| Scope: nuke.Account, | ||
| Resource: &S3VectorsBucket{}, | ||
| Lister: &S3VectorsBucketLister{}, | ||
| DependsOn: []string{ | ||
| S3VectorsIndexResource, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| type S3VectorsBucketLister struct{} | ||
|
|
||
| func (l *S3VectorsBucketLister) List(ctx context.Context, o interface{}) ([]resource.Resource, error) { | ||
| opts := o.(*nuke.ListerOpts) | ||
| svc := s3vectors.NewFromConfig(*opts.Config) | ||
|
|
||
| var resources []resource.Resource | ||
| params := &s3vectors.ListVectorBucketsInput{} | ||
|
|
||
| paginator := s3vectors.NewListVectorBucketsPaginator(svc, params) | ||
| for paginator.HasMorePages() { | ||
| page, err := paginator.NextPage(ctx) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| for _, bucket := range page.VectorBuckets { | ||
| resources = append(resources, &S3VectorsBucket{ | ||
| svc: svc, | ||
| Name: bucket.VectorBucketName, | ||
| ARN: bucket.VectorBucketArn, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| return resources, nil | ||
| } | ||
|
|
||
| type S3VectorsBucket struct { | ||
| svc *s3vectors.Client | ||
| Name *string | ||
| ARN *string | ||
| } | ||
|
|
||
| func (r *S3VectorsBucket) Remove(ctx context.Context) error { | ||
| _, err := r.svc.DeleteVectorBucket(ctx, &s3vectors.DeleteVectorBucketInput{ | ||
| VectorBucketName: r.Name, | ||
| }) | ||
| return err | ||
| } | ||
|
|
||
| func (r *S3VectorsBucket) Properties() types.Properties { | ||
| return types.NewPropertiesFromStruct(r) | ||
| } | ||
|
|
||
| func (r *S3VectorsBucket) String() string { | ||
| return *r.Name | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package resources | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/gotidy/ptr" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func Test_S3VectorsBucket_Properties(t *testing.T) { | ||
| bucket := &S3VectorsBucket{ | ||
| Name: ptr.String("my-vector-bucket"), | ||
| ARN: ptr.String("arn:aws:s3vectors:us-east-1:123456789012:bucket/my-vector-bucket"), | ||
| } | ||
|
|
||
| properties := bucket.Properties() | ||
|
|
||
| assert.Equal(t, "my-vector-bucket", properties.Get("Name")) | ||
| assert.Equal(t, "arn:aws:s3vectors:us-east-1:123456789012:bucket/my-vector-bucket", properties.Get("ARN")) | ||
| } | ||
|
|
||
| func Test_S3VectorsBucket_String(t *testing.T) { | ||
| bucket := &S3VectorsBucket{ | ||
| Name: ptr.String("test-vector-bucket"), | ||
| } | ||
|
|
||
| assert.Equal(t, "test-vector-bucket", bucket.String()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| package resources | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/aws/aws-sdk-go-v2/service/s3vectors" | ||
|
|
||
| "github.com/ekristen/libnuke/pkg/registry" | ||
| "github.com/ekristen/libnuke/pkg/resource" | ||
| "github.com/ekristen/libnuke/pkg/types" | ||
|
|
||
| "github.com/ekristen/aws-nuke/v3/pkg/nuke" | ||
| ) | ||
|
|
||
| const S3VectorsIndexResource = "S3VectorsIndex" | ||
|
|
||
| func init() { | ||
| registry.Register(®istry.Registration{ | ||
| Name: S3VectorsIndexResource, | ||
| Scope: nuke.Account, | ||
| Resource: &S3VectorsIndex{}, | ||
| Lister: &S3VectorsIndexLister{}, | ||
| DependsOn: []string{ | ||
| S3VectorsVectorResource, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| type S3VectorsIndexLister struct{} | ||
|
|
||
| func (l *S3VectorsIndexLister) List(ctx context.Context, o interface{}) ([]resource.Resource, error) { | ||
| opts := o.(*nuke.ListerOpts) | ||
| svc := s3vectors.NewFromConfig(*opts.Config) | ||
|
|
||
| var resources []resource.Resource | ||
|
|
||
| // First, list all vector buckets | ||
| bucketsParams := &s3vectors.ListVectorBucketsInput{} | ||
| bucketsPaginator := s3vectors.NewListVectorBucketsPaginator(svc, bucketsParams) | ||
|
|
||
| for bucketsPaginator.HasMorePages() { | ||
| bucketsPage, err := bucketsPaginator.NextPage(ctx) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| // For each bucket, list all indexes | ||
| for _, bucket := range bucketsPage.VectorBuckets { | ||
| indexParams := &s3vectors.ListIndexesInput{ | ||
| VectorBucketName: bucket.VectorBucketName, | ||
| } | ||
|
|
||
| paginator := s3vectors.NewListIndexesPaginator(svc, indexParams) | ||
| for paginator.HasMorePages() { | ||
| page, err := paginator.NextPage(ctx) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| for _, index := range page.Indexes { | ||
| resources = append(resources, &S3VectorsIndex{ | ||
| svc: svc, | ||
| BucketName: bucket.VectorBucketName, | ||
| IndexName: index.IndexName, | ||
| IndexARN: index.IndexArn, | ||
| }) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return resources, nil | ||
| } | ||
|
|
||
| type S3VectorsIndex struct { | ||
| svc *s3vectors.Client | ||
| BucketName *string | ||
| IndexName *string | ||
| IndexARN *string | ||
| } | ||
|
|
||
| func (r *S3VectorsIndex) Remove(ctx context.Context) error { | ||
| _, err := r.svc.DeleteIndex(ctx, &s3vectors.DeleteIndexInput{ | ||
| VectorBucketName: r.BucketName, | ||
| IndexName: r.IndexName, | ||
| }) | ||
| return err | ||
| } | ||
|
|
||
| func (r *S3VectorsIndex) Properties() types.Properties { | ||
| return types.NewPropertiesFromStruct(r) | ||
| } | ||
|
|
||
| func (r *S3VectorsIndex) String() string { | ||
| return *r.IndexName | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the hierarchy implemented:
S3VectorsBucket depends on S3VectorsIndex, which depends on S3VectorsVector.
Is it possible for an S3VectorsVector to exist without an S3VectorsIndex?
If so, the Bucket should also depend on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will also say that the dependency hierarchy is definitely experimental and a bit buggy, it can cause some stalled removes. Love that you are using it, or might be, would appreciate any feedback to issues you encounter.