implemented integration tests for engine.#Pull + moved auth code separately for sharing code with other tasks later
Signed-off-by: Sam Alba <samalba@users.noreply.github.com>
This commit is contained in:
54
plan/task/auth.go
Normal file
54
plan/task/auth.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package task
|
||||
|
||||
import (
|
||||
"go.dagger.io/dagger/compiler"
|
||||
"go.dagger.io/dagger/plancontext"
|
||||
)
|
||||
|
||||
type authValue struct {
|
||||
Target string
|
||||
Username string
|
||||
Secret *plancontext.Secret
|
||||
}
|
||||
|
||||
// Decodes an auth field value
|
||||
//
|
||||
// Cue format:
|
||||
// auth: [...{
|
||||
// target: string
|
||||
// username: string
|
||||
// secret: string | #Secret
|
||||
// }]
|
||||
func decodeAuthValue(pctx *plancontext.Context, v *compiler.Value) ([]*authValue, error) {
|
||||
vals, err := v.List()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
authVals := []*authValue{}
|
||||
for _, val := range vals {
|
||||
authVal := authValue{}
|
||||
|
||||
target, err := val.Lookup("target").String()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
authVal.Target = target
|
||||
|
||||
username, err := val.Lookup("username").String()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
authVal.Username = username
|
||||
|
||||
secret, err := pctx.Secrets.FromValue(val.Lookup("secret"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
authVal.Secret = secret
|
||||
|
||||
authVals = append(authVals, &authVal)
|
||||
}
|
||||
|
||||
return authVals, nil
|
||||
}
|
Reference in New Issue
Block a user