Skip to content

Commit

Permalink
Add a flag to ignore API key management
Browse files Browse the repository at this point in the history
  • Loading branch information
Amulyam24 committed Oct 25, 2024
1 parent c51c4d9 commit 6cd287a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
6 changes: 4 additions & 2 deletions cmd/ibmcloud-janitor-boskos/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var (
passwordFile = flag.String("password-file", "", "The path to password file used to access the Boskos server")
logLevel = flag.String("log-level", "info", fmt.Sprintf("Log level is one of %v.", logrus.AllLevels))
debug = flag.Bool("debug", false, "Setting it to true allows logs for PowerVS client")
ignoreAPIKey = flag.Bool("ignore-api-key", false, "Setting it to true will skip clean up and rotation of API keys")
)

const (
Expand All @@ -60,8 +61,9 @@ func run(boskos *boskosClient.Client) error {
return errors.Wrap(err, "Couldn't retrieve resources from Boskos")
} else {
options := &resources.CleanupOptions{
Resource: res,
Debug: *debug,
Resource: res,
Debug: *debug,
IgnoreAPIKey: *ignoreAPIKey,
}
if err := resources.CleanAll(options); err != nil {
return errors.Wrapf(err, "Couldn't clean resource %q", res.Name)
Expand Down
9 changes: 7 additions & 2 deletions internal/ibmcloud-janitor/resources/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,24 @@ package resources

import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

func CleanAll(options *CleanupOptions) error {
list, err := listResources(options.Resource.Type)
if err != nil {
return errors.Wrapf(err, "Failed to fetch the list of resources of type %q", options.Resource.Name)
return errors.Wrapf(err, "Failed to fetch the list of resources of type %q", options.Resource.Type)
}
for _, resource := range list {
err = resource.cleanup(options)
if err != nil {
return errors.Wrapf(err, "Failed to clean the resources of type %q", options.Resource.Type)
return errors.Wrapf(err, "Failed to clean the resource %q of type %q", options.Resource.Name, options.Resource.Type)
}
}
if options.IgnoreAPIKey {
logrus.Infof("Skipping cleanup and rotation of API keys for resource %s of type %s", options.Resource.Name, options.Resource.Type)
return nil
}

for _, resource := range CommonResources {
err = resource.cleanup(options)
Expand Down
5 changes: 3 additions & 2 deletions internal/ibmcloud-janitor/resources/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ type Resource interface {
}

type CleanupOptions struct {
Resource *common.Resource
Debug bool
Resource *common.Resource
Debug bool
IgnoreAPIKey bool
}

var PowervsResources = []Resource{
Expand Down

0 comments on commit 6cd287a

Please sign in to comment.