Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions internal/datasources/rest/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
uritemplate "github.com/std-uritemplate/std-uritemplate/go/v2"
"google.golang.org/protobuf/types/known/structpb"

"github.com/mindersec/minder/internal/engine/eval/rego"
"github.com/mindersec/minder/internal/util"
"github.com/mindersec/minder/internal/util/schemaupdate"
"github.com/mindersec/minder/internal/util/schemavalidate"
Expand All @@ -36,6 +37,8 @@ type restHandler struct {
inputSchema *jsonschema.Schema
endpointTmpl string
method string
// used only to allow requests to localhost during tests
testOnlyTransport http.RoundTripper
// contains the request body or the key
body string
bodyFromInput bool
Expand Down Expand Up @@ -109,10 +112,16 @@ func (h *restHandler) Call(ctx context.Context, _ *interfaces.Result, args any)
return nil, err
}

transport := h.testOnlyTransport
if transport == nil {
transport = rego.LimitedDialer(nil)
}
// TODO: Add option to use custom client
cli := &http.Client{
// TODO: Make timeout configurable
Timeout: 5 * time.Second,
// Don't allow calling non-public addresses.
Transport: transport,
}

b, err := h.getBody(argsMap)
Expand Down
11 changes: 6 additions & 5 deletions internal/datasources/rest/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,12 @@ func Test_restHandler_Call(t *testing.T) {
tt.fields.endpointTmpl = server.URL + tt.fields.endpointTmpl

h := &restHandler{
endpointTmpl: tt.fields.endpointTmpl,
method: tt.fields.method,
body: tt.fields.body,
headers: tt.fields.headers,
parse: tt.fields.parse,
endpointTmpl: tt.fields.endpointTmpl,
method: tt.fields.method,
body: tt.fields.body,
headers: tt.fields.headers,
parse: tt.fields.parse,
testOnlyTransport: http.DefaultTransport,
}
got, err := h.Call(context.Background(), nil, tt.args.args)
if tt.wantErr {
Expand Down