mdeuser commented on a change in pull request #244: Add --web-secure option to 
action create/update
URL: 
https://github.com/apache/incubator-openwhisk-cli/pull/244#discussion_r175903104
 
 

 ##########
 File path: commands/action.go
 ##########
 @@ -442,14 +457,109 @@ func parseAction(cmd *cobra.Command, args []string, 
update bool) (*whisk.Action,
                return nil, noArtifactError()
        }
 
+       whisk.Debug(whisk.DbgInfo, "Parsed action struct: %#v\n", action)
+       return action, err
+}
+
+func augmentAction(cmd *cobra.Command, args []string, action *whisk.Action, 
update bool) (*whisk.Action, error) {
+       var err error
+       var existingAction *whisk.Action = nil
+       var augmentedAction *whisk.Action = new(whisk.Action)
+       *augmentedAction = *action
+
+       if update {
+               if existingAction, _, err = Client.Actions.Get(action.Name, 
DO_NOT_FETCH_CODE); err != nil {
+                       whiskErr, isWhiskError := err.(*whisk.WskError)
+
+                       if (isWhiskError && whiskErr.ExitCode != 
whisk.EXIT_CODE_NOT_FOUND) || !isWhiskError {
+                               return nil, actionGetError(action.Name, 
DO_NOT_FETCH_CODE, err)
+                       }
+               }
+       }
+
+       // Augment the action's annotations with the --web related annotations
+       // FIXME MWD - avoid retrieving existing action TWICE!  once above and 
once in the webAction() below
+       if augmentedAction, err = augmentWebArg(cmd, args, augmentedAction, 
existingAction); err != nil {
+               return nil, err
+       }
+
+       // Augment the action's annotations with the --web-secure related 
annotations
+       if augmentedAction, err = augmentWebSecureArg(cmd, args, action, 
augmentedAction, existingAction); err != nil {
+               return nil, err
+       }
+
+       whisk.Debug(whisk.DbgInfo, "Augmented action struct: %#v\n", 
augmentedAction)
+       return augmentedAction, err
+}
+
+func augmentWebArg(cmd *cobra.Command, args []string, action *whisk.Action, 
existingAction *whisk.Action) (*whisk.Action, error) {
+       var err error
+       preserveAnnotations := action.Annotations == nil
+       var augmentedAction *whisk.Action = new(whisk.Action)
+       *augmentedAction = *action
 
 Review comment:
   @dubee good question...   not really.  in general, there are three separate 
"action" states that must be kept separate
   
   1. the original cli input that generated an action.  this action has the 
nicely parsed annotations/parameters
   2. the in-progress action which may or may not have been manipulated by 
other command line option processing
   3. the existing action (when present)
   
   the option augmentation logic is free to update the in-progress state, but 
not touch the original or existing action states.  this way each of the special 
command option processing will have all of the state to make its action 
augmentation decisions.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to