Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Ortel <jortel@redhat.com>
  • Loading branch information
jortel committed Feb 2, 2025
1 parent 0c7ec80 commit e56859a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
5 changes: 1 addition & 4 deletions cmd/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,8 @@ func (r *Analyzer) Run() (issueBuilder *builder.Issues, depBuilder *builder.Deps

// options builds Analyzer options.
func (r *Analyzer) options(output, depOutput string) (options command.Options, err error) {
variables := map[string]any{
"location": r.Mode.Location(),
}
settings := &Settings{}
err = settings.AppendExtensions(variables)
err = settings.AppendExtensions(&r.Mode)
if err != nil {
return
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/injector.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,21 @@ func (e *TypeError) Is(err error) (matched bool) {
return
}

// KeyRedefinedError reports key redefined errors.
type KeyRedefinedError struct {
// KeyConflictError reports key redefined errors.
type KeyConflictError struct {
Key string
Value any
}

func (e *KeyRedefinedError) Error() (s string) {
func (e *KeyConflictError) Error() (s string) {
return fmt.Sprintf(
"Key: '%s' = '%v' cannot be redefined.",
e.Key,
e.Value)
}

func (e *KeyRedefinedError) Is(err error) (matched bool) {
var inst *KeyRedefinedError
func (e *KeyConflictError) Is(err error) (matched bool) {
var inst *KeyConflictError
matched = errors.As(err, &inst)
return
}
Expand Down Expand Up @@ -425,7 +425,7 @@ func (r *ResourceInjector) addField(f *Field, v any) (err error) {
}
}
if _, found := r.dict[f.Key]; found {
err = &KeyRedefinedError{
err = &KeyConflictError{
Key: f.Key,
Value: v,
}
Expand Down
37 changes: 29 additions & 8 deletions cmd/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ import (
"gopkg.in/yaml.v2"
)

const (
// Builtin namespace.
Builtin = "builtin"
// BuiltinLocation The Location passed to the provider.
BuiltinLocation = Builtin + ".location"
)

// Settings - provider settings file.
type Settings struct {
index int
Expand All @@ -39,23 +46,25 @@ func (r *Settings) Read() (err error) {
}

// AppendExtensions adds extension fragments.
func (r *Settings) AppendExtensions(variables map[string]any) (err error) {
func (r *Settings) AppendExtensions(mode *Mode) (err error) {
addon, err := addon.Addon(true)
if err != nil {
return
}
for _, extension := range addon.Extensions {
var md *Metadata
md, err = r.metadata(&extension)
if r.hasProvider(&md.Provider) {
continue
}
builtin := r.injectBuiltins(md, mode)
injector := ResourceInjector{}
injector.Use(variables)
injector.Use(builtin)
err = injector.Inject(md)
if err != nil {
return
}
if !r.hasProvider(md.Provider.Name) {
r.content = append(r.content, md.Provider)
}
r.content = append(r.content, md.Provider)
}
return
}
Expand Down Expand Up @@ -128,6 +137,18 @@ func (r *Settings) ProxySettings() (err error) {
return
}

// injectBuiltins injects `builtin` field values.
func (r *Settings) injectBuiltins(md *Metadata, mode *Mode) (builtin map[string]any) {
builtin = make(map[string]any)
list := md.Provider.InitConfig
for i := range list {
in := &list[i]
in.Location = mode.Location()
builtin[BuiltinLocation] = in.Location
}
return
}

// getProxy set proxy settings.
func (r *Settings) getProxy(kind string) (url string, excluded []string, err error) {
var p *api.Proxy
Expand Down Expand Up @@ -170,9 +191,9 @@ func (r *Settings) path() (p string) {
}

// hasProvider returns true when the provider found.
func (r *Settings) hasProvider(name string) (found bool) {
for _, p := range r.content {
if p.Name == name {
func (r *Settings) hasProvider(p *provider.Config) (found bool) {
for i := range r.content {
if r.content[i].Name == p.Name {
found = true
break
}
Expand Down

0 comments on commit e56859a

Please sign in to comment.