From b37db8eedb6961ebb9ba64143865f22c4bd5b53a Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Mon, 12 Jul 2021 10:46:48 +0200 Subject: [PATCH] cmd: implemented input validation when updating environment Signed-off-by: Sam Alba --- cmd/dagger/cmd/input/root.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/cmd/dagger/cmd/input/root.go b/cmd/dagger/cmd/input/root.go index ef1ae3cf..c681db4e 100644 --- a/cmd/dagger/cmd/input/root.go +++ b/cmd/dagger/cmd/input/root.go @@ -8,7 +8,10 @@ import ( "github.com/rs/zerolog/log" "github.com/spf13/cobra" "github.com/spf13/viper" + "go.dagger.io/dagger/client" "go.dagger.io/dagger/cmd/dagger/cmd/common" + "go.dagger.io/dagger/environment" + "go.dagger.io/dagger/solver" "go.dagger.io/dagger/state" ) @@ -32,13 +35,26 @@ func init() { ) } -func updateEnvironmentInput(ctx context.Context, target string, input state.Input) { +func updateEnvironmentInput(ctx context.Context, cl *client.Client, target string, input state.Input) { lg := log.Ctx(ctx) workspace := common.CurrentWorkspace(ctx) st := common.CurrentEnvironmentState(ctx, workspace) + st.SetInput(target, input) + _, err := cl.Do(ctx, st, func(ctx context.Context, env *environment.Environment, s solver.Solver) error { + _, err := env.ScanInputs(ctx, true) + if err != nil { + return err + } + return nil + }) + + if err != nil { + lg.Fatal().Err(err).Str("environment", st.Name).Msg("invalid input") + } + if err := workspace.Save(ctx, st); err != nil { lg.Fatal().Err(err).Str("environment", st.Name).Msg("cannot update environment") }