Skip to content

Commit fb8cf62

Browse files
authored
Merge pull request #51 from HexmosTech/wasmauth
Added auth support for wasm
2 parents 31de19e + 1668fdd commit fb8cf62

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

cmdgen/cmdgen.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,6 @@ func assembleCmdString(httpv string, url string, jsonObj *gabs.Container, header
3838
jsonStr = dst.String()
3939
}
4040

41-
/*
42-
if !multipart && jsonStr != "" {
43-
command = append(command, "echo '")
44-
command = append(command, jsonStr)
45-
command = append(command, "' |")
46-
}*/
47-
4841
command = append(command, "ht ")
4942
if o != nil && o.Nocolor {
5043
command = append(command, "--pretty=none ")
@@ -78,6 +71,7 @@ func assembleCmdString(httpv string, url string, jsonObj *gabs.Container, header
7871
command = append(command, key+":"+val.Data().(*gabs.Container).Data().(string))
7972
}
8073
}
74+
8175
cleanCommand := make([]string, 0)
8276
for _, c := range command {
8377
cleanC := strings.TrimSpace(c)

cmdgen/cmdgen.wasm.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,24 @@ package cmdgen
55
import (
66
"github.com/HexmosTech/gabs/v2"
77
"github.com/HexmosTech/lama2/lama2cmd"
8+
"syscall/js"
89
)
910

1011
func ConstructCommand(parsedInput *gabs.Container, o *lama2cmd.Opts) ([]string, string) {
1112
httpv, url, jsonObj, headers, multipartBool, formBool := ConstructCommandHelper(parsedInput)
1213
res, stdinBody := assembleCmdString(httpv, url, jsonObj, headers, multipartBool, formBool, nil)
14+
15+
LaBearerAuthToken := js.Global().Get("LaBearerAuthToken").String()
16+
authHeaderExists := false
17+
for _, header := range res {
18+
if len(header) >= len("Authorization:") && header[:len("Authorization:")] == "Authorization:" {
19+
authHeaderExists = true
20+
break
21+
}
22+
}
23+
24+
if !authHeaderExists {
25+
res = append(res, "Authorization: Bearer "+LaBearerAuthToken)
26+
}
1327
return res, stdinBody
1428
}

l2.wasm.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ func main() {
3030

3131
func wasmLamaPromise() js.Func {
3232
return js.FuncOf(func(this js.Value, args []js.Value) interface{} {
33+
laBearerAuthToken := args[2].String()
34+
js.Global().Set("LaBearerAuthToken", laBearerAuthToken)
3335
inputdata := args[0].String()
3436
handler := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
3537
resolve := args[0]

0 commit comments

Comments
 (0)