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
Add warn when input attributes is missing #4416
Conversation
Hello @anderseknert, does the approach look ok to you? If yes, I can work on adding/fixing tests. |
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.
Thanks! Left a comment on the URL as I think we might want to skip that. Looks like several tests need to be updated to work with this addition though, and perhaps you'd want to add a test or two on your own, unless this is already well covered by those that are there already (I think that might be the case).
server/types/types.go
Outdated
const CodeAPIUsageWarn = "api_usage_warning" | ||
|
||
// Warning Messages | ||
const MsgInputKeyMissing = "'input' key missing: see https://www.openpolicyagent.org/docs/latest/#4-try-opa-run-server for more details" |
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.
I think we can skip the URL in the message. It will be very easy to forget about this later, making this a 404 if we update the docs.
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.
Thanks for the feedback @anderseknert, will remove the url and fix tests.
server/server.go
Outdated
@@ -1415,6 +1415,10 @@ func (s *Server) v1DataGet(w http.ResponseWriter, r *http.Request) { | |||
DecisionID: decisionID, | |||
} | |||
|
|||
if input == nil { |
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.
I think this validates if the 'input' http query parameter is present in the request, the validation should be after JSON unmarshall is completed and validate if it has an 'input' field.
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.
That's a good point, Christian! The tests should help shine some light on this :)
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.
Warning if the POST v1/data endpoint is called w/o providing input
makes sense, but I'd rather not see that warning show up in GET v1/data.
thank you @tsandall @anderseknert, pushed the changes based on the feedback. |
@@ -1463,6 +1533,16 @@ p = true { false }` | |||
] | |||
}`}, | |||
}}, | |||
{"post api usage warning", []tr{ |
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.
added tests for warning but I can remove them if they look redundant
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.
Nice! Thanks 👍
@@ -1463,6 +1533,16 @@ p = true { false }` | |||
] | |||
}`}, | |||
}}, | |||
{"post api usage warning", []tr{ |
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.
Nice! Thanks 👍
b620952
to
c2be58a
Compare
This change adds an api_usage_warning when input attribute is missing in the request to /v1/data Fixes: open-policy-agent#4386 Signed-off-by: Alam <afaaqalam@gmail.com> server: remove url from warning msg Signed-off-by: Alam <afaaqalam@gmail.com> server: remove warning for GET requests to v1/data; fix tests Signed-off-by: Alam <afaaqalam@gmail.com>
rebased and squashed all the commits, ready to be merged. |
Thanks for your contribution, Alam! This will be helpful to many 👍 |
Fixes: #4386