From 82aa09f5bcd1e41d153c12be35d69334acc482fc Mon Sep 17 00:00:00 2001 From: Erik Kristensen Date: Sat, 13 Jan 2024 15:07:49 -0700 Subject: [PATCH] feat: DefaultScope --- pkg/nuke/scan.go | 2 +- pkg/resource/registry.go | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/nuke/scan.go b/pkg/nuke/scan.go index 20133e6..01d6ba1 100644 --- a/pkg/nuke/scan.go +++ b/pkg/nuke/scan.go @@ -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 } diff --git a/pkg/resource/registry.go b/pkg/resource/registry.go index f3691d6..534523e 100644 --- a/pkg/resource/registry.go +++ b/pkg/resource/registry.go @@ -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 @@ -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)) }