Skip to content
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
aae8c2d
working wasm implementation
Sreedeep-rougeloop Oct 17, 2023
7a60260
fixing the promise
Sreedeep-rougeloop Oct 17, 2023
0afffff
got the result back to web from wasm
Sreedeep-rougeloop Oct 17, 2023
8d61989
promise return working
Sreedeep-rougeloop Oct 26, 2023
2d1e752
bug fix
Sreedeep-rougeloop Nov 9, 2023
888cb6a
widget basic working design
Sreedeep-rougeloop Nov 9, 2023
67787e2
removing goja dependancy
Sreedeep-rougeloop Nov 11, 2023
17b350b
removing goja dependancy
Sreedeep-rougeloop Nov 20, 2023
5470ef5
removing zerolog completely
Sreedeep-rougeloop Nov 26, 2023
4bc3708
Removed net http dependancy
Sreedeep-rougeloop Nov 26, 2023
1894b80
proxy chenges
Sreedeep-rougeloop Feb 14, 2024
4a40c6d
addings an common wokspace
Sreedeep-rougeloop Apr 16, 2024
19d3e4c
Fixed proxy url
RijulTP May 8, 2024
8d25a15
removing some useles code
Sreedeep-rougeloop May 11, 2024
2f68122
Different files for wasm and cli build
Sreedeep-rougeloop May 18, 2024
4e20d80
Removing comments conveting to wasm build files
Sreedeep-rougeloop May 23, 2024
6df60ba
Add cleaning the commnets
Sreedeep-rougeloop May 23, 2024
ef7305e
cleaning code
Sreedeep-rougeloop May 23, 2024
5e645f0
removing zerolog comments
Sreedeep-rougeloop May 23, 2024
9886c29
fixing workflow
Sreedeep-rougeloop May 23, 2024
703c800
fixing workflow
Sreedeep-rougeloop May 23, 2024
61cb447
Removing zerolog
Sreedeep-rougeloop May 24, 2024
4754562
removing comments and unused code
Sreedeep-rougeloop May 25, 2024
6a97e0b
Removing unused dependeny
Sreedeep-rougeloop May 25, 2024
8eadb84
removing duplication
Sreedeep-rougeloop May 25, 2024
7eb34be
Fixed duplication in controller, lama2cmd and outputmanager
RijulTP May 25, 2024
a48a9cf
intermediate commit
Sreedeep-rougeloop May 25, 2024
66236db
Merge branch 'Wasm' of github.com:HexmosTech/Lama2 into Wasm
Sreedeep-rougeloop May 25, 2024
f77c1c5
adressing the code repetetion issues
Sreedeep-rougeloop May 27, 2024
5c87003
fixing code repetetion
Sreedeep-rougeloop Jun 6, 2024
e0f3fdf
fixed cli build
Sreedeep-rougeloop Jun 8, 2024
69f0dce
Fixed the testcases failing issues
Sreedeep-rougeloop Jun 11, 2024
8a14d44
handling usename in env
Sreedeep-rougeloop Jun 12, 2024
6b09d77
Removing code duplication
Sreedeep-rougeloop Jun 12, 2024
8996428
removing reduntant deps
Sreedeep-rougeloop Jun 12, 2024
b2a0856
updated the httpie-go version to latest
Sreedeep-rougeloop Jun 13, 2024
b6e9594
fixing yams addind tag for test
Sreedeep-rougeloop Jun 13, 2024
b797654
fixing output parsing issues
Sreedeep-rougeloop Jun 15, 2024
2cd120c
removing unused imports
Sreedeep-rougeloop Jun 15, 2024
8cd876f
Removing reduntant code
Sreedeep-rougeloop Jun 15, 2024
8619733
fixed some code duplccation remaining
Sreedeep-rougeloop Jun 15, 2024
22bb77e
fixing major code duplications in expandvar and preprocess
Sreedeep-rougeloop Jun 15, 2024
5fb6459
removing preprocess.wasm
Sreedeep-rougeloop Jun 15, 2024
a7364fc
fixing small errr in expandvar
Sreedeep-rougeloop Jun 16, 2024
e0eee8b
fixed the null point issue with VM
Sreedeep-rougeloop Jun 17, 2024
18ff371
removed unused imports
Sreedeep-rougeloop Jun 17, 2024
c915394
adding old error message back
Sreedeep-rougeloop Jun 21, 2024
fbf3f64
Added 2 more tests \n 1.Wrong file format error check \n 2. Multipart…
Sreedeep-rougeloop Jun 21, 2024
c49c7f0
implementing wasm code converter
Sreedeep-rougeloop Jun 25, 2024
f441a82
removing some unused files
Sreedeep-rougeloop Jul 2, 2024
b4457e6
code converter for multipart
Sreedeep-rougeloop Jul 15, 2024
3af3893
added a return promise for code converter
Sreedeep-rougeloop Jul 26, 2024
b702455
converted vm type to interface
Sreedeep-rougeloop Aug 2, 2024
0a8782f
fixed cli build
Sreedeep-rougeloop Aug 2, 2024
ae09eed
Fixed wasm build
RijulTP Aug 2, 2024
568a2ec
Merge branch 'Wasm' of github.com:HexmosTech/Lama2 into Wasm
RijulTP Aug 2, 2024
65449ae
Converter expandvar to webworkers
RijulTP Aug 3, 2024
e6ec4bc
Removing goja dependency for wasm
RijulTP Aug 3, 2024
a84f7e3
Adding webworkers
RijulTP Aug 4, 2024
a7e344e
fixing the datastructure build issue
Sreedeep-rougeloop Aug 4, 2024
6d04379
Merge branch 'Wasm' of github.com:HexmosTech/Lama2 into Wasm
Sreedeep-rougeloop Aug 4, 2024
02a12fa
fixed play button
Sreedeep-rougeloop Aug 4, 2024
f8f95f5
fixed code convertion using browser js interpreter
Sreedeep-rougeloop Aug 6, 2024
782c193
Fixing deadlock issue
RijulTP Aug 6, 2024
e99b903
Fixed sync issue in expand var webworkers
RijulTP Aug 7, 2024
9673ba3
Fixed result variable issue in chain request
RijulTP Aug 7, 2024
3c0ae3f
Renamed webworker file
RijulTP Aug 8, 2024
98953f7
Fixed cli build issue
RijulTP Aug 8, 2024
7ab6474
Added seperator
Sreedeep-rougeloop Aug 8, 2024
30e22e3
Merge branch 'Wasm' of github.com:HexmosTech/Lama2 into Wasm
Sreedeep-rougeloop Aug 8, 2024
bf4e836
Removed unwanted code
RijulTP Aug 8, 2024
f7d6312
Issue: Heap overflow
Sreedeep-rougeloop Aug 8, 2024
dcc4bd4
Merge branch 'Wasm' of github.com:HexmosTech/Lama2 into Wasm
Sreedeep-rougeloop Aug 8, 2024
4a22fad
added inlining to silence heap failing
Sreedeep-rougeloop Aug 9, 2024
df60536
Removed httpsnippet log
RijulTP Aug 10, 2024
69693ce
Fixed build issues
RijulTP Aug 10, 2024
704ce78
Embedded workerjs file
RijulTP Aug 10, 2024
e54872d
Added correction to pyhon and js single stage code convert
Sreedeep-rougeloop Aug 10, 2024
5dd3417
Added support for php
Sreedeep-rougeloop Aug 11, 2024
4a79319
Updated httpsnippet
RijulTP Aug 11, 2024
fffc451
Updated httpiego
RijulTP Aug 11, 2024
e741821
Added new httpe vesion
Sreedeep-rougeloop Aug 11, 2024
c457908
pulled changes
RijulTP Aug 11, 2024
3e92c17
fixing merge conflicts
Sreedeep-rougeloop Sep 1, 2024
8a1625d
Merge remote-tracking branch 'origin/main' into Wasm
Sreedeep-rougeloop Sep 1, 2024
4ebde26
fixing the mkdocs build
Sreedeep-rougeloop Sep 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/testapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ jobs:
- name: Install dependencies
run: go mod tidy
- name: Build
run: go build -v ./...
run: go build -tags=cli -v ./...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this done only for ones with tag cli, are there any other tags

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes there is wasm tag also currently build is failing , checking that now

- name: Test with the Go CLI
run: |
go mod tidy
go build -o build/l2 -ldflags "-X main.version=`git tag --sort=-version:refname | head -n 1`" l2.go
go test -v ./tests/
go build -tags=cli -o build/l2 -ldflags "-X main.version=`git tag --sort=-version:refname | head -n 1`" l2.go
go test -tags=cli -v ./tests/
- name: Deploy hexmos doc
run: curl -X POST --fail -F token=${{ secrets.TRIGGER_TOKEN }} -F ref=main https://git.apps.hexmos.com/api/v4/projects/85/trigger/pipeline
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
build/
lama2
.vscode
buildAndPublish.sh
static/
.env
5 changes: 2 additions & 3 deletions cmdexec/cmdexec.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build cli

// Package `cmdexec` provides a facility to execute
// l2 commands, stream output to stdout, while also
// providing ability to retrieve the command output as
Expand All @@ -11,7 +13,6 @@ import (

"github.com/HexmosTech/httpie-go"
"github.com/HexmosTech/lama2/utils"
"github.com/rs/zerolog/log"
)

// ExecCommand changes directory to the given `apiDir`
Expand All @@ -25,10 +26,8 @@ func ExecCommand(cmdSlice []string, stdinBody string, apiDir string) (httpie.ExR
utils.ChangeWorkingDir(apiDir)
resp, err := httpie.Lama2Entry(cmdSlice, strings.NewReader(stdinBody))
if err != nil {
log.Fatal().Str("Error from the API executor", err.Error()).Msg("")
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)
return resp, nil
}
36 changes: 36 additions & 0 deletions cmdexec/cmdexec.wasm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//go:build wasm

// Package `cmdexec` provides a facility to execute
// l2 commands, stream output to stdout, while also
// providing ability to retrieve the command output as
// a string.
package cmdexec

import (
"errors"
"fmt"
"os"

"strings"

"github.com/HexmosTech/httpie-go"
)

// ExecCommand changes directory to the given `apiDir`
// and then executes the command specified in `cmdStr`
// During command execution, ExecCommand streams output
// to stdout.
// Once execution finishes, previous CWD is restored,
// and the command output is returned as a string
func ExecCommand(cmdSlice []string, stdinBody string, apiDir string) (httpie.ExResponse, error) {
proxyURL := os.Getenv("PROXY_URL")
proxyUserName := os.Getenv("PROXY_USERNAME")
proxyUserPassword := os.Getenv("PROXY_PASSWORD")
allowRedirects := true
resp, err := httpie.Lama2Entry(cmdSlice, strings.NewReader(stdinBody), proxyURL, proxyUserName, proxyUserPassword, allowRedirects)
if err != nil {
fmt.Println("Got error while executing", err)
return httpie.ExResponse{}, errors.New("Error from API executor: " + err.Error())
}
return resp, nil
}
5 changes: 5 additions & 0 deletions cmdexec/js.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build cli

package cmdexec

import (
Expand All @@ -24,6 +26,9 @@ func GetJSVm() *goja.Runtime {
// you reuse the vm for other operations, the state
// from previous invocations carry over
func RunVMCode(jsCode string, vm *goja.Runtime) {
if vm == nil {
vm = GetJSVm()
}
_, err := vm.RunString(jsCode)
if ex, ok := err.(*goja.Exception); ok {
log.Fatal().Str("Error executing JS processor block", ex.String()).Msg("")
Expand Down
28 changes: 28 additions & 0 deletions cmdexec/js.wasm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//go:build wasm

package cmdexec

import (
"syscall/js"

"github.com/dop251/goja"
)

func RunVMCode(jsCode string, vm *goja.Runtime) {
js.Global().Call("eval", jsCode)
}

// The GenerateChainCode function creates a JavaScript code snippet
// that attempts to parse a given HTTP response body as JSON, logging
// success or failure, and stores the result accordingly.
func GenerateChainCode(httpRespBody string) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a comment on what this function is doing? what is generate chain code?

code := `try {
result = JSON.parse(String.raw` + "`" + httpRespBody + "`" + `)
console.log("Stored as JSON")
} catch (e) {
result = String.raw` + "`" + httpRespBody + "`" + `
console.log(e)
console.log("Stored as string")
}`
return code
}
14 changes: 14 additions & 0 deletions cmdgen/cmdgen.cli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//go:build cli

package cmdgen

import (
"github.com/HexmosTech/gabs/v2"
"github.com/HexmosTech/lama2/lama2cmd"
)

func ConstructCommand(parsedInput *gabs.Container, o *lama2cmd.Opts) ([]string, string) {
httpv, url, jsonObj, headers, multipartBool, formBool := ConstructCommandHelper(parsedInput)
res, stdinBody := assembleCmdString(httpv, url, jsonObj, headers, multipartBool, formBool, o)
return res, stdinBody
}
39 changes: 12 additions & 27 deletions cmdgen/cmdgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,27 @@ import (

"github.com/HexmosTech/gabs/v2"
"github.com/HexmosTech/lama2/lama2cmd"
"github.com/rs/zerolog/log"
)

// The assembleCmdString function constructs a httpie
// command string for an HTTP request based on the provided
// HTTP method, URL, JSON object, headers, and options. It also
// handle multipart and form data.
func assembleCmdString(httpv string, url string, jsonObj *gabs.Container, headers *gabs.Container, multipart bool, form bool, o *lama2cmd.Opts) ([]string, string) {
command := make([]string, 0)
log.Info().
Str("Type", "Construct Command").
Str("httpv", httpv).
Str("url", url).
Bool("multipart", multipart).
Bool("form", form).
Msg(fmt.Sprint("Construct parameters"))

log.Debug().
Str("JSONObj", jsonObj.String()).
Str("Headers", headers.String()).Msg("")

var files *gabs.Container
if multipart {
if jsonObj.ExistsP("@files") {
files = jsonObj.S("@files")
log.Debug().Str("Files", files.String()).Msg("")
jsonObj.Delete("@files")
log.Trace().Str("Shortened JsonObj", jsonObj.String()).Msg("")
}
}

jsonStr := ""
if jsonObj != nil && !multipart && !form {
dst := &bytes.Buffer{}
if err := json.Compact(dst, []byte(jsonObj.String())); err != nil {
log.Fatal().
Str("Error", err.Error()).
Msg("Couldn't minify JSON")
fmt.Println(err)
}
jsonStr = dst.String()
}
Expand All @@ -58,7 +45,7 @@ func assembleCmdString(httpv string, url string, jsonObj *gabs.Container, header
}*/

command = append(command, "ht ")
if o.Nocolor {
if o != nil && o.Nocolor {
command = append(command, "--pretty=none ")
}
if multipart || form {
Expand All @@ -70,7 +57,8 @@ func assembleCmdString(httpv string, url string, jsonObj *gabs.Container, header

if multipart {
for key, val := range jsonObj.Data().(*gabs.Container).ChildrenMap() {
command = append(command, "'"+key+"'='"+val.Data().(string)+"' ")
keyValuePair := fmt.Sprintf("%s=%s", key, val.Data().(string))
command = append(command, keyValuePair)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these changes tested?

}
for key, val := range files.ChildrenMap() {
command = append(command, key+"@"+val.Data().(string))
Expand All @@ -79,7 +67,7 @@ func assembleCmdString(httpv string, url string, jsonObj *gabs.Container, header

if form {
for key, val := range jsonObj.Data().(*gabs.Container).ChildrenMap() {
keyValuePair := fmt.Sprintf("'%s'='%s' ", key, val.Data().(string))
keyValuePair := fmt.Sprintf("%s=%s", key, val.Data().(string))
command = append(command, keyValuePair)
}
}
Expand All @@ -104,20 +92,17 @@ func assembleCmdString(httpv string, url string, jsonObj *gabs.Container, header
// API file inputs, figures out the type of target command
// and finally generates a string representing the generated
// command
func ConstructCommand(parsedInput *gabs.Container, o *lama2cmd.Opts) ([]string, string) {
log.Info().Str("ParsedInput", parsedInput.String()).Msg("")
func ConstructCommandHelper(parsedInput *gabs.Container) (string, string, *gabs.Container, *gabs.Container, bool, bool) {
httpv := parsedInput.S("verb", "value")
url := parsedInput.S("url", "value")
jsonObj := parsedInput.S("details", "ip_data")
headers := parsedInput.S("details", "headers")
multipart := parsedInput.S("multipart", "value")
form := parsedInput.S("form", "value")
multipartBool := false
if multipart != nil {
multipartBool = true
}
form := parsedInput.S("form", "value")
formBool := form != nil

res, stdinBody := assembleCmdString(httpv.Data().(string), url.Data().(string), jsonObj, headers, multipartBool, formBool, o)
return res, stdinBody
return httpv.Data().(string), url.Data().(string), jsonObj, headers, multipartBool, formBool
}
14 changes: 14 additions & 0 deletions cmdgen/cmdgen.wasm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//go:build wasm

package cmdgen

import (
"github.com/HexmosTech/gabs/v2"
"github.com/HexmosTech/lama2/lama2cmd"
)

func ConstructCommand(parsedInput *gabs.Container, o *lama2cmd.Opts) ([]string, string) {
httpv, url, jsonObj, headers, multipartBool, formBool := ConstructCommandHelper(parsedInput)
res, stdinBody := assembleCmdString(httpv, url, jsonObj, headers, multipartBool, formBool, nil)
return res, stdinBody
}
94 changes: 94 additions & 0 deletions controller/controller.cli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
//go:build cli

// Package controller coordinates all the other
// components in the `Lama2` project. The high
// level overview of command execution is easily
// understood from this package
package contoller

import (
"fmt"
"os"

"github.com/HexmosTech/gabs/v2"
"github.com/HexmosTech/httpie-go"
"github.com/HexmosTech/lama2/cmdexec"
"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/dop251/goja"
"github.com/rs/zerolog/log"
)

func ExecuteProcessorBlock(block *gabs.Container, vm *goja.Runtime) httpie.ExResponse {
return ExecuteProcessorBlockHelper(block, vm)
}

// func ExecuteRequestorBlock(block *gabs.Container, vm *goja.Runtime, opts *lama2cmd.Opts, dir string) httpie.ExResponse {
// return ExecuteRequestorBlockHelper(block, vm, opts, dir)
// }

func HandleParsedFile(parsedAPI *gabs.Container, o *lama2cmd.Opts, dir string) (httpie.ExResponse, *lama2cmd.Opts) {
vm := cmdexec.GetJSVm()
return HandleParsedFileHelper(parsedAPI, o, dir, vm)
}

// 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
}

if e != nil {
log.Fatal().
Str("Type", "Controller").
Str("LamaFile", o.Positional.LamaAPIFile).
Str("Error", e.Error()).
Msg("Parse Error")
}
log.Debug().Str("Parsed API", parsedAPI.String()).Msg("")
res, out := HandleParsedFile(parsedAPI, o, dir)
if out.Output != "" {
outputmanager.WriteJSONOutput(res, out.Output)
}
}

func ExecuteRequestorBlockHelper(resp httpie.ExResponse, headersString string, e1 error, vm *goja.Runtime) httpie.ExResponse {
if e1 == nil {
chainCode := cmdexec.GenerateChainCode(resp.Body)
cmdexec.RunVMCode(chainCode, vm)
} else {
fmt.Printf("Error from ExecCommand", e1)
os.Exit(1)
}
return resp
}
Loading