* * Return a whisk.Action augmented with --web-secure annotation updates * originalAction: a action constructed from command line argument * action: an action constructed from command line args + possible other augmentation (i.e. --web annotations) * existingAction: on an action updat
(cmd *cobra.Command, args []string, originalAction *whisk.Action, action *whisk.Action, existingAction *whisk.Action)
| 550 | * existingAction: on an action update, this is the existing action |
| 551 | */ |
| 552 | func augmentWebSecureArg(cmd *cobra.Command, args []string, originalAction *whisk.Action, action *whisk.Action, existingAction *whisk.Action) (*whisk.Action, error) { |
| 553 | preserveAnnotations := action.Annotations == nil |
| 554 | var augmentedAction *whisk.Action = new(whisk.Action) |
| 555 | *augmentedAction = *action |
| 556 | disableWebAction := strings.ToLower(Flags.action.web) == "false" || strings.ToLower(Flags.action.web) == "no" |
| 557 | isWebSecureFlagValidToUse := action.WebAction() || (existingAction != nil && existingAction.WebAction() && !disableWebAction) |
| 558 | |
| 559 | // Process the --web-secure flag when set |
| 560 | if cmd.LocalFlags().Changed(WEB_SECURE_FLAG) { |
| 561 | // The --web-secure option is only valid when: |
| 562 | // 1. action --web is set to either true or raw (i.e. web-export annotation is true) |
| 563 | // -OR- |
| 564 | // 2. existing action web-export annotation is true && action --web is not false/no |
| 565 | whisk.Debug(whisk.DbgInfo, "disableWebAction: %v isWebSecureFlagValidToUse: %v\n", disableWebAction, isWebSecureFlagValidToUse) |
| 566 | if !isWebSecureFlagValidToUse { |
| 567 | return nil, webSecureUsageError() |
| 568 | } |
| 569 | |
| 570 | // Carry forward some or all of the existing action's annotations |
| 571 | // all -> if original command line had at least one annotation specified |
| 572 | // some -> if original command line had NO annotations, carry forward web/websecure annotation values |
| 573 | if existingAction != nil { |
| 574 | if preserveAnnotations { |
| 575 | augmentedAction.Annotations = action.Annotations.AppendKeyValueArr(existingAction.Annotations) |
| 576 | } else { |
| 577 | augmentedAction.Annotations = action.Annotations.AppendKeyValueArr(getWebActionAnnotations(existingAction)) |
| 578 | augmentedAction.Annotations = augmentedAction.Annotations.AppendKeyValueArr(getWebSecureAnnotations(existingAction)) |
| 579 | } |
| 580 | } |
| 581 | // when "--web-secure false", need to delete require-whisk-auth annotation |
| 582 | secureSecret := webSecureSecret(Flags.action.websecure) // will be false when "--web-secure false" |
| 583 | existingSecret := augmentedAction.Annotations.GetValue(WEB_SECURE_ANNOT) |
| 584 | _, disableSecurity := secureSecret.(bool) |
| 585 | if existingSecret != nil && disableSecurity { |
| 586 | augmentedAction.DelAnnotations = []string{"require-whisk-auth"} |
| 587 | } |
| 588 | augmentedAction.Annotations = updateWebSecureAnnotation(Flags.action.websecure, augmentedAction.Annotations) |
| 589 | } |
| 590 | |
| 591 | whisk.Debug(whisk.DbgInfo, "augmentWebSecureArg: Augmented action struct: %#v\n", augmentedAction) |
| 592 | return augmentedAction, nil |
| 593 | } |
| 594 | |
| 595 | func getExec(args []string, params ActionFlags) (*whisk.Exec, error) { |
| 596 | var err error |
no test coverage detected