This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 724
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add opensearch packages vpc endpoint support (#1078)
* Create opensearchservice-packages.go Adding support for opensearch packages. * Update opensearchservice-packages.go Confirmed working cleanup of os packages. * Adding opensearch vpcendpoints functionality. Removing unused var from packages. * Update opensearchservice-vpcendpoints.go Correctly retrieving VPC endpoint ids. * Update opensearchservice-packages.go Setting property values. * Update opensearchservice-vpcendpoints.go Adding id to properties. * Update opensearchservice-vpcendpoints.go Removing unneeded describe call. * Update opensearchservice-vpcendpoints.go Removed extra function for getting id's, incorporated into list function. * Adding pagination to list functions.
- Loading branch information
1 parent
150eb13
commit 5342982
Showing
2 changed files
with
142 additions
and
0 deletions.
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,75 @@ | ||
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) | ||
resources := []Resource{} | ||
var nextToken *string | ||
|
||
for { | ||
params := &opensearchservice.DescribePackagesInput{ | ||
NextToken: nextToken, | ||
} | ||
listResp, err := svc.DescribePackages(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, pkg := range listResp.PackageDetailsList { | ||
resources = append(resources, &OSPackage{ | ||
svc: svc, | ||
packageID: pkg.PackageID, | ||
packageName: pkg.PackageName, | ||
createdTime: pkg.CreatedAt, | ||
}) | ||
} | ||
|
||
// Check if there are more results | ||
if listResp.NextToken == nil { | ||
break // No more results, exit the loop | ||
} | ||
|
||
// Set the nextToken for the next iteration | ||
nextToken = listResp.NextToken | ||
} | ||
|
||
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,67 @@ | ||
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) | ||
resources := []Resource{} | ||
var nextToken *string | ||
|
||
for { | ||
params := &opensearchservice.ListVpcEndpointsInput{ | ||
NextToken: nextToken, | ||
} | ||
listResp, err := svc.ListVpcEndpoints(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, vpcEndpoint := range listResp.VpcEndpointSummaryList { | ||
resources = append(resources, &OSVPCEndpoint{ | ||
svc: svc, | ||
vpcEndpointId: vpcEndpoint.VpcEndpointId, | ||
}) | ||
} | ||
|
||
// Check if there are more results | ||
if listResp.NextToken == nil { | ||
break // No more results, exit the loop | ||
} | ||
|
||
// Set the nextToken for the next iteration | ||
nextToken = listResp.NextToken | ||
} | ||
|
||
return resources, 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 | ||
} |