-
Notifications
You must be signed in to change notification settings - Fork 1
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 security api and fake client #44
Conversation
|
||
security = flask.Blueprint("security", __name__) | ||
|
||
if base_fake.USE_FAKE_DATA: |
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.
This is yet another approach of Fake API implementation, there is another one already via decorator, example:
ceagle/ceagle/api/v1/status.py
Line 27 in 89c8e43
@fake_status.get_status |
It is very doubtful that having two approaches is good choice, only one should be in use
region: | ||
type: string | ||
description: filter by region | ||
|
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.
It would be very helpful to add a reference to response example (like at L29-34)
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.
+1
ed4470f
to
9505907
Compare
9505907
to
d99f6dd
Compare
d99f6dd
to
fd94c67
Compare
@@ -55,6 +55,18 @@ mediaType: application/json | |||
schema: !include schemas/404.json | |||
example: !include response_examples/404/region.json | |||
|
|||
/security/issues/{period}: |
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.
Will you introduce /security/stats/{period} API endpoint in this pull request? Or this will be doe separately?
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.
Done
fd94c67
to
d938a4f
Compare
d938a4f
to
0eee879
Compare
0eee879
to
101d0eb
Compare
101d0eb
to
1b59d5e
Compare
1b59d5e
to
745e92c
Compare
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.
lgtm
745e92c
to
3896521
Compare
3896521
to
7a50ebe
Compare
if config.get_config().get("use_fake_api_data", True): | ||
fake_client_class = FAKE_CLIENT_MAP.get(service_name) | ||
if fake_client_class: | ||
return fake_client_class(name=service_name, endpoint="_fake_") |
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.
So this will return a fake client even if service_name is absent in config? Thi slooks like ignoring config options. I think both real & fake client should be returned only if service appears in config - this is checked at L74-76
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.
Done
@@ -14,15 +14,20 @@ | |||
# under the License. | |||
|
|||
import flask | |||
from flask import request # noqa |
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.
Why? flask.request is not a module! Use flask.request instead, without "# noqa"
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.
Travis is failing on this line. Looks like a bug in some versions of flake8
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.
pep8 must fail on this line since `request' is not a module
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.
+1 you seem to never use request, so it's safe to just delete the line
|
||
security = flask.Blueprint("security", __name__) | ||
|
||
client = client.get_client("security") |
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.
So if security service is missed in config file, this module will raise UnknownService at import-time (will not be imported at all, so main.py will failed to start) ?
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.
Done
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.
Does this mean that security service is mandatory?
} | ||
|
||
|
||
class Client(object): |
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.
If inherited from ceagle.api.client.Client, there will be only one method get() overriden, but __ init __ and __ repr __ will work as usually
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.
Done, but I had to move Client in separate module because of circular imports.
if issue["discovered_at"] >= discovered_before: | ||
issues.append(issue) | ||
else: | ||
return "Region not found", 404 |
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.
Is this ok to return str message instead of {"error": "Region not found"} ?
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.
Done
7a50ebe
to
a555c81
Compare
a555c81
to
e56aa92
Compare
e56aa92
to
1312504
Compare
@@ -14,15 +14,20 @@ | |||
# under the License. | |||
|
|||
import flask | |||
from flask import request # noqa |
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.
+1 you seem to never use request, so it's safe to just delete the line
@@ -44,6 +45,11 @@ def not_found(error): | |||
return flask.jsonify({"error": "Not Found"}), 404 | |||
|
|||
|
|||
@app.errorhandler(client.UnknownService) | |||
def handle_unknown_service(ex): | |||
return flask.jsonify({"error": str(ex)}), 400 |
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 thing 404 is a bit more appropriate. It basically means all health/security/availability/whatever is not configured and all respective urls are unavailable. While 400 is usually viewed as some sort of problem with request itself https://httpstatuses.com/400
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.
404 is "resource not found" but resource is found but misconfigured. This looks more like 500
1312504
to
14cfb7a
Compare
14cfb7a
to
f707005
Compare
No description provided.