plancontext: use helpers to determine if CUE value is secret/fs/service
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
parent
201ac391b4
commit
c881bc2dba
@ -11,8 +11,8 @@ import (
|
||||
"github.com/spf13/viper"
|
||||
"go.dagger.io/dagger/client"
|
||||
"go.dagger.io/dagger/compiler"
|
||||
"go.dagger.io/dagger/plancontext"
|
||||
"go.dagger.io/dagger/state"
|
||||
"go.dagger.io/dagger/stdlib"
|
||||
)
|
||||
|
||||
func CurrentProject(ctx context.Context) *state.Project {
|
||||
@ -86,16 +86,17 @@ func CurrentEnvironmentState(ctx context.Context, project *state.Project) *state
|
||||
|
||||
// FormatValue returns the String representation of the cue value
|
||||
func FormatValue(val *compiler.Value) string {
|
||||
if val.HasAttr("artifact") {
|
||||
switch {
|
||||
case val.HasAttr("artifact"):
|
||||
return "dagger.#Artifact"
|
||||
case plancontext.IsSecretValue(val):
|
||||
return "dagger.#Secret"
|
||||
case plancontext.IsFSValue(val):
|
||||
return "dagger.#FS"
|
||||
case plancontext.IsServiceValue(val):
|
||||
return "dagger.#Service"
|
||||
}
|
||||
|
||||
if val.LookupPath(cue.MakePath(
|
||||
cue.Hid("_secret", stdlib.PackageName),
|
||||
cue.Str("id"),
|
||||
)).Exists() {
|
||||
return "dagger.#Secret"
|
||||
}
|
||||
if val.IsConcreteR() != nil {
|
||||
return val.IncompleteKind().String()
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"go.dagger.io/dagger/cmd/dagger/logger"
|
||||
"go.dagger.io/dagger/compiler"
|
||||
"go.dagger.io/dagger/environment"
|
||||
"go.dagger.io/dagger/plancontext"
|
||||
"go.dagger.io/dagger/solver"
|
||||
"go.dagger.io/dagger/state"
|
||||
|
||||
@ -61,15 +62,15 @@ var listCmd = &cobra.Command{
|
||||
_, hasDefault := inp.Default()
|
||||
|
||||
switch {
|
||||
case env.Context().Secrets.Contains(inp):
|
||||
case plancontext.IsSecretValue(inp):
|
||||
if _, err := env.Context().Secrets.FromValue(inp); err != nil {
|
||||
isConcrete = false
|
||||
}
|
||||
case env.Context().FS.Contains(inp):
|
||||
case plancontext.IsFSValue(inp):
|
||||
if _, err := env.Context().FS.FromValue(inp); err != nil {
|
||||
isConcrete = false
|
||||
}
|
||||
case env.Context().Services.Contains(inp):
|
||||
case plancontext.IsServiceValue(inp):
|
||||
if _, err := env.Context().Services.FromValue(inp); err != nil {
|
||||
isConcrete = false
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
"go.dagger.io/dagger/compiler"
|
||||
"go.dagger.io/dagger/environment"
|
||||
"go.dagger.io/dagger/plan"
|
||||
"go.dagger.io/dagger/plancontext"
|
||||
"go.dagger.io/dagger/solver"
|
||||
"golang.org/x/term"
|
||||
|
||||
@ -142,15 +143,15 @@ func checkInputs(ctx context.Context, env *environment.Environment) error {
|
||||
for _, i := range inputs {
|
||||
isConcrete := (i.IsConcreteR(cue.Optional(true)) == nil)
|
||||
switch {
|
||||
case env.Context().Secrets.Contains(i):
|
||||
case plancontext.IsSecretValue(i):
|
||||
if _, err := env.Context().Secrets.FromValue(i); err != nil {
|
||||
isConcrete = false
|
||||
}
|
||||
case env.Context().FS.Contains(i):
|
||||
case plancontext.IsFSValue(i):
|
||||
if _, err := env.Context().FS.FromValue(i); err != nil {
|
||||
isConcrete = false
|
||||
}
|
||||
case env.Context().Services.Contains(i):
|
||||
case plancontext.IsServiceValue(i):
|
||||
if _, err := env.Context().Services.FromValue(i); err != nil {
|
||||
isConcrete = false
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ func (p *Pipeline) ops() ([]*compiler.Value, error) {
|
||||
|
||||
// dagger.#FS forward compat
|
||||
// FIXME: remove this
|
||||
if p.pctx.FS.Contains(p.code) {
|
||||
if plancontext.IsFSValue(p.code) {
|
||||
ops = append(ops, p.code)
|
||||
}
|
||||
|
||||
@ -212,7 +212,7 @@ func (p *Pipeline) run(ctx context.Context) error {
|
||||
func (p *Pipeline) doOp(ctx context.Context, op *compiler.Value, st llb.State) (llb.State, error) {
|
||||
// dagger.#FS forward compat
|
||||
// FIXME: remove this
|
||||
if p.pctx.FS.Contains(op) {
|
||||
if plancontext.IsFSValue(op) {
|
||||
fs, err := p.pctx.FS.FromValue(op)
|
||||
if err != nil {
|
||||
return st, nil
|
||||
|
@ -18,6 +18,10 @@ var (
|
||||
)
|
||||
)
|
||||
|
||||
func IsFSValue(v *compiler.Value) bool {
|
||||
return v.LookupPath(fsIDPath).Exists()
|
||||
}
|
||||
|
||||
type FS struct {
|
||||
id string
|
||||
result bkgw.Reference
|
||||
@ -54,10 +58,6 @@ func (c *fsContext) New(result bkgw.Reference) *FS {
|
||||
return fs
|
||||
}
|
||||
|
||||
func (c *fsContext) Contains(v *compiler.Value) bool {
|
||||
return v.LookupPath(fsIDPath).Exists()
|
||||
}
|
||||
|
||||
func (c *fsContext) FromValue(v *compiler.Value) (*FS, error) {
|
||||
c.l.RLock()
|
||||
defer c.l.RUnlock()
|
||||
|
@ -16,6 +16,10 @@ var (
|
||||
)
|
||||
)
|
||||
|
||||
func IsSecretValue(v *compiler.Value) bool {
|
||||
return v.LookupPath(secretIDPath).Exists()
|
||||
}
|
||||
|
||||
type Secret struct {
|
||||
id string
|
||||
plainText string
|
||||
@ -55,10 +59,6 @@ func (c *secretContext) New(plaintext string) *Secret {
|
||||
return secret
|
||||
}
|
||||
|
||||
func (c *secretContext) Contains(v *compiler.Value) bool {
|
||||
return v.LookupPath(secretIDPath).Exists()
|
||||
}
|
||||
|
||||
func (c *secretContext) FromValue(v *compiler.Value) (*Secret, error) {
|
||||
c.l.RLock()
|
||||
defer c.l.RUnlock()
|
||||
|
@ -16,6 +16,10 @@ var (
|
||||
)
|
||||
)
|
||||
|
||||
func IsServiceValue(v *compiler.Value) bool {
|
||||
return v.LookupPath(serviceIDPath).Exists()
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
id string
|
||||
|
||||
@ -62,10 +66,6 @@ func (c *serviceContext) New(unix, npipe string) *Service {
|
||||
return s
|
||||
}
|
||||
|
||||
func (c *serviceContext) Contains(v *compiler.Value) bool {
|
||||
return v.LookupPath(serviceIDPath).Exists()
|
||||
}
|
||||
|
||||
func (c *serviceContext) FromValue(v *compiler.Value) (*Service, error) {
|
||||
c.l.RLock()
|
||||
defer c.l.RUnlock()
|
||||
|
Reference in New Issue
Block a user