From 80456d29528885eea004fa2bc765fc23361fc66c Mon Sep 17 00:00:00 2001 From: Erik Kristensen Date: Mon, 11 Nov 2024 09:48:26 -0700 Subject: [PATCH 1/2] fix(os-package): filter all package plugins --- resources/opensearchservice-packages.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/resources/opensearchservice-packages.go b/resources/opensearchservice-packages.go index f0bdb9cc..3dd0ece8 100644 --- a/resources/opensearchservice-packages.go +++ b/resources/opensearchservice-packages.go @@ -48,6 +48,7 @@ func (l *OSPackageLister) List(_ context.Context, o interface{}) ([]resource.Res svc: svc, packageID: pkg.PackageID, packageName: pkg.PackageName, + packageType: pkg.PackageType, createdTime: pkg.CreatedAt, }) } @@ -68,6 +69,7 @@ type OSPackage struct { svc *opensearchservice.OpenSearchService packageID *string packageName *string + packageType *string createdTime *time.Time } @@ -75,6 +77,10 @@ func (o *OSPackage) Filter() error { if strings.HasPrefix(*o.packageID, "G") { return fmt.Errorf("cannot delete default opensearch packages") } + + if *o.packageType == "ZIP-PLUGIN" { + return fmt.Errorf("cannot delete opensearch package plugin") + } return nil } @@ -90,6 +96,7 @@ func (o *OSPackage) Properties() types.Properties { properties := types.NewProperties() properties.Set("PackageID", o.packageID) properties.Set("PackageName", o.packageName) + properties.Set("PackageType", o.packageType) properties.Set("CreatedTime", o.createdTime.Format(time.RFC3339)) return properties } From 3fa592e96c3b11893731ee2de578a098d457d8d7 Mon Sep 17 00:00:00 2001 From: Erik Kristensen Date: Mon, 11 Nov 2024 09:49:58 -0700 Subject: [PATCH 2/2] refactor(os-package): convert to libnuke resource format --- ...ckages.go => opensearchservice-package.go} | 41 ++++++++----------- 1 file changed, 18 insertions(+), 23 deletions(-) rename resources/{opensearchservice-packages.go => opensearchservice-package.go} (64%) diff --git a/resources/opensearchservice-packages.go b/resources/opensearchservice-package.go similarity index 64% rename from resources/opensearchservice-packages.go rename to resources/opensearchservice-package.go index 3dd0ece8..61421dde 100644 --- a/resources/opensearchservice-packages.go +++ b/resources/opensearchservice-package.go @@ -46,10 +46,10 @@ func (l *OSPackageLister) List(_ context.Context, o interface{}) ([]resource.Res for _, pkg := range listResp.PackageDetailsList { resources = append(resources, &OSPackage{ svc: svc, - packageID: pkg.PackageID, - packageName: pkg.PackageName, - packageType: pkg.PackageType, - createdTime: pkg.CreatedAt, + PackageID: pkg.PackageID, + PackageName: pkg.PackageName, + PackageType: pkg.PackageType, + CreatedTime: pkg.CreatedAt, }) } @@ -67,40 +67,35 @@ func (l *OSPackageLister) List(_ context.Context, o interface{}) ([]resource.Res type OSPackage struct { svc *opensearchservice.OpenSearchService - packageID *string - packageName *string - packageType *string - createdTime *time.Time + PackageID *string + PackageName *string + PackageType *string + CreatedTime *time.Time } -func (o *OSPackage) Filter() error { - if strings.HasPrefix(*o.packageID, "G") { +func (r *OSPackage) Filter() error { + if strings.HasPrefix(*r.PackageID, "G") { return fmt.Errorf("cannot delete default opensearch packages") } - if *o.packageType == "ZIP-PLUGIN" { + if *r.PackageType == "ZIP-PLUGIN" { return fmt.Errorf("cannot delete opensearch package plugin") } return nil } -func (o *OSPackage) Remove(_ context.Context) error { - _, err := o.svc.DeletePackage(&opensearchservice.DeletePackageInput{ - PackageID: o.packageID, +func (r *OSPackage) Remove(_ context.Context) error { + _, err := r.svc.DeletePackage(&opensearchservice.DeletePackageInput{ + PackageID: r.PackageID, }) return err } -func (o *OSPackage) Properties() types.Properties { - properties := types.NewProperties() - properties.Set("PackageID", o.packageID) - properties.Set("PackageName", o.packageName) - properties.Set("PackageType", o.packageType) - properties.Set("CreatedTime", o.createdTime.Format(time.RFC3339)) - return properties +func (r *OSPackage) Properties() types.Properties { + return types.NewPropertiesFromStruct(r) } -func (o *OSPackage) String() string { - return *o.packageID +func (r *OSPackage) String() string { + return *r.PackageID }