Skip to content

Commit

Permalink
add jsvm to lint schema and update otto vendor
Browse files Browse the repository at this point in the history
  • Loading branch information
joshblakeley committed Nov 21, 2018
1 parent 7076e32 commit a689f7d
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 27 deletions.
3 changes: 3 additions & 0 deletions cli/lint/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ const confSchema = `{
"enable_jsvm": {
"type": "boolean"
},
"jsvm":{
"type": "string"
},
"jsvm_timeout": {
"type": "integer"
},
Expand Down
12 changes: 5 additions & 7 deletions jsvm_goja.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import (
"time"

"github.com/Sirupsen/logrus"
"github.com/dop251/goja"

"github.com/TykTechnologies/tyk/apidef"
"github.com/TykTechnologies/tyk/config"
"github.com/TykTechnologies/tyk/user"
"github.com/dop251/goja"
)

type TykJSVM interface {
Expand Down Expand Up @@ -154,7 +155,6 @@ func (j *GojaJSVM) RunJSRequestDynamic(d *DynamicMiddleware, logger *logrus.Entr

func (j *GojaJSVM) RunJSRequestVirtual(d *VirtualEndpoint, logger *logrus.Entry, vmeta *apidef.VirtualMeta, requestAsJson string, sessionAsJson string, specAsJson string) (error, int, string) {

interrupt := make(chan func(), 1)
d.Logger().Debug("Running: ", vmeta.ResponseFunctionName)
// buffered, leaving no chance of a goroutine leak since the
// spawned goroutine will send 0 or 1 values.
Expand All @@ -180,14 +180,12 @@ func (j *GojaJSVM) RunJSRequestVirtual(d *VirtualEndpoint, logger *logrus.Entry,
return nil, -1, ""
}
t.Stop()

case <-t.C:
t.Stop()
d.Logger().Error("JS middleware timed out after ", j.GetTimeout())
interrupt <- func() {
// only way to stop the VM is to send it a func
// that panics.
panic("stop")
}

j.VM.Interrupt("Stopping VM for timeout")
return nil, -1, ""
}
returnDataStr := returnRaw.String()
Expand Down
5 changes: 3 additions & 2 deletions jsvm_otto.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import (
"strings"
"time"

"github.com/robertkrimen/otto"
_ "github.com/robertkrimen/otto/underscore"

"github.com/TykTechnologies/tyk/apidef"
"github.com/TykTechnologies/tyk/config"
"github.com/TykTechnologies/tyk/user"
"github.com/robertkrimen/otto"
_ "github.com/robertkrimen/otto/underscore"

"github.com/Sirupsen/logrus"
)
Expand Down
3 changes: 2 additions & 1 deletion mw_js_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ func (d *DynamicMiddleware) ProcessRequest(w http.ResponseWriter, r *http.Reques
err, code, returnDataStr := d.Spec.JSVM.RunJSRequestDynamic(d, logger, string(requestAsJson), string(sessionAsJson), specAsJson)
if err != nil {
log.Errorf("JSVM error: %v", err)
return err, code
}

if code != -1 {
if code != -1 || returnDataStr == "" {
return nil, code
}
// Decode the return object
Expand Down
5 changes: 2 additions & 3 deletions mw_virtual_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -172,8 +171,8 @@ func (d *VirtualEndpoint) ServeHTTPForCache(w http.ResponseWriter, r *http.Reque
// Run the middleware
err, code, returnDataStr := d.Spec.JSVM.RunJSRequestVirtual(d, d.logger, vmeta, string(requestAsJson), string(sessionAsJson), specAsJson)
if err != nil {
//TODO
fmt.Println(err)
log.Errorf("JSVM VE error: %v", err)
return nil
}
if code != -1 {
return nil
Expand Down
2 changes: 1 addition & 1 deletion vendor/github.com/robertkrimen/otto/README.markdown

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion vendor/github.com/robertkrimen/otto/builtin_array.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/robertkrimen/otto/error.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions vendor/github.com/robertkrimen/otto/inline.pl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

94 changes: 93 additions & 1 deletion vendor/github.com/robertkrimen/otto/runtime.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a689f7d

Please sign in to comment.