MCPcopy Create free account
hub / github.com/apache/openwhisk-cli / saveCode

Function saveCode

commands/action.go:709–761  ·  view source on GitHub ↗
(action whisk.Action, filename string)

Source from the content-addressed store, hash-verified

707}
708
709func saveCode(action whisk.Action, filename string) (err error) {
710 var code string
711 var runtime string
712 var exec whisk.Exec
713
714 exec = *action.Exec
715 runtime = strings.Split(exec.Kind, ":")[0]
716
717 if strings.ToLower(runtime) == BLACKBOX && exec.Code == nil && *exec.Binary == false {
718 return cannotSaveImageError()
719 } else if strings.ToLower(runtime) == SEQUENCE {
720 return cannotSaveSequenceError()
721 }
722
723 if exec.Code != nil {
724 code = *exec.Code
725 }
726
727 if *exec.Binary {
728 decoded, _ := base64.StdEncoding.DecodeString(code)
729 code = string(decoded)
730
731 if len(filename) == 0 {
732 filename = action.Name + getBinaryKindExtension(runtime)
733 }
734 } else {
735 if len(filename) == 0 {
736 filename = action.Name + getKindExtension(runtime)
737 }
738 }
739
740 if exists, err := FileExists(filename); err != nil {
741 return err
742 } else if exists {
743 return fileExistsError(filename)
744 }
745
746 if err := writeFile(filename, code); err != nil {
747 return err
748 }
749
750 pwd, err := os.Getwd()
751 if err != nil {
752 whisk.Debug(whisk.DbgError, "os.Getwd() error: %s\n", err)
753 return err
754 }
755
756 savedPath := fmt.Sprintf("%s%s%s", pwd, string(os.PathSeparator), filename)
757
758 printSavedActionCodeSuccess(savedPath)
759
760 return nil
761}
762
763func webAction(webMode string, annotations whisk.KeyValueArr, entityName string, preserveAnnotations bool, existingAction *whisk.Action) (whisk.KeyValueArr, error) {
764 switch strings.ToLower(webMode) {

Callers 1

action.goFile · 0.85

Calls 8

cannotSaveImageErrorFunction · 0.85
cannotSaveSequenceErrorFunction · 0.85
getBinaryKindExtensionFunction · 0.85
getKindExtensionFunction · 0.85
FileExistsFunction · 0.85
fileExistsErrorFunction · 0.85
writeFileFunction · 0.85

Tested by

no test coverage detected