-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow clients to provide decision_id #1465
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1124,6 +1124,7 @@ func (s *Server) v1DataPost(w http.ResponseWriter, r *http.Request) { | |
includeInstrumentation := getBoolParam(r.URL, types.ParamInstrumentV1, true) | ||
partial := getBoolParam(r.URL, types.ParamPartialV1, true) | ||
provenance := getBoolParam(r.URL, types.ParamProvenanceV1, true) | ||
decisionID = getStringParam(r.URL, types.ParamDecisionIdV1, decisionID) | ||
|
||
m.Timer(metrics.RegoQueryParse).Start() | ||
|
||
|
@@ -2083,6 +2084,22 @@ func validateParsedQuery(body ast.Body) ([]string, error) { | |
return unsafeOperators, nil | ||
} | ||
|
||
func getStringParam(url *url.URL, name string, ifEmpty string) string { | ||
|
||
p, ok := url.Query()[name] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] It's not a deep change, but we could use if p := url.Query().Get(name); p != "" {
return p
}
return ifEmpty It doesn't do much, so it also doesn't matter if we use it or not, I suppose 😉 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! It make the code a bit cleaner :) |
||
if !ok { | ||
return ifEmpty | ||
} | ||
|
||
// Query params w/o values are represented as slice (of len 1) with an | ||
// empty string. | ||
if len(p) == 1 && p[0] == "" { | ||
return ifEmpty | ||
} | ||
|
||
return p[0] | ||
} | ||
|
||
func getBoolParam(url *url.URL, name string, ifEmpty bool) bool { | ||
|
||
p, ok := url.Query()[name] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe reword this to:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed