Skip to content

Commit

Permalink
Add confirm when delete or update action
Browse files Browse the repository at this point in the history
As more and more production system uses openwhisk,
Users will need some feature to protect their action to be
deleted or updated by mistake When environment variable
WSK_CLI_PROMPT_ON_CHANGE=true.
  • Loading branch information
ningyougang committed Sep 25, 2018
1 parent bb1b635 commit 8294483
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
17 changes: 17 additions & 0 deletions commands/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ var actionUpdateCmd = &cobra.Command{
return actionParseError(cmd, args, err)
}

if os.Getenv("WSK_CLI_PROMPT_ON_CHANGE") == "true" {
if Flags.action.confirm != "yes" && Flags.action.confirm != "y" {
fmt.Fprintf(color.Output, wski18n.T("Please update action using --confirm yes if you really want to update it"))
return nil
}
}

if _, _, err = Client.Actions.Insert(action, true); err != nil {
return actionInsertError(action, err)
}
Expand Down Expand Up @@ -335,6 +342,13 @@ var actionDeleteCmd = &cobra.Command{

Client.Namespace = qualifiedName.GetNamespace()

if os.Getenv("WSK_CLI_PROMPT_ON_CHANGE") == "true" {
if Flags.action.confirm != "yes" && Flags.action.confirm != "y" {
fmt.Fprintf(color.Output, wski18n.T("Please delete action using --confirm yes if you really want to update it"))
return nil
}
}

if _, err = Client.Actions.Delete(qualifiedName.GetEntityName()); err != nil {
return actionDeleteError(qualifiedName.GetEntityName(), err)
}
Expand Down Expand Up @@ -1269,6 +1283,8 @@ func init() {
actionCreateCmd.Flags().StringVar(&Flags.action.web, WEB_FLAG, "", wski18n.T("treat ACTION as a web action, a raw HTTP web action, or as a standard action; yes | true = web action, raw = raw HTTP web action, no | false = standard action"))
actionCreateCmd.Flags().StringVar(&Flags.action.websecure, WEB_SECURE_FLAG, "", wski18n.T("secure the web action. where `SECRET` is true, false, or any string. Only valid when the ACTION is a web action"))

actionDeleteCmd.Flags().StringVar(&Flags.action.confirm, "confirm", "no", wski18n.T("you confirm do this operation?yes or y | default:no (environment variable WSK_CLI_PROMPT_ON_CHANGE=true works)"))

actionUpdateCmd.Flags().BoolVar(&Flags.action.native, "native", false, wski18n.T("treat ACTION as native action (zip file provides a compatible executable to run)"))
actionUpdateCmd.Flags().StringVar(&Flags.action.docker, "docker", "", wski18n.T("use provided docker image (a path on DockerHub) to run the action"))
actionUpdateCmd.Flags().BoolVar(&Flags.action.copy, "copy", false, wski18n.T("treat ACTION as the name of an existing action"))
Expand All @@ -1284,6 +1300,7 @@ func init() {
actionUpdateCmd.Flags().StringVarP(&Flags.common.paramFile, "param-file", "P", "", wski18n.T("`FILE` containing parameter values in JSON format"))
actionUpdateCmd.Flags().StringVar(&Flags.action.web, WEB_FLAG, "", wski18n.T("treat ACTION as a web action, a raw HTTP web action, or as a standard action; yes | true = web action, raw = raw HTTP web action, no | false = standard action"))
actionUpdateCmd.Flags().StringVar(&Flags.action.websecure, WEB_SECURE_FLAG, "", wski18n.T("secure the web action. where `SECRET` is true, false, or any string. Only valid when the ACTION is a web action"))
actionUpdateCmd.Flags().StringVar(&Flags.action.confirm, "confirm", "no", wski18n.T("you confirm do this operation?yes or y | default:no"))

actionInvokeCmd.Flags().StringSliceVarP(&Flags.common.param, "param", "p", []string{}, wski18n.T("parameter values in `KEY VALUE` format"))
actionInvokeCmd.Flags().StringVarP(&Flags.common.paramFile, "param-file", "P", "", wski18n.T("`FILE` containing parameter values in JSON format"))
Expand Down
1 change: 1 addition & 0 deletions commands/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ type ActionFlags struct {
url bool
save bool
saveAs string
confirm string
}

func IsVerbose() bool {
Expand Down
4 changes: 4 additions & 0 deletions wski18n/resources/en_US.all.json
Original file line number Diff line number Diff line change
Expand Up @@ -1415,6 +1415,10 @@
"id": "treat ACTION as a web action, a raw HTTP web action, or as a standard action; yes | true = web action, raw = raw HTTP web action, no | false = standard action",
"translation": "treat ACTION as a web action, a raw HTTP web action, or as a standard action; yes | true = web action, raw = raw HTTP web action, no | false = standard action"
},
{
"id": "you confirm do this operation?yes or y | default:no (environment variable WSK_CLI_PROMPT_ON_CHANGE=true works)",
"translation": "you confirm do this operation?yes or y | default:no (environment variable WSK_CLI_PROMPT_ON_CHANGE=true works)"
},
{
"id": "secure the web action. where `SECRET` is true, false, or any string. Only valid when the ACTION is a web action",
"translation": "secure the web action. where `SECRET` is true, false, or any string. Only valid when the ACTION is a web action"
Expand Down

0 comments on commit 8294483

Please sign in to comment.