This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
dagger/plan/task/auth.go
2021-12-17 10:07:33 -08:00

55 lines
1011 B
Go

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
}