This repository was archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 727
Add opensearch packages vpc endpoint support #1078
Merged
der-eismann
merged 11 commits into
rebuy-de:main
from
oreillymedia:Add-Opensearch-Packages-VPCEndpoint-Support
Aug 25, 2023
Merged
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b5c792e
Create opensearchservice-packages.go
swhite-oreilly 55571a7
Update opensearchservice-packages.go
swhite-oreilly 84fbd14
Adding opensearch vpcendpoints functionality.
swhite-oreilly 378ccab
Update opensearchservice-vpcendpoints.go
swhite-oreilly ade341a
Update opensearchservice-packages.go
swhite-oreilly 41e22d2
Update opensearchservice-vpcendpoints.go
swhite-oreilly 083b3b9
Merge branch 'main' into Add-Opensearch-Packages-VPCEndpoint-Support
swhite-oreilly 7ddbe32
Update opensearchservice-vpcendpoints.go
swhite-oreilly d6deab9
Update opensearchservice-vpcendpoints.go
swhite-oreilly ea85816
Adding pagination to list functions.
swhite-oreilly 94d09bb
Merge branch 'main' into Add-Opensearch-Packages-VPCEndpoint-Support
swhite-oreilly 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 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,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 | ||
} |
This file contains 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 ( | ||
"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 | ||
} |
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.
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!