From 4e20d80287781a86ae902c5f8b3838995ebfea50 Mon Sep 17 00:00:00 2001 From: Sreedeep CV Date: Thu, 23 May 2024 18:41:43 +0530 Subject: [PATCH] Removing comments conveting to wasm build files --- cmdexec/cmdexec.wasm.go | 13 ------- cmdexec/js.wasm.go | 3 -- cmdgen/cmdgen.wasm.go | 2 -- codegen/codegen.wasm.go | 25 ++----------- controller/controller.wasm.go | 67 ----------------------------------- l2.wasm.go | 2 -- 6 files changed, 3 insertions(+), 109 deletions(-) diff --git a/cmdexec/cmdexec.wasm.go b/cmdexec/cmdexec.wasm.go index 3f7e0395..751bc803 100644 --- a/cmdexec/cmdexec.wasm.go +++ b/cmdexec/cmdexec.wasm.go @@ -10,13 +10,9 @@ import ( "errors" "fmt" - // "os" "strings" "github.com/HexmosTech/httpie-go" - // "github.com/HexmosTech/lama2/utils" - // "github.com/rs/zerolog/log" - // "github.com/HexmosTech/httpie-go" ) // ExecCommand changes directory to the given `apiDir` @@ -26,23 +22,14 @@ import ( // Once execution finishes, previous CWD is restored, // and the command output is returned as a string func ExecCommand(cmdSlice []string, stdinBody string) (httpie.ExResponse, error) { - fmt.Println("Inside cmd exec code") - fmt.Println("Inside cmd exec code httpie Integer", httpie.Int(24601)) proxyURL := "https://proxyserver.hexmos.com/" proxyUserName := "proxyServer" proxyUserPassword := "proxy22523146server" allowRedirects := true resp, err := httpie.Lama2Entry(cmdSlice, strings.NewReader(stdinBody), proxyURL, proxyUserName, proxyUserPassword, allowRedirects) - // resp, err := httpie.Lama2Entry(cmdSlice, strings.NewReader(stdinBody), "", "", "", false) - fmt.Println("error:", err) - fmt.Println("Data Response:", resp) if err != nil { - // log.Fatal().Str("Error from the API executor", err.Error()).Msg("") fmt.Println("Got error while executing", err) return httpie.ExResponse{}, errors.New("Error from API executor: " + err.Error()) } - // log.Debug().Str("Response body from API executor", resp.Body).Msg("") - // utils.ChangeWorkingDir(oldDir) - // fmt.Println("Reponse fro httpie", resp) return resp, nil } diff --git a/cmdexec/js.wasm.go b/cmdexec/js.wasm.go index a582a8cd..3d1e6ad7 100644 --- a/cmdexec/js.wasm.go +++ b/cmdexec/js.wasm.go @@ -3,8 +3,6 @@ package cmdexec import ( - // "github.com/rs/zerolog/log" - "fmt" "syscall/js" ) @@ -50,6 +48,5 @@ func GenerateChainCode(httpRespBody string) string { console.log("Stored as string") }` // log.Info().Str("Chain code generated", code).Msg("") - fmt.Println("code:", code) return code } diff --git a/cmdgen/cmdgen.wasm.go b/cmdgen/cmdgen.wasm.go index 11526f0f..75dbe3a4 100644 --- a/cmdgen/cmdgen.wasm.go +++ b/cmdgen/cmdgen.wasm.go @@ -13,8 +13,6 @@ import ( "strings" "github.com/HexmosTech/gabs/v2" - // "github.com/HexmosTech/lama2/lama2cmd" - // "github.com/rs/zerolog/log" ) func assembleCmdString(httpv string, url string, jsonObj *gabs.Container, headers *gabs.Container, multipart bool, form bool) ([]string, string) { diff --git a/codegen/codegen.wasm.go b/codegen/codegen.wasm.go index 9721bca2..e3457386 100644 --- a/codegen/codegen.wasm.go +++ b/codegen/codegen.wasm.go @@ -7,12 +7,10 @@ import ( _ "embed" "fmt" "strings" - "text/template" "syscall/js" - // "github.com/rs/zerolog/log" + "text/template" "github.com/HexmosTech/gabs/v2" - // "github.com/HexmosTech/lama2/cmdexec" "github.com/HexmosTech/lama2/preprocess" ) @@ -136,14 +134,10 @@ func GetRequestHARString(block *gabs.Container) string { } func GenerateTargetCode(targetLangLib string, parsedAPI *gabs.Container) { - // initialize() parsedAPIblocks := parsedAPI.S("value").Data().(*gabs.Container).Children() convertedSnippetList := make([]string, 0) for i, block := range parsedAPIblocks { - // log.Debug().Int("Block num", i).Msg("") - fmt.Println(i) - // log.Debug().Str("Block getting processed", block.String()).Msg("") blockType := block.S("type").Data().(string) if blockType == "processor" { snippet := block.S("value").Data().(*gabs.Container).Data().(string) @@ -157,21 +151,8 @@ func GenerateTargetCode(targetLangLib string, parsedAPI *gabs.Container) { snippetArgs.HARRequest = harRequest snippetArgs.SnippetCore = snippetcore httpsnippetCode := PrepareHTTPSnippetGenerator(snippetArgs) - - // vm := cmdexec.GetJSVm() - // _, e := vm.RunString(httpsnippetCode) - js.Global().Call("eval", httpsnippetCode) - - // if e != nil { - // log.Fatal(). - // Str("Type", "CodeGen"). - // Str("Error", e.Error()). - // Msg("Code generator error") - // } - // Init returns an error if the package is not ready for use. - // convertedSnippet := vm.Get("convertedSnippet").String() - - convertedSnippet := js.Global().Get("convertedSnippet").String() + js.Global().Call("eval", httpsnippetCode) + convertedSnippet := js.Global().Get("convertedSnippet").String() convertedSnippetList = append(convertedSnippetList, convertedSnippet) } } diff --git a/controller/controller.wasm.go b/controller/controller.wasm.go index 7f6ca101..509e3097 100644 --- a/controller/controller.wasm.go +++ b/controller/controller.wasm.go @@ -9,9 +9,6 @@ package contoller import ( "fmt" "os" - - // "os" - "strings" "reflect" @@ -21,16 +18,9 @@ import ( "github.com/HexmosTech/lama2/cmdexec" "github.com/HexmosTech/lama2/cmdgen" - // "github.com/HexmosTech/lama2/codegen" - // "github.com/HexmosTech/lama2/lama2cmd" - - // outputmanager "github.com/HexmosTech/lama2/outputManager" "github.com/HexmosTech/lama2/parser" "github.com/HexmosTech/lama2/preprocess" - // "github.com/HexmosTech/lama2/prettify" - // "github.com/HexmosTech/lama2/utils" - // "github.com/rs/zerolog/log" "syscall/js" ) @@ -40,11 +30,7 @@ func GetParsedAPIBlocks(parsedAPI *gabs.Container) []*gabs.Container { func ExecuteProcessorBlock(block *gabs.Container) { b := block.S("value").Data().(*gabs.Container) - // log.Info().Str("Processor block incoming block", block.String()).Msg("") script := b.Data().(string) - // cmdexec.RunVMCode(script, vm) - fmt.Println("<-----JS CODE----->:", script) - // log.Info().Str("Evaluated through syscall js:", script).Msg("") js.Global().Call("eval", script) } @@ -52,15 +38,9 @@ func ExecuteRequestorBlock(block *gabs.Container) httpie.ExResponse { preprocess.ProcessVarsInBlock(block) // TODO - replace stuff in headers, and varjson and json as well cmd, stdinBody := cmdgen.ConstructCommand(block) - fmt.Println("Reached ExecuteRequestorBlock") resp, e1 := cmdexec.ExecCommand(cmd, stdinBody) - fmt.Println("Command to execute:", cmd) - fmt.Println("Value of e1 lets see:", e1) printFields(resp) - headers := resp.Headers - fmt.Println("Value of Headders:", headers) - var headersString string for key, value := range headers { headersString += fmt.Sprintf("%s: %s\n", key, value) @@ -75,25 +55,13 @@ func ExecuteRequestorBlock(block *gabs.Container) httpie.ExResponse { } else { fmt.Printf("'%s' is not present in the headers.\n", targetHeader) if e1 == nil { - fmt.Println("Chain code evaluator") chainCode := cmdexec.GenerateChainCode(resp.Body) - fmt.Println("chainCode:", chainCode) js.Global().Call("eval", chainCode) } else { - fmt.Println("Exiting ........") os.Exit(1) } } - // if e1 == nil { - // fmt.Println("Chain code evaluator") - // chainCode := cmdexec.GenerateChainCode(resp.Body) - // fmt.Println("chainCode:", chainCode) - // js.Global().Call("eval", chainCode) - // } else { - // fmt.Println("Exiting ........") - // os.Exit(1) - // } return resp } @@ -120,44 +88,9 @@ func HandleParsedFile(parsedAPI *gabs.Container) httpie.ExResponse { resp = ExecuteRequestorBlock(block) } } - // if o.Output != "" { - // outputmanager.WriteJSONOutput(resp, o.Output) - // } return resp } -// Process initiates the following tasks in the given order: -// 1. Parse command line arguments -// 2. Read API file contents -// 3. Expand environment variables in API file -// 4. Parse the API contents -// 5. Generate API request command -// 6. Execute command & retrieve results -// 7. Optionally, post-process and write results to a JSON file -// func Process(version string) { -// o := lama2cmd.GetAndValidateCmd(os.Args) -// lama2cmd.ArgParsing(o, version) - -// apiContent := preprocess.GetLamaFileAsString(o.Positional.LamaAPIFile) -// _, dir, _ := utils.GetFilePathComponents(o.Positional.LamaAPIFile) -// oldDir, _ := os.Getwd() -// utils.ChangeWorkingDir(dir) - -// preprocess.LoadEnvironments(dir) -// utils.ChangeWorkingDir(oldDir) -// p := parser.NewLama2Parser() -// parsedAPI, e := p.Parse(apiContent) -// if o.Convert != "" { -// codegen.GenerateTargetCode(o.Convert, parsedAPI) -// return -// } - -// if o.Prettify { -// prettify.Prettify(parsedAPI, p.Context, p.MarkRange, apiContent, o.Positional.LamaAPIFile) -// return -// } -// HandleParsedFile(parsedAPI) -// } func ProcessWasmInput(data string) httpie.ExResponse { apiContent := data diff --git a/l2.wasm.go b/l2.wasm.go index b1b2cefb..02beb28a 100644 --- a/l2.wasm.go +++ b/l2.wasm.go @@ -41,13 +41,11 @@ func wasmLamaPromise() js.Func { resolve := args[0] go func() { result := controller.ProcessWasmInput(inputdata) - fmt.Println("<-----Result----->:", result) resultJSON, err := json.Marshal(result) if err != nil { fmt.Println("Error:", err) return } - fmt.Println("Result: ", string(resultJSON)) resolve.Invoke(js.ValueOf(string(resultJSON))) }() return nil