Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
Add opensearch packages vpc endpoint support (#1078)
Browse files Browse the repository at this point in the history
* 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
swhite-oreilly authored Aug 25, 2023
1 parent 150eb13 commit 5342982
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 0 deletions.
75 changes: 75 additions & 0 deletions resources/opensearchservice-packages.go
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
}
67 changes: 67 additions & 0 deletions resources/opensearchservice-vpcendpoints.go
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
}

0 comments on commit 5342982

Please sign in to comment.