Skip to content

Commit 5ef37da

Browse files
committed
fix(runner): handle multiple resps in GetLazyAuthFetchCallback
the callback logic does not properly accumulate results from multiple responses Signed-off-by: Dwi Siswanto <[email protected]>
1 parent ff5734b commit 5ef37da

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

internal/runner/lazy.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ func GetLazyAuthFetchCallback(opts *AuthLazyFetchOptions) authx.LazyFetchSecret
105105
var finalErr error
106106
ctx.OnResult = func(e *output.InternalWrappedEvent) {
107107
if e == nil {
108-
finalErr = fmt.Errorf("no result found for template: %s", d.TemplatePath)
109108
return
110109
}
110+
111111
if !e.HasOperatorResult() {
112-
finalErr = fmt.Errorf("no result found for template: %s", d.TemplatePath)
113112
return
114113
}
114+
115115
// dynamic values
116116
for k, v := range e.OperatorsResult.DynamicValues {
117117
// Iterate through all the values and choose the
@@ -123,31 +123,37 @@ func GetLazyAuthFetchCallback(opts *AuthLazyFetchOptions) authx.LazyFetchSecret
123123
}
124124
}
125125
}
126+
126127
// named extractors
127128
for k, v := range e.OperatorsResult.Extracts {
128129
if len(v) > 0 {
129-
data[k] = v[0]
130-
}
131-
}
132-
if len(data) == 0 {
133-
if e.OperatorsResult.Matched {
134-
finalErr = fmt.Errorf("match found but no (dynamic/extracted) values found for template: %s", d.TemplatePath)
135-
} else {
136-
finalErr = fmt.Errorf("no match or (dynamic/extracted) values found for template: %s", d.TemplatePath)
130+
// NOTE(dwisiswant0): Only set if we don't already have a
131+
// value -- or -- if the new value is non-empty.
132+
if _, exists := data[k]; !exists || data[k] == "" {
133+
data[k] = v[0]
134+
}
137135
}
138136
}
137+
139138
// log result of template in result file/screen
140139
_ = writer.WriteResult(e, opts.ExecOpts.Output, opts.ExecOpts.Progress, opts.ExecOpts.IssuesClient)
141140
}
141+
142142
_, err := tmpl.Executer.ExecuteWithResults(ctx)
143143
if err != nil {
144144
finalErr = err
145145
}
146+
147+
if len(data) == 0 && finalErr == nil {
148+
finalErr = fmt.Errorf("no extracted values found for template: %s", d.TemplatePath)
149+
}
150+
146151
// store extracted result in auth context
147152
d.Extracted = data
148153
if finalErr != nil && opts.OnError != nil {
149154
opts.OnError(finalErr)
150155
}
156+
151157
return finalErr
152158
}
153159
}

0 commit comments

Comments
 (0)