Skip to content

Commit 62cab2f

Browse files
committed
Add confirm mechanism 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.
1 parent bb1b635 commit 62cab2f

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

commands/action.go

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

142+
if Flags.action.confirm != "yes" && Flags.action.confirm != "y" {
143+
fmt.Fprintf(color.Output, wski18n.T("Please update action using --confirm yes if you really want to update it"))
144+
return nil
145+
}
146+
142147
if _, _, err = Client.Actions.Insert(action, true); err != nil {
143148
return actionInsertError(action, err)
144149
}
@@ -335,6 +340,11 @@ var actionDeleteCmd = &cobra.Command{
335340

336341
Client.Namespace = qualifiedName.GetNamespace()
337342

343+
if Flags.action.confirm != "yes" && Flags.action.confirm != "y" {
344+
fmt.Fprintf(color.Output, wski18n.T("Please delete action using --confirm yes if you really want to delete it"))
345+
return nil
346+
}
347+
338348
if _, err = Client.Actions.Delete(qualifiedName.GetEntityName()); err != nil {
339349
return actionDeleteError(qualifiedName.GetEntityName(), err)
340350
}
@@ -1269,6 +1279,8 @@ func init() {
12691279
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"))
12701280
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"))
12711281

1282+
actionDeleteCmd.Flags().StringVar(&Flags.action.confirm, "confirm", "no", wski18n.T("you confirm do this operation?yes or y | default:no"))
1283+
12721284
actionUpdateCmd.Flags().BoolVar(&Flags.action.native, "native", false, wski18n.T("treat ACTION as native action (zip file provides a compatible executable to run)"))
12731285
actionUpdateCmd.Flags().StringVar(&Flags.action.docker, "docker", "", wski18n.T("use provided docker image (a path on DockerHub) to run the action"))
12741286
actionUpdateCmd.Flags().BoolVar(&Flags.action.copy, "copy", false, wski18n.T("treat ACTION as the name of an existing action"))
@@ -1284,6 +1296,7 @@ func init() {
12841296
actionUpdateCmd.Flags().StringVarP(&Flags.common.paramFile, "param-file", "P", "", wski18n.T("`FILE` containing parameter values in JSON format"))
12851297
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"))
12861298
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"))
1299+
actionUpdateCmd.Flags().StringVar(&Flags.action.confirm, "confirm", "no", wski18n.T("you confirm do this operation?yes or y | default:no"))
12871300

12881301
actionInvokeCmd.Flags().StringSliceVarP(&Flags.common.param, "param", "p", []string{}, wski18n.T("parameter values in `KEY VALUE` format"))
12891302
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",
1420+
"translation": "you confirm do this operation?yes or y | default:no"
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)