From 873edfce42b79587cec1a969e761cdf5f1a3e91c Mon Sep 17 00:00:00 2001 From: Yves Brissaud Date: Tue, 15 Oct 2024 22:29:21 +0200 Subject: [PATCH] allow to set a accept-the-risk configuration In this case it will not prompt for user confirmation Signed-off-by: Yves Brissaud --- README.md | 4 ++++ docs/index.markdown | 4 ++++ docs/reference/docker_runx.yaml | 11 +++++++++++ docs/reference/runx.md | 1 + internal/commands/root/root.go | 8 ++++---- runkit/config.go | 1 + runkit/types.go | 5 +++-- 7 files changed, 28 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1fc5588..6e69b74 100644 --- a/README.md +++ b/README.md @@ -172,6 +172,10 @@ This is useful to configure some actions for a specific project for instance. ```yaml # Optional. +# If set to true, the user will not be prompted to check some security risks. +# If not set, the user will be prompted for confirmation based on flags like volume, mounts, privileged, etc. +accept-the-risk: true|false +# Optional. # It allows to define a default reference to an image if none is provided by the user. # with the ref set to IMAGE a `docker runx` is equivalent to `docker runx IMAGE` ref: IMAGE diff --git a/docs/index.markdown b/docs/index.markdown index e61c0fb..942bb0c 100644 --- a/docs/index.markdown +++ b/docs/index.markdown @@ -165,6 +165,10 @@ This is useful to configure some actions for a specific project for instance. ```yaml # Optional. +# If set to true, the user will not be prompted to check some security risks. +# If not set, the user will be prompted for confirmation based on flags like volume, mounts, privileged, etc. +accept-the-risk: true|false +# Optional. # It allows to define a default reference to an image if none is provided by the user. # with the ref set to IMAGE a `docker runx` is equivalent to `docker runx IMAGE` ref: IMAGE diff --git a/docs/reference/docker_runx.yaml b/docs/reference/docker_runx.yaml index a93089d..80c9a5c 100644 --- a/docs/reference/docker_runx.yaml +++ b/docs/reference/docker_runx.yaml @@ -57,6 +57,17 @@ options: experimentalcli: false kubernetes: false swarm: false + - option: "yes" + shorthand: "y" + value_type: bool + default_value: "false" + description: Do not check flags before running the command + deprecated: false + hidden: false + experimental: false + experimentalcli: false + kubernetes: false + swarm: false deprecated: false hidden: false experimental: false diff --git a/docs/reference/runx.md b/docs/reference/runx.md index 2bbb572..0a2b1a4 100644 --- a/docs/reference/runx.md +++ b/docs/reference/runx.md @@ -21,6 +21,7 @@ Docker Run, better | `-d`, `--docs` | `bool` | | Print the documentation of the image | | `-l`, `--list` | `bool` | | List available actions | | `--opt` | `stringArray` | | Set an option value | +| `-y`, `--yes` | `bool` | | Do not check flags before running the command | diff --git a/internal/commands/root/root.go b/internal/commands/root/root.go index 0403253..b1f62a1 100644 --- a/internal/commands/root/root.go +++ b/internal/commands/root/root.go @@ -122,7 +122,7 @@ func NewCmd(dockerCli command.Cli, isPlugin bool) *cobra.Command { if tui.IsATTY(dockerCli.In().FD()) && len(rk.Config.Actions) > 0 { selectedAction := prompt.SelectAction(rk.Config.Actions) if selectedAction != "" { - return run(cmd.Context(), dockerCli.Err(), src, rk, selectedAction) + return run(cmd.Context(), dockerCli.Err(), src, rk, selectedAction, lc) } } else { _, _ = fmt.Fprintln(dockerCli.Out(), tui.Markdown(mdActions(rk))) @@ -131,7 +131,7 @@ func NewCmd(dockerCli command.Cli, isPlugin bool) *cobra.Command { } if action != "" { - return run(cmd.Context(), dockerCli.Err(), src, rk, action) + return run(cmd.Context(), dockerCli.Err(), src, rk, action, lc) } return cmd.Help() @@ -199,7 +199,7 @@ func getValuesLocal(src, action string) map[string]string { return localOpts } -func run(ctx context.Context, out io.Writer, src string, rk *runkit.RunKit, action string) error { +func run(ctx context.Context, out io.Writer, src string, rk *runkit.RunKit, action string, lc *runkit.LocalConfig) error { runnable, cleanup, err := rk.GetRunnable(action) defer cleanup() if err != nil { @@ -238,7 +238,7 @@ func run(ctx context.Context, out io.Writer, src string, rk *runkit.RunKit, acti `, runnable.Command) var flags []string - if !noFlagCheck { + if !noFlagCheck && !lc.AcceptTheRisk { flags, err = runnable.CheckFlags() } if err != nil { diff --git a/runkit/config.go b/runkit/config.go index 57ccffa..9506fde 100644 --- a/runkit/config.go +++ b/runkit/config.go @@ -62,6 +62,7 @@ func getLocalConfig() (LocalConfig, error) { } func merge(a, b LocalConfig) LocalConfig { + a.AcceptTheRisk = cmp.Or(b.AcceptTheRisk, a.AcceptTheRisk) a.Ref = cmp.Or(b.Ref, a.Ref) if a.Images == nil { a.Images = b.Images diff --git a/runkit/types.go b/runkit/types.go index 03eef84..81913c8 100644 --- a/runkit/types.go +++ b/runkit/types.go @@ -43,8 +43,9 @@ type ( OptType string LocalConfig struct { - Ref string `yaml:"ref,omitempty" json:"ref,omitempty"` - Images map[string]ConfigImage `yaml:"images,omitempty" json:"images,omitempty"` + AcceptTheRisk bool `yaml:"accept-the-risk,omitempty" json:"accept-the-risk,omitempty"` + Ref string `yaml:"ref,omitempty" json:"ref,omitempty"` + Images map[string]ConfigImage `yaml:"images,omitempty" json:"images,omitempty"` } ConfigImage struct {