Skip to content

Commit

Permalink
Add --no-prompt flag to enclave setup
Browse files Browse the repository at this point in the history
This flag requires all setup values (project and config) to be specified without an interactive prompt. If any value is not specified via flag or environment variable, the enclave setup command will exit with a non-zero code.
  • Loading branch information
Piccirello committed Jan 14, 2020
1 parent 20c4a89 commit 154c09a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/cmd/enclave_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var setupCmd = &cobra.Command{
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
silent := utils.GetBoolFlag(cmd, "silent")
promptUser := !utils.GetBoolFlag(cmd, "no-prompt")
scope := cmd.Flag("scope").Value.String()
localConfig := configuration.LocalConfig(cmd)
scopedConfig := configuration.Get(scope)
Expand All @@ -49,6 +50,10 @@ var setupCmd = &cobra.Command{
flagsFromEnvironment = append(flagsFromEnvironment, "ENCLAVE_PROJECT")
project = localConfig.EnclaveProject.Value
default:
if !promptUser {
utils.HandleError(errors.New("project must be specified via --project flag or ENCLAVE_PROJECT environment variable when using --no-prompt"))
}

projects, httpErr := http.GetProjects(localConfig.APIHost.Value, utils.GetBool(localConfig.VerifyTLS.Value, true), localConfig.Token.Value)
if !httpErr.IsNil() {
utils.HandleError(httpErr.Unwrap(), httpErr.Message)
Expand Down Expand Up @@ -95,6 +100,10 @@ var setupCmd = &cobra.Command{
flagsFromEnvironment = append(flagsFromEnvironment, "ENCLAVE_CONFIG")
config = localConfig.EnclaveConfig.Value
default:
if !promptUser {
utils.HandleError(errors.New("config must be specified via --config flag or ENCLAVE_CONFIG environment variable when using --no-prompt"))
}

configs, apiError := http.GetConfigs(localConfig.APIHost.Value, utils.GetBool(localConfig.VerifyTLS.Value, true), localConfig.Token.Value, project)
if !apiError.IsNil() {
utils.HandleError(apiError.Unwrap(), apiError.Message)
Expand Down Expand Up @@ -141,5 +150,6 @@ func init() {
setupCmd.Flags().StringP("project", "p", "", "enclave project (e.g. backend)")
setupCmd.Flags().StringP("config", "c", "", "enclave config (e.g. dev)")
setupCmd.Flags().Bool("silent", false, "do not output the response")
setupCmd.Flags().Bool("no-prompt", false, "do not prompt for information. if the project or config is not specified, an error will be thrown.")
enclaveCmd.AddCommand(setupCmd)
}

0 comments on commit 154c09a

Please sign in to comment.