From 02a0efd5bcd795d73412dea9c02d17a16405780e Mon Sep 17 00:00:00 2001 From: Guillaume Lours <705411+glours@users.noreply.github.com> Date: Wed, 18 Oct 2023 15:30:50 +0200 Subject: [PATCH] check that the pull policy provided is a valid one or is not missing when --pull is used Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com> --- cmd/compose/create.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmd/compose/create.go b/cmd/compose/create.go index 9379818dd4e..4c8d6862883 100644 --- a/cmd/compose/create.go +++ b/cmd/compose/create.go @@ -19,6 +19,7 @@ package compose import ( "context" "fmt" + "slices" "strconv" "strings" "time" @@ -138,6 +139,9 @@ func (opts createOptions) GetTimeout() *time.Duration { func (opts createOptions) Apply(project *types.Project) error { if opts.pullChanged { + if !opts.isPullPolicyValid() { + return fmt.Errorf("invalid --pull option %q", opts.Pull) + } for i, service := range project.Services { service.PullPolicy = opts.Pull project.Services[i] = service @@ -187,3 +191,9 @@ func (opts createOptions) Apply(project *types.Project) error { } return nil } + +func (opts createOptions) isPullPolicyValid() bool { + pullPolicies := []string{types.PullPolicyAlways, types.PullPolicyNever, types.PullPolicyBuild, + types.PullPolicyMissing, types.PullPolicyIfNotPresent} + return slices.Contains(pullPolicies, opts.Pull) +}