Skip to content

Commit

Permalink
feat: DefaultScope
Browse files Browse the repository at this point in the history
  • Loading branch information
ekristen committed Jan 13, 2024
1 parent 4c4494b commit 82aa09f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/nuke/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (s *Scanner) list(owner, resourceType string, opts interface{}) {
}

dump := utils.Indent(fmt.Sprintf("%v", err), " ")
logrus.Errorf("Listing %s failed:\n%s", resourceType, dump)
logrus.WithError(err).Errorf("Listing %s failed:\n%s", resourceType, dump)
return
}

Expand Down
12 changes: 8 additions & 4 deletions pkg/resource/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ import (
"github.com/stevenle/topsort"
)

// Scope is a string in which resources are grouped against
// Scope is a string in which resources are grouped against, this is meant for upstream tools to define their
// own scopes if the DefaultScope is not sufficient. For example Azure has multiple levels of scoping for resources,
// whereas AWS does not.
type Scope string

// DefaultScope is the default scope which resources are registered against if no other scope is provided
const DefaultScope Scope = "default"

// Registrations is a map of resource type to registration
type Registrations map[string]Registration

Expand Down Expand Up @@ -45,11 +50,10 @@ type RegisterOption func(name string, lister Lister)
// Register registers a resource lister with the registry
func Register(r Registration, opts ...RegisterOption) {
if r.Scope == "" {
panic(fmt.Errorf("scope must be set"))
r.Scope = DefaultScope
}

_, exists := registrations[r.Name]
if exists {
if _, exists := registrations[r.Name]; exists {
panic(fmt.Sprintf("a resource with the name %s already exists", r.Name))
}

Expand Down

0 comments on commit 82aa09f

Please sign in to comment.