Skip to content

Commit

Permalink
Merge pull request #413 from ekristen/fix-os-package
Browse files Browse the repository at this point in the history
fix(os-package): filter plugins
  • Loading branch information
ekristen authored Nov 11, 2024
2 parents 17d5f8e + 3fa592e commit a17f53d
Showing 1 changed file with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +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,
createdTime: pkg.CreatedAt,
PackageID: pkg.PackageID,
PackageName: pkg.PackageName,
PackageType: pkg.PackageType,
CreatedTime: pkg.CreatedAt,
})
}

Expand All @@ -66,34 +67,35 @@ func (l *OSPackageLister) List(_ context.Context, o interface{}) ([]resource.Res

type OSPackage struct {
svc *opensearchservice.OpenSearchService
packageID *string
packageName *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 *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("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
}

0 comments on commit a17f53d

Please sign in to comment.