Skip to content

Commit 8294483

Browse files
committed
Add confirm when delete or update action
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.
1 parent bb1b635 commit 8294483

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

commands/action.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,13 @@ var actionUpdateCmd = &cobra.Command{
139139
return actionParseError(cmd, args, err)
140140
}
141141

142+
if os.Getenv("WSK_CLI_PROMPT_ON_CHANGE") == "true" {
143+
if Flags.action.confirm != "yes" && Flags.action.confirm != "y" {
144+
fmt.Fprintf(color.Output, wski18n.T("Please update action using --confirm yes if you really want to update it"))
145+
return nil
146+
}
147+
}
148+
142149
if _, _, err = Client.Actions.Insert(action, true); err != nil {
143150
return actionInsertError(action, err)
144151
}
@@ -335,6 +342,13 @@ var actionDeleteCmd = &cobra.Command{
335342

336343
Client.Namespace = qualifiedName.GetNamespace()
337344

345+
if os.Getenv("WSK_CLI_PROMPT_ON_CHANGE") == "true" {
346+
if Flags.action.confirm != "yes" && Flags.action.confirm != "y" {
347+
fmt.Fprintf(color.Output, wski18n.T("Please delete action using --confirm yes if you really want to update it"))
348+
return nil
349+
}
350+
}
351+
338352
if _, err = Client.Actions.Delete(qualifiedName.GetEntityName()); err != nil {
339353
return actionDeleteError(qualifiedName.GetEntityName(), err)
340354
}
@@ -1269,6 +1283,8 @@ func init() {
12691283
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"))
12701284
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"))
12711285

1286+
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)"))
1287+
12721288
actionUpdateCmd.Flags().BoolVar(&Flags.action.native, "native", false, wski18n.T("treat ACTION as native action (zip file provides a compatible executable to run)"))
12731289
actionUpdateCmd.Flags().StringVar(&Flags.action.docker, "docker", "", wski18n.T("use provided docker image (a path on DockerHub) to run the action"))
12741290
actionUpdateCmd.Flags().BoolVar(&Flags.action.copy, "copy", false, wski18n.T("treat ACTION as the name of an existing action"))
@@ -1284,6 +1300,7 @@ func init() {
12841300
actionUpdateCmd.Flags().StringVarP(&Flags.common.paramFile, "param-file", "P", "", wski18n.T("`FILE` containing parameter values in JSON format"))
12851301
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"))
12861302
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"))
1303+
actionUpdateCmd.Flags().StringVar(&Flags.action.confirm, "confirm", "no", wski18n.T("you confirm do this operation?yes or y | default:no"))
12871304

12881305
actionInvokeCmd.Flags().StringSliceVarP(&Flags.common.param, "param", "p", []string{}, wski18n.T("parameter values in `KEY VALUE` format"))
12891306
actionInvokeCmd.Flags().StringVarP(&Flags.common.paramFile, "param-file", "P", "", wski18n.T("`FILE` containing parameter values in JSON format"))

commands/flags.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ type ActionFlags struct {
145145
url bool
146146
save bool
147147
saveAs string
148+
confirm string
148149
}
149150

150151
func IsVerbose() bool {

wski18n/resources/en_US.all.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,10 @@
14151415
"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",
14161416
"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"
14171417
},
1418+
{
1419+
"id": "you confirm do this operation?yes or y | default:no (environment variable WSK_CLI_PROMPT_ON_CHANGE=true works)",
1420+
"translation": "you confirm do this operation?yes or y | default:no (environment variable WSK_CLI_PROMPT_ON_CHANGE=true works)"
1421+
},
14181422
{
14191423
"id": "secure the web action. where `SECRET` is true, false, or any string. Only valid when the ACTION is a web action",
14201424
"translation": "secure the web action. where `SECRET` is true, false, or any string. Only valid when the ACTION is a web action"

0 commit comments

Comments
 (0)