Skip to content
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

Merged
merged 3 commits into from
Dec 23, 2016
Merged

Conversation

redixin
Copy link

@redixin redixin commented Dec 5, 2016

No description provided.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 96.438% when pulling ed4470f on add-security-raml-and-fake-impl into 89c8e43 on master.


security = flask.Blueprint("security", __name__)

if base_fake.USE_FAKE_DATA:
Copy link
Contributor

@maretskiy maretskiy Dec 6, 2016

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:

@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

Copy link
Contributor

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)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@redixin redixin force-pushed the add-security-raml-and-fake-impl branch from ed4470f to 9505907 Compare December 7, 2016 19:49
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.7%) to 94.5% when pulling 9505907 on add-security-raml-and-fake-impl into a9c7499 on master.

@redixin redixin force-pushed the add-security-raml-and-fake-impl branch from 9505907 to d99f6dd Compare December 8, 2016 13:55
@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 95.455% when pulling d99f6dd on add-security-raml-and-fake-impl into a9c7499 on master.

@redixin redixin force-pushed the add-security-raml-and-fake-impl branch from d99f6dd to fd94c67 Compare December 9, 2016 13:30
@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 95.455% when pulling fd94c67 on add-security-raml-and-fake-impl into a9c7499 on master.

@@ -55,6 +55,18 @@ mediaType: application/json
schema: !include schemas/404.json
example: !include response_examples/404/region.json

/security/issues/{period}:
Copy link
Contributor

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@redixin redixin force-pushed the add-security-raml-and-fake-impl branch from fd94c67 to d938a4f Compare December 12, 2016 12:47
@coveralls
Copy link

Coverage Status

Coverage increased (+1.6%) to 96.86% when pulling d938a4f on add-security-raml-and-fake-impl into b81830c on master.

@redixin redixin force-pushed the add-security-raml-and-fake-impl branch from d938a4f to 0eee879 Compare December 13, 2016 14:14
@coveralls
Copy link

Coverage Status

Coverage increased (+1.3%) to 96.618% when pulling 0eee879 on add-security-raml-and-fake-impl into b81830c on master.

@redixin redixin force-pushed the add-security-raml-and-fake-impl branch from 0eee879 to 101d0eb Compare December 13, 2016 14:29
@coveralls
Copy link

Coverage Status

Coverage increased (+1.3%) to 96.618% when pulling 101d0eb on add-security-raml-and-fake-impl into b81830c on master.

@redixin redixin force-pushed the add-security-raml-and-fake-impl branch from 101d0eb to 1b59d5e Compare December 13, 2016 20:17
@coveralls
Copy link

Coverage Status

Coverage increased (+1.3%) to 96.618% when pulling 1b59d5e on add-security-raml-and-fake-impl into b81830c on master.

@redixin redixin force-pushed the add-security-raml-and-fake-impl branch from 1b59d5e to 745e92c Compare December 13, 2016 20:38
@coveralls
Copy link

Coverage Status

Coverage increased (+1.6%) to 96.852% when pulling 745e92c on add-security-raml-and-fake-impl into b81830c on master.

Copy link
Collaborator

@teferi teferi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@redixin redixin force-pushed the add-security-raml-and-fake-impl branch from 745e92c to 3896521 Compare December 16, 2016 12:49
@coveralls
Copy link

Coverage Status

Coverage increased (+1.3%) to 96.61% when pulling 3896521 on add-security-raml-and-fake-impl into b81830c on master.

@redixin redixin force-pushed the add-security-raml-and-fake-impl branch from 3896521 to 7a50ebe Compare December 16, 2016 13:02
@coveralls
Copy link

Coverage Status

Coverage increased (+1.3%) to 96.61% when pulling 7a50ebe on add-security-raml-and-fake-impl into b81830c on master.

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_")
Copy link
Contributor

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

Copy link
Author

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
Copy link
Contributor

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"

Copy link
Author

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

Copy link
Contributor

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

Copy link
Collaborator

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")
Copy link
Contributor

@maretskiy maretskiy Dec 16, 2016

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) ?

Copy link
Author

@redixin redixin Dec 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

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):
Copy link
Contributor

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

Copy link
Author

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
Copy link
Contributor

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"} ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@redixin redixin force-pushed the add-security-raml-and-fake-impl branch from 7a50ebe to a555c81 Compare December 19, 2016 12:35
@coveralls
Copy link

Coverage Status

Coverage increased (+0.9%) to 96.163% when pulling a555c81 on add-security-raml-and-fake-impl into b81830c on master.

@redixin redixin force-pushed the add-security-raml-and-fake-impl branch from a555c81 to e56aa92 Compare December 19, 2016 20:00
@coveralls
Copy link

Coverage Status

Coverage increased (+0.6%) to 95.923% when pulling e56aa92 on add-security-raml-and-fake-impl into b81830c on master.

@redixin redixin force-pushed the add-security-raml-and-fake-impl branch from e56aa92 to 1312504 Compare December 19, 2016 20:49
@coveralls
Copy link

Coverage Status

Coverage increased (+0.9%) to 96.163% when pulling 1312504 on add-security-raml-and-fake-impl into b81830c on master.

@@ -14,15 +14,20 @@
# under the License.

import flask
from flask import request # noqa
Copy link
Collaborator

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
Copy link
Collaborator

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

Copy link
Author

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

@redixin redixin force-pushed the add-security-raml-and-fake-impl branch from 1312504 to 14cfb7a Compare December 20, 2016 15:05
@redixin redixin force-pushed the add-security-raml-and-fake-impl branch from 14cfb7a to f707005 Compare December 20, 2016 16:10
@coveralls
Copy link

Coverage Status

Coverage increased (+0.6%) to 95.913% when pulling f707005 on add-security-raml-and-fake-impl into b81830c on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.6%) to 95.913% when pulling 867b56d on add-security-raml-and-fake-impl into e0ba62c on master.

@maretskiy maretskiy merged commit d563eb4 into master Dec 23, 2016
@boris-42 boris-42 deleted the add-security-raml-and-fake-impl branch December 28, 2016 02:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants