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

Add opensearch packages vpc endpoint support #1078

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
}
Loading