mdeuser commented on a change in pull request #2544: Allow CLI to Save Code from Action URL: https://github.com/apache/incubator-openwhisk/pull/2544#discussion_r144964356
########## File path: tools/cli/go-whisk-cli/commands/action.go ########## @@ -495,6 +513,87 @@ func getExec(args []string, params ActionFlags) (*whisk.Exec, error) { return exec, nil } +func getBinaryKindExtension(kind string) (extension string){ + switch strings.ToLower(kind) { + case JAVA: + extension = JAVA_EXT + default: + extension = ZIP_EXT + } + + return extension +} + +func getKindExtension(kind string) (extension string){ + switch strings.ToLower(kind) { + case NODE_JS: + extension = NODE_JS_EXT + case PYTHON: + extension = PYTHON_EXT + case SWIFT: + fallthrough + case PHP: + extension = "." + kind + } + + return extension +} + +func saveCode(action whisk.Action, filename string) (err error) { + var code string + var kind string + var exec whisk.Exec + + exec = *action.Exec + kind = strings.Split(exec.Kind, ":")[0] + + if strings.ToLower(kind) == BLACKBOX { + return cannotSaveImageError() + } else if strings.ToLower(kind) == SEQUENCE { + return cannotSaveSequenceError() + } + + if exec.Code == nil { + code = "" + } else { + code = *exec.Code + } + + if *exec.Binary { + decoded, _ := base64.StdEncoding.DecodeString(code) + code = string(decoded) + + if len(filename) == 0 { + filename = action.Name + getBinaryKindExtension(kind) + } + } else { + if len(filename) == 0 { + filename = action.Name + getKindExtension(kind) + } + } Review comment: not 100% sure, but it seems that an npm .zip action won't be handled correctly. a npm .zip file is not an attachment, so the exec.binary will be `false`; also the associated exec.code is encoded binary which will need decoding back into the binary prior to writing out to a file. ---------------------------------------------------------------- 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