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 Jan 9, 2025
1 parent 7801fb0 commit 05a7e54
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions cmd/injector.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (p *ParsedSelector) With(s string) {

// ResourceInjector inject resources into extension metadata.
type ResourceInjector struct {
dict map[string]string
dict map[string]any
}

// Inject resources into extension metadata.
Expand Down Expand Up @@ -126,7 +126,7 @@ func (r *ResourceInjector) Inject(extension *api.Extension) (p *provider.Config,

// build builds resource dictionary.
func (r *ResourceInjector) build(md *Metadata) (err error) {
r.dict = make(map[string]string)
r.dict = make(map[string]any)
application, err := addon.Task.Application()
if err != nil {
return
Expand Down Expand Up @@ -177,30 +177,33 @@ func (r *ResourceInjector) add(resource *Resource, object any) (err error) {
}
return
}
fv := r.string(v)
if f.Path != "" {
err = r.write(f.Path, fv)
err = r.write(f.Path, v)
if err != nil {
return
}
fv = f.Path
v = f.Path
}
r.dict[f.Key] = fv
r.dict[f.Key] = v
}
return
}

// write a resource field value to a file.
func (r *ResourceInjector) write(path string, s string) (err error) {
func (r *ResourceInjector) write(path string, v any) (err error) {
err = nas.MkDir(pathlib.Dir(path), 0755)
if err != nil {
return
}
f, err := os.Create(path)
if err == nil {
_, err = f.Write([]byte(s))
_ = f.Close()
if err != nil {
return
}
defer func() {
_ = f.Close()
}()
s := r.string(v)
_, err = f.Write([]byte(s))
return
}

Expand Down Expand Up @@ -249,10 +252,15 @@ func (r *ResourceInjector) inject(in any) (out any) {
if len(match) < 3 {
break
}
v := r.dict[match[2]]
if len(node) == len(match[0]) {
out = v
return
}
node = strings.Replace(
node,
match[0],
r.dict[match[2]],
r.string(v),
-1)
}
out = node
Expand Down

0 comments on commit 05a7e54

Please sign in to comment.