-
Notifications
You must be signed in to change notification settings - Fork 722
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
Add opensearch packages vpc endpoint support #1078
Changes from 6 commits
b5c792e
55571a7
84fbd14
378ccab
ade341a
41e22d2
083b3b9
7ddbe32
d6deab9
ea85816
94d09bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package resources | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/opensearchservice" | ||
"github.com/rebuy-de/aws-nuke/v2/pkg/types" | ||
) | ||
|
||
type OSPackage struct { | ||
svc *opensearchservice.OpenSearchService | ||
packageID *string | ||
packageName *string | ||
createdTime *time.Time | ||
} | ||
|
||
func init() { | ||
register("OSPackage", ListOSPackages) | ||
} | ||
|
||
func ListOSPackages(sess *session.Session) ([]Resource, error) { | ||
svc := opensearchservice.New(sess) | ||
|
||
listResp, err := svc.DescribePackages(&opensearchservice.DescribePackagesInput{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
resources := make([]Resource, 0) | ||
|
||
for _, pkg := range listResp.PackageDetailsList { | ||
resources = append(resources, &OSPackage{ | ||
svc: svc, | ||
packageID: pkg.PackageID, | ||
packageName: pkg.PackageName, | ||
createdTime: pkg.CreatedAt, | ||
}) | ||
} | ||
|
||
return resources, nil | ||
} | ||
|
||
func (o *OSPackage) Remove() error { | ||
_, err := o.svc.DeletePackage(&opensearchservice.DeletePackageInput{ | ||
PackageID: o.packageID, | ||
}) | ||
|
||
return err | ||
} | ||
|
||
func (o *OSPackage) Properties() types.Properties { | ||
properties := types.NewProperties() | ||
properties.Set("PackageID", o.packageID) | ||
properties.Set("PackageName", o.packageName) | ||
properties.Set("CreatedTime", o.createdTime.Format(time.RFC3339)) | ||
return properties | ||
} | ||
|
||
func (o *OSPackage) String() string { | ||
return *o.packageID | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package resources | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/opensearchservice" | ||
"github.com/rebuy-de/aws-nuke/v2/pkg/types" | ||
) | ||
|
||
type OSVPCEndpoint struct { | ||
svc *opensearchservice.OpenSearchService | ||
vpcEndpointId *string | ||
} | ||
|
||
func init() { | ||
register("OSVPCEndpoint", ListOSVPCEndpoints) | ||
} | ||
|
||
func ListOSVPCEndpoints(sess *session.Session) ([]Resource, error) { | ||
svc := opensearchservice.New(sess) | ||
|
||
vpcEndpointIds, err := getOpenSearchVpcEndpointIds(svc) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
listResp, err := svc.DescribeVpcEndpoints(&opensearchservice.DescribeVpcEndpointsInput{ | ||
VpcEndpointIds: vpcEndpointIds, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
resources := make([]Resource, 0) | ||
|
||
for _, vpcEndpoint := range listResp.VpcEndpoints { | ||
resources = append(resources, &OSVPCEndpoint{ | ||
svc: svc, | ||
vpcEndpointId: vpcEndpoint.VpcEndpointId, | ||
}) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for your contribution! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @der-eismann apologies. You are correct. That should have been removed and is now updated. |
||
|
||
return resources, nil | ||
} | ||
|
||
func getOpenSearchVpcEndpointIds(svc *opensearchservice.OpenSearchService) ([]*string, error) { | ||
vpcEndpointIds := make([]*string, 0) | ||
|
||
listResp, err := svc.ListVpcEndpoints(&opensearchservice.ListVpcEndpointsInput{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, vpcEndpoint := range listResp.VpcEndpointSummaryList { | ||
vpcEndpointIds = append(vpcEndpointIds, vpcEndpoint.VpcEndpointId) | ||
} | ||
|
||
return vpcEndpointIds, nil | ||
} | ||
|
||
func (o *OSVPCEndpoint) Remove() error { | ||
_, err := o.svc.DeleteVpcEndpoint(&opensearchservice.DeleteVpcEndpointInput{ | ||
VpcEndpointId: o.vpcEndpointId, | ||
}) | ||
|
||
return err | ||
} | ||
|
||
func (o *OSVPCEndpoint) Properties() types.Properties { | ||
properties := types.NewProperties() | ||
properties.Set("VpcEndpointId", o.vpcEndpointId) | ||
return properties | ||
} | ||
|
||
func (o *OSVPCEndpoint) String() string { | ||
return *o.vpcEndpointId | ||
} |
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.
Sorry, another thing I just noticed - both resources need paging as well, just like you did in #1044. Could you do that?
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.
@der-eismann No worries, updated with pagination and noted for my next PR's!