Skip to content

Commit

Permalink
Move profile flag to common flags
Browse files Browse the repository at this point in the history
Move profile flag to common flags for server/agent so that it can be
loaded from config YAML.

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
  • Loading branch information
brandond committed Sep 29, 2020
1 parent 5cf8216 commit 13d8832
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 28 deletions.
10 changes: 9 additions & 1 deletion pkg/cli/cmds/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,16 @@ func NewAgentCommand() cli.Command {
}

func AgentRun(clx *cli.Context) error {
if profile == "" {
switch profile {
case "cis-1.5":
if err := validateCISreqs(); err != nil {
logrus.Fatal(err)
}
case "":
logrus.Warn("not running in CIS 1.5 mode")
default:
logrus.Fatal("invalid value provided for --profile flag")
}

return rke2.Agent(clx, config)
}
22 changes: 6 additions & 16 deletions pkg/cli/cmds/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ var (
EnvVar: "RKE2_CLOUD_PROVIDER_CONFIG",
Destination: &config.CloudProviderConfig,
},
&cli.StringFlag{
Name: "profile",
Usage: "(security) Validate system configuration against the selected benchmark (valid items: cis-1.5)",
EnvVar: "RKE2_CIS_PROFILE",
Destination: &profile,
},
}
)

Expand Down Expand Up @@ -133,28 +139,12 @@ func NewApp() *cli.App {
Destination: &debug,
EnvVar: "RKE2_DEBUG",
},
cli.StringFlag{
Name: "profile",
Usage: "Indicate we need to run in CIS 1.5 mode",
Destination: &profile,
EnvVar: "RKE2_CIS_PROFILE",
},
}

app.Before = func(clx *cli.Context) error {
if debug {
logrus.SetLevel(logrus.DebugLevel)
}
switch profile {
case "cis-1.5":
if err := validateCISreqs(); err != nil {
logrus.Fatal(err)
}
case "":
// continue. warning output another layer down.
default:
logrus.Fatal("invalid value provided for --profile flag")
}
return nil
}

Expand Down
10 changes: 9 additions & 1 deletion pkg/cli/cmds/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,16 @@ func NewServerCommand() cli.Command {
}

func ServerRun(clx *cli.Context) error {
if profile == "" {
switch profile {
case "cis-1.5":
if err := validateCISreqs(); err != nil {
logrus.Fatal(err)
}
case "":
logrus.Warn("not running in CIS 1.5 mode")
default:
logrus.Fatal("invalid value provided for --profile flag")
}

return rke2.Server(clx, config)
}
12 changes: 2 additions & 10 deletions pkg/rke2/rke2.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,10 @@ func setup(clx *cli.Context, cfg Config) error {
case cli.StringFlag:
if strings.Contains(t.Name, "data-dir") {
dataDir = *t.Destination
}
}
}

for _, f := range clx.App.Flags {
switch t := f.(type) {
case cli.StringFlag:
if t.Name == "profile" && t.Destination != nil && *t.Destination != "" {
} else if t.Name == "profile" && t.Destination != nil && *t.Destination != "" {
cisMode = true
}
default:
// nothing to do. Keep moving.

}
}

Expand Down

0 comments on commit 13d8832

Please sign in to comment.