Documentation
¶
Overview ¶
* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.
* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.
* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.
* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.
Example (BadZip) ¶
Issue #62 sample zip
buf := []byte{ 0x50, 0x4b, 0x03, 0x04, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0xb0, 0x81, 0x4d, 0x2d, 0xf6, 0xa5, 0x66, 0x48, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x09, 0x00, 0x1c, 0x00, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x2e, 0x70, 0x68, 0x70, 0x55, 0x54, 0x09, 0x00, 0x03, 0x51, 0x05, 0x03, 0x5c, 0x54, 0x05, 0x03, 0x5c, 0x75, 0x78, 0x0b, 0x00, 0x01, 0x04, 0xf5, 0x01, 0x00, 0x00, 0x04, 0x14, 0x00, 0x00, 0x00, 0x3c, 0x3f, 0x70, 0x68, 0x70, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6e, 0x69, 0x61, 0x6d, 0x28, 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, 0x24, 0x61, 0x72, 0x67, 0x73, 0x29, 0x20, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5b, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x3d, 0x3e, 0x20, 0x22, 0x69, 0x74, 0x20, 0x77, 0x6f, 0x72, 0x6b, 0x73, 0x22, 0x5d, 0x3b, 0x0a, 0x7d, 0x0a, 0x50, 0x4b, 0x01, 0x02, 0x1e, 0x03, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0xb0, 0x81, 0x4d, 0x2d, 0xf6, 0xa5, 0x66, 0x48, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x09, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xb4, 0x81, 0x00, 0x00, 0x00, 0x00, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x2e, 0x70, 0x68, 0x70, 0x55, 0x54, 0x05, 0x00, 0x03, 0x51, 0x05, 0x03, 0x5c, 0x75, 0x78, 0x0b, 0x00, 0x01, 0x04, 0xf5, 0x01, 0x00, 0x00, 0x04, 0x14, 0x00, 0x00, 0x00, 0x50, 0x4b, 0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x4f, 0x00, 0x00, 0x00, 0x8b, 0x00, 0x00, 0x00, 0x00, 0x00, } fmt.Printf("%t", IsZip(buf))
Output: true
Example (Badcompile) ¶
os.Setenv("OW_LOG_INIT_ERROR", "1") ts, cur, log := startTestServer("_test/badcompile.sh") res, _, _ := doPost(ts.URL+"/init", initBytes([]byte("hello"), "main")) fmt.Print(res) stopTestServer(ts, cur, log) os.Setenv("OW_LOG_INIT_ERROR", "")
Output: {"error":"The action failed to generate or locate a binary. See logs for details."} error in stdout error in stderr XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
Example (Badinit_nocompiler) ¶
ts, cur, log := startTestServer("") doRun(ts, "") doInit(ts, "{}") //sys("ls", "_test/exec") doInit(ts, initBinary("_test/exec", "")) // empty doInit(ts, initBinary("_test/hi", "")) // say hi doInit(ts, initBinary("_test/hello.src", "")) // source not executable doRun(ts, "") stopTestServer(ts, cur, log)
Output: 500 {"error":"no action defined yet"} 403 {"error":"Missing main/no code to execute."} 502 {"error":"cannot start action: command exited"} 502 {"error":"cannot start action: command exited"} 502 {"error":"cannot start action: command exited"} 500 {"error":"no action defined yet"} hi
Example (Bininit_nocompiler) ¶
ts, cur, log := startTestServer("") doRun(ts, "") doInit(ts, initBinary("_test/hello_message", "")) doRun(ts, "") stopTestServer(ts, cur, log) ts, cur, log = startTestServer("") doInit(ts, initBinary("_test/hello_greeting", "")) doRun(ts, "") stopTestServer(ts, cur, log)
Output: 500 {"error":"no action defined yet"} 200 {"ok":true} 200 {"message":"Hello, Mike!"} name=Mike XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX 200 {"ok":true} 200 {"greetings":"Hello, Mike"} Hello, Mike XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
Example (Cli_compiler) ¶
compile a main
sys(PREP, "hello.src", "0", "exec") ap := NewActionProxy(TMP, COMP, os.Stdout, os.Stderr) fmt.Println(isCompiled(TMP + "0/src/exec")) ap.CompileAction("main", TMP+"0/src", TMP+"0/bin") sys(CHECK, TMP+"0/bin/exec") fmt.Println(isCompiled(TMP + "0/bin/exec")) // errors fmt.Println(isCompiled(TMP + "0/bin/exec1"))
Output: false _test/compile/0/bin/exec: application/x-executable name=Mike {"message":"Hello, Mike!"} true false
Example (CompileError) ¶
N := "6" sys(PREP, "error.src", N) ap := NewActionProxy(TMP, COMP, os.Stdout, os.Stderr) err := ap.CompileAction("main", TMP+N+"/src", TMP+N+"/bin") fmt.Printf("%v", removeLineNr(err.Error()))
Output: ./exec__.go::: syntax error: unexpected error at end of statement
Example (Compile_bin) ¶
os.RemoveAll("./action/c1") logf, _ := ioutil.TempFile("/tmp", "log") ap := NewActionProxy("./action/c1", "_test/compile.py", logf, logf) dat, _ := Zip("_test/pysample") inp := bytes.NewBuffer(dat) out := new(bytes.Buffer) ap.ExtractAndCompileIO(inp, out, "main", "") Unzip(out.Bytes(), "./action/c1/out") sys("_test/find.sh", "./action/c1/out")
Output: ./action/c1/out ./action/c1/out/exec ./action/c1/out/lib ./action/c1/out/lib/action ./action/c1/out/lib/action/__init__.py ./action/c1/out/lib/action/main.py ./action/c1/out/lib/exec.py
Example (Compile_simple) ¶
comp, _ := filepath.Abs("../common/gobuild.py") ts, cur, log := startTestServer(comp) doRun(ts, "") doInit(ts, initCode("_test/hello.src", "")) doRun(ts, "") stopTestServer(ts, cur, log)
Output: 500 {"error":"no action defined yet"} 200 {"ok":true} 200 {"message":"Hello, Mike!"} name=Mike XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
Example (Compile_src) ¶
os.RemoveAll("./action/c2") logf, _ := ioutil.TempFile("/tmp", "log") ap := NewActionProxy("./action/c2", "_test/compile.py", logf, logf) log.Println(ioutil.ReadAll(logf)) dat, _ := Zip("_test/pysample/lib") inp := bytes.NewBuffer(dat) out := new(bytes.Buffer) ap.ExtractAndCompileIO(inp, out, "main", "") Unzip(out.Bytes(), "./action/c2/out") sys("_test/find.sh", "./action/c2/out")
Output: ./action/c2/out ./action/c2/out/action ./action/c2/out/action/action ./action/c2/out/action/action/__init__.py ./action/c2/out/action/action/main.py ./action/c2/out/action/exec.py ./action/c2/out/exec
Example (Compile_withMain) ¶
comp, _ := filepath.Abs("../common/gobuild.py") ts, cur, log := startTestServer(comp) doRun(ts, "") doInit(ts, initCode("_test/hello1.src", "hello")) doRun(ts, "") stopTestServer(ts, cur, log)
Output: 500 {"error":"no action defined yet"} 200 {"ok":true} 200 {"hello":"Hello, Mike!"} name=Mike XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
Example (Compile_withZipSrc) ¶
comp, _ := filepath.Abs("../common/gobuild.py") ts, cur, log := startTestServer(comp) doRun(ts, "") doInit(ts, initBinary("_test/hello.zip", "")) doRun(ts, "") stopTestServer(ts, cur, log)
Output: 500 {"error":"no action defined yet"} 200 {"ok":true} 200 {"greetings":"Hello, Mike"} Main Hello, Mike XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
Example (ExecutionEnv_check) ¶
os.Setenv("OW_EXECUTION_ENV", "bad/env") ts, cur, log := startTestServer("") res, _, _ := doPost(ts.URL+"/init", initBinary("_test/helloack.zip", "main")) fmt.Print(res) os.Setenv("OW_EXECUTION_ENV", "exec/env") res, _, _ = doPost(ts.URL+"/init", initBinary("_test/helloack.zip", "main")) fmt.Print(res) stopTestServer(ts, cur, log) // reset value os.Setenv("OW_EXECUTION_ENV", "")
Output: Expected exec.env should start with bad/env Actual value: exec/env {"error":"cannot start action: Execution environment version mismatch. See logs for details."} {"ok":true}
Example (ExecutionEnv_nocheck) ¶
os.Setenv("OW_EXECUTION_ENV", "") ts, cur, log := startTestServer("") res, _, _ := doPost(ts.URL+"/init", initBinary("_test/helloack.zip", "main")) fmt.Print(res) stopTestServer(ts, cur, log)
Output: {"ok":true}
Example (Filetype) ¶
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package main import "fmt" var zipFile = []byte{ 0x50, 0x4b, 0x03, 0x04, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x60, 0x83, 0x4d, 0x00, 0x00, } var linuxFile = []byte{ 0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, } var darwinFile = []byte{ 0xcf, 0xfa, 0xed, 0xfe, 0x07, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, } var windowsFile = []byte{ 0x4d, 0x5a, 0x90, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, } var shellFile = []byte("#!/bin/sh\necho hello\n") func main() { fmt.Printf("%t\n%t\n", IsElf(linuxFile), IsElf(zipFile)) fmt.Printf("%t\n%t\n", IsMach64(darwinFile), IsMach64(zipFile)) fmt.Printf("%t\n%t\n", IsExe(windowsFile), IsExe(zipFile)) fmt.Printf("%t\n%t\n", IsZip(zipFile), IsExe(linuxFile)) fmt.Printf("%t\n%t\n", IsExecutable(linuxFile, "linux"), IsExecutable(zipFile, "linux")) fmt.Printf("%t\n%t\n", IsExecutable(windowsFile, "windows"), IsExecutable(zipFile, "windows")) fmt.Printf("%t\n%t\n", IsExecutable(darwinFile, "darwin"), IsExecutable(zipFile, "darwin")) fmt.Printf("%t\n%t\n%t\n", IsExecutable(shellFile, "darwin"), IsExecutable(shellFile, "linux"), IsExecutable(shellFile, "windows")) }
Output: true false true false true false true false true false true false true false true true false
Example (Hello) ¶
compile a not-main (hello) function
N := "1" sys(PREP, "hello1.src", N, "exec") ap := NewActionProxy(TMP, COMP, os.Stdout, os.Stderr) env := map[string]interface{}{"GOROOT": TMP + N} ap.SetEnv(env) ap.CompileAction("hello", TMP+N+"/src", TMP+N+"/bin") sys(CHECK, TMP+N+"/bin/exec")
Output: _test/compile/1/bin/exec: application/x-executable name=Mike {"hello":"Hello, Mike!"}
Example (Jar) ¶
os.RemoveAll("./action/unzip") os.Mkdir("./action/unzip", 0755) buf, err := Zip("_test/jar") fmt.Println(err) err = UnzipOrSaveJar(buf, "./action/unzip", "./action/unzip/exec.jar") sys("_test/find.sh", "./action/unzip") fmt.Println(err)
Output: <nil> ./action/unzip ./action/unzip/exec.jar <nil>
Example (Json_init) ¶
fmt.Println(initCode("", "")) fmt.Println(initCode("_test/etc", "")) fmt.Println(initCode("_test/etc", "world")) fmt.Println(initBinary("_test/etc", "")) fmt.Println(initBinary("_test/etc", "hello"))
Output: {"value":{}} {"value":{"code":"1\n"}} {"value":{"code":"1\n","main":"world"}} {"value":{"code":"MQo=","binary":true}} {"value":{"code":"MQo=","binary":true,"main":"hello"}}
Example (Main_nocompiler) ¶
ts, cur, log := startTestServer("") doRun(ts, "") doInit(ts, initBinary("_test/hello_message", "message")) doRun(ts, "") stopTestServer(ts, cur, log) ts, cur, log = startTestServer("") doInit(ts, initBinary("_test/hello_greeting", "greeting")) doRun(ts, "") stopTestServer(ts, cur, log)
Output: 500 {"error":"no action defined yet"} 200 {"ok":true} 200 {"message":"Hello, Mike!"} name=Mike XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX 200 {"ok":true} 200 {"greetings":"Hello, Mike"} Hello, Mike XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
Example (Main_zipinit_nocompiler) ¶
ts, cur, log := startTestServer("") doRun(ts, "") doInit(ts, initBinary("_test/hello_greeting.zip", "greeting")) doRun(ts, "") stopTestServer(ts, cur, log) ts, cur, log = startTestServer("") doInit(ts, initBinary("_test/hello_message.zip", "message")) doRun(ts, "") stopTestServer(ts, cur, log)
Output: 500 {"error":"no action defined yet"} 200 {"ok":true} 200 {"greetings":"Hello, Mike"} Hello, Mike XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX 200 {"ok":true} 200 {"message":"Hello, Mike!"} name=Mike XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
Example (Package) ¶
compile a function including a package
N := "2" sys(PREP, "hello2.src", N, "exec", "hello") ap := NewActionProxy(TMP, COMP, os.Stdout, os.Stderr) env := map[string]interface{}{"GOROOT": TMP + N} ap.SetEnv(env) ap.CompileAction("main", TMP+N+"/src", TMP+N+"/bin") sys(CHECK, TMP+N+"/bin/exec")
Output: _test/compile/2/bin/exec: application/x-executable Main Hello, Mike {"greetings":"Hello, Mike"}
Example (Parse_env) ¶
var request initBodyRequest body := []byte(`{"code":"code"}`) json.Unmarshal(body, &request) fmt.Println(request.Env) var request1 initBodyRequest body = []byte(`{"code":"code", "env":{"hello":"world"}}`) json.Unmarshal(body, &request1) fmt.Println(request1.Env["hello"]) var request2 initBodyRequest body = []byte(`{"code":"code", "env": { "hello": "world", "hi": "all"}}`) json.Unmarshal(body, &request2) fmt.Println(request2.Env["hello"], request2.Env["hi"])
Output: map[] world world all
Example (Shell_nocompiler) ¶
ts, cur, log := startTestServer("") doRun(ts, "") doInit(ts, initBinary("_test/hello.sh", "")) doRun(ts, "") doRun(ts, `{"name":"world"}`) stopTestServer(ts, cur, log)
Output: 500 {"error":"no action defined yet"} 200 {"ok":true} 200 {"hello": "Mike"} 200 {"hello": "world"} msg=hello Mike XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX msg=hello world XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
Example (StartTestServer) ¶
ts, cur, log := startTestServer("") res, _, _ := doPost(ts.URL+"/init", "{}") fmt.Print(res) res, _, _ = doPost(ts.URL+"/init", "XXX") fmt.Print(res) res, _, _ = doPost(ts.URL+"/run", "{}") fmt.Print(res) res, _, _ = doPost(ts.URL+"/run", "XXX") fmt.Print(res) stopTestServer(ts, cur, log)
Output: {"error":"Missing main/no code to execute."} {"error":"Error unmarshaling request: invalid character 'X' looking for beginning of value"} {"error":"no action defined yet"} {"error":"no action defined yet"}
Example (Venv) ¶
os.RemoveAll("./action/unzip") os.Mkdir("./action/unzip", 0755) buf, err := Zip("_test/venv") fmt.Println(1, err) err = ioutil.WriteFile("/tmp/appo.zip", buf, 0644) fmt.Println(2, err) err = UnzipOrSaveJar(buf, "./action/unzip", "./action/unzip/exec.jar") sys("bash", "-c", "cd action/unzip/bin && find . -type l -name python && rm ./python") sys2("bash", "-c", "diff -qr _test/venv action/unzip 2>/dev/null") fmt.Println(3, err)
Output: 1 <nil> 2 <nil> ./python Only in _test/venv/bin: python 3 <nil>
Example (WithMain) ¶
N := "7" sys(PREP, "hi.src", N, "exec") ap := NewActionProxy(TMP, COMP, os.Stdout, os.Stderr) err := ap.CompileAction("main", TMP+N+"/src", TMP+N+"/bin") fmt.Println(err) sys(TMP + N + "/bin/exec")
Output: <nil> hi
Example (Zip) ¶
os.RemoveAll("./action/unzip") os.Mkdir("./action/unzip", 0755) buf, err := Zip("_test/pysample") fmt.Println(err) err = UnzipOrSaveJar(buf, "./action/unzip", "./action/unzip/exec.jar") sys("_test/find.sh", "./action/unzip") fmt.Println(err)
Output: <nil> ./action/unzip ./action/unzip/exec ./action/unzip/lib ./action/unzip/lib/action ./action/unzip/lib/action/__init__.py ./action/unzip/lib/action/main.py ./action/unzip/lib/exec.py <nil>
Example (Zip_init) ¶
ts, cur, log := startTestServer("") buf, _ := Zip("_test/pysample") doInit(ts, initBytes(buf, "")) doRun(ts, ``) doRun(ts, `{"name":"World"}`) stopTestServer(ts, cur, log)
Output: 200 {"ok":true} 200 {"python": "Hello, Mike"} 200 {"python": "Hello, World"} XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
Example (Zipinit_nocompiler) ¶
ts, cur, log := startTestServer("") doRun(ts, "") doInit(ts, initBinary("_test/hello_greeting.zip", "")) doRun(ts, "") stopTestServer(ts, cur, log) ts, cur, log = startTestServer("") doInit(ts, initBinary("_test/hello_message.zip", "")) doRun(ts, "") stopTestServer(ts, cur, log)
Output: 500 {"error":"no action defined yet"} 200 {"ok":true} 200 {"greetings":"Hello, Mike"} Hello, Mike XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX 200 {"ok":true} 200 {"message":"Hello, Mike!"} name=Mike XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
Index ¶
- Constants
- Variables
- func Debug(format string, args ...interface{})
- func DebugLimit(msg string, in []byte, limit int)
- func IsBangPath(buf []byte) bool
- func IsElf(buf []byte) bool
- func IsExe(buf []byte) bool
- func IsExecutable(buf []byte, runtime string) bool
- func IsGz(buf []byte) bool
- func IsMach64(buf []byte) bool
- func IsZip(buf []byte) bool
- func UnTar(src []byte, dest string) error
- func Unzip(src []byte, dest string) error
- func UnzipOrSaveJar(src []byte, dest string, jarFile string) error
- func Zip(dir string) ([]byte, error)
- type ActionAck
- type ActionProxy
- func (ap *ActionProxy) CompileAction(main string, srcDir string, binDir string) error
- func (ap *ActionProxy) ExtractAction(buf *[]byte, suffix string) (string, error)
- func (ap *ActionProxy) ExtractAndCompile(buf *[]byte, main string) (string, error)
- func (ap *ActionProxy) ExtractAndCompileIO(r io.Reader, w io.Writer, main string, env string)
- func (ap *ActionProxy) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (ap *ActionProxy) SetEnv(env map[string]interface{})
- func (ap *ActionProxy) Start(port int)
- func (ap *ActionProxy) StartLatestAction() error
- type ErrResponse
- type Executor
Examples ¶
- Package (BadZip)
- Package (Badcompile)
- Package (Badinit_nocompiler)
- Package (Bininit_nocompiler)
- Package (Cli_compiler)
- Package (CompileError)
- Package (Compile_bin)
- Package (Compile_simple)
- Package (Compile_src)
- Package (Compile_withMain)
- Package (Compile_withZipSrc)
- Package (ExecutionEnv_check)
- Package (ExecutionEnv_nocheck)
- Package (Filetype)
- Package (Hello)
- Package (Jar)
- Package (Json_init)
- Package (Main_nocompiler)
- Package (Main_zipinit_nocompiler)
- Package (Package)
- Package (Parse_env)
- Package (Shell_nocompiler)
- Package (StartTestServer)
- Package (Venv)
- Package (WithMain)
- Package (Zip)
- Package (Zip_init)
- Package (Zipinit_nocompiler)
- NewExecutor (Ack)
- NewExecutor (Badack)
- NewExecutor (Badack2)
- NewExecutor (Bc)
- NewExecutor (Env)
- NewExecutor (Failed)
- NewExecutor (Hello)
- NewExecutor (Helloack)
Constants ¶
const OutputGuard = "XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX\n"
OutputGuard constant string
Variables ¶
var Debugging = false
Debugging flag
var DefaultTimeoutStart = 5 * time.Millisecond
DefaultTimeoutStart to wait for a process to start
var Version = "1.17.1"
Version number - internal
Functions ¶
func DebugLimit ¶
DebugLimit emits a debug message with a limit in length
func IsExecutable ¶
IsExecutable check if it is an executable, according the current runtime
func UnzipOrSaveJar ¶
UnzipOrSaveJar checks if is is a jar file looking if there is a META-INF folder in it if it is a jar file, save it as the file jarFile Otherwise unzip the files in the destination dir
Types ¶
type ActionAck ¶
type ActionAck struct {
Ok bool `json:"ok"`
}
ActionAck is the expected data structure for the action acknowledgement
type ActionProxy ¶
type ActionProxy struct {
// contains filtered or unexported fields
}
ActionProxy is the container of the data specific to a server
func NewActionProxy ¶
func NewActionProxy(baseDir string, compiler string, outFile *os.File, errFile *os.File) *ActionProxy
NewActionProxy creates a new action proxy that can handle http requests
func (*ActionProxy) CompileAction ¶
func (ap *ActionProxy) CompileAction(main string, srcDir string, binDir string) error
CompileAction will compile an anction in source format invoking a compiler
func (*ActionProxy) ExtractAction ¶
func (ap *ActionProxy) ExtractAction(buf *[]byte, suffix string) (string, error)
ExtractAction accept a byte array and write it to a file it handles zip files extracting the content it stores in a new directory under ./action/XXX/suffix where x is incremented every time it returns the file if a file or the directory if it was a zip file
func (*ActionProxy) ExtractAndCompile ¶
func (ap *ActionProxy) ExtractAndCompile(buf *[]byte, main string) (string, error)
ExtractAndCompile decode the buffer and if a compiler is defined, compile it also
func (*ActionProxy) ExtractAndCompileIO ¶
ExtractAndCompileIO read in input and write in output to use the runtime as a compiler "on-the-fly"
func (*ActionProxy) ServeHTTP ¶
func (ap *ActionProxy) ServeHTTP(w http.ResponseWriter, r *http.Request)
func (*ActionProxy) SetEnv ¶
func (ap *ActionProxy) SetEnv(env map[string]interface{})
SetEnv sets the environment
func (*ActionProxy) Start ¶
func (ap *ActionProxy) Start(port int)
Start creates a proxy to execute actions
func (*ActionProxy) StartLatestAction ¶
func (ap *ActionProxy) StartLatestAction() error
StartLatestAction tries to start the more recently uploaded action if valid, otherwise remove it and fallback to the previous, if any
type ErrResponse ¶
type ErrResponse struct {
Error string `json:"error"`
}
ErrResponse is the response when there are errors
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor is the container and the guardian of a child process It starts a command, feeds input and output, read logs and control its termination
func NewExecutor ¶
func NewExecutor(logout *os.File, logerr *os.File, command string, env map[string]string, args ...string) (proc *Executor)
NewExecutor creates a child subprocess using the provided command line, writing the logs in the given file. You can then start it getting a communication channel
Example (Ack) ¶
log, _ := ioutil.TempFile("", "log") proc := NewExecutor(log, log, "_test/hi", m) err := proc.Start(true) fmt.Println(err) proc.Stop() dump(log)
Output: Command exited abruptly during initialization. hi
Example (Badack) ¶
log, _ := ioutil.TempFile("", "log") proc := NewExecutor(log, log, "_test/badack.sh", m) err := proc.Start(true) fmt.Println(err) proc.Stop() dump(log)
Output: invalid character 'b' looking for beginning of value
Example (Badack2) ¶
log, _ := ioutil.TempFile("", "log") proc := NewExecutor(log, log, "_test/badack2.sh", m) err := proc.Start(true) fmt.Println(err) proc.Stop() dump(log)
Output: The action did not initialize properly.
Example (Bc) ¶
log, _ := ioutil.TempFile("", "log") proc := NewExecutor(log, log, "_test/bc.sh", m) err := proc.Start(false) fmt.Println(err) res, _ := proc.Interact([]byte("2+2")) fmt.Printf("%s", res) proc.Stop() dump(log)
Output: <nil> 4 XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
Example (Env) ¶
log, _ := ioutil.TempFile("", "log") proc := NewExecutor(log, log, "_test/env.sh", map[string]string{"TEST_HELLO": "WORLD", "TEST_HI": "ALL"}) err := proc.Start(false) fmt.Println(err) res, _ := proc.Interact([]byte(`{"value":{"name":"Mike"}}`)) fmt.Printf("%s", res) proc.Stop() dump(log)
Output: <nil> { "env": "TEST_HELLO=WORLD TEST_HI=ALL"} XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
Example (Failed) ¶
log, _ := ioutil.TempFile("", "log") proc := NewExecutor(log, log, "true", m) err := proc.Start(false) fmt.Println(err) proc.Stop() proc = NewExecutor(log, log, "/bin/pwd", m) err = proc.Start(false) fmt.Println(err) proc.Stop() proc = NewExecutor(log, log, "donotexist", m) err = proc.Start(false) fmt.Println(err) proc.Stop() proc = NewExecutor(log, log, "/etc/passwd", m) err = proc.Start(false) fmt.Println(err) proc.Stop()
Output: command exited command exited command exited command exited
Example (Hello) ¶
log, _ := ioutil.TempFile("", "log") proc := NewExecutor(log, log, "_test/hello.sh", m) err := proc.Start(false) fmt.Println(err) res, _ := proc.Interact([]byte(`{"value":{"name":"Mike"}}`)) fmt.Printf("%s", res) proc.Stop() dump(log)
Output: <nil> {"hello": "Mike"} msg=hello Mike XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
Example (Helloack) ¶
log, _ := ioutil.TempFile("", "log") proc := NewExecutor(log, log, "_test/helloack/exec", m) err := proc.Start(true) fmt.Println(err) res, _ := proc.Interact([]byte(`{"value":{"name":"Mike"}}`)) fmt.Printf("%s", res) proc.Stop() dump(log)
Output: <nil> {"hello": "Mike"} msg=hello Mike XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX