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

first commit #2

Merged
merged 13 commits into from
Apr 20, 2020
Merged

first commit #2

merged 13 commits into from
Apr 20, 2020

Conversation

odra
Copy link
Contributor

@odra odra commented Mar 31, 2020

  • first or which uses the bravado library
  • instructions on usage in the readme file

Sample usage:

c = Client.from_url('http://myspecurl.com', base_url='http://fasjson.example.test/fasjson' principal='admin@EXAMPLE.TEST')

output = c.api.v1.whoami().response().result

print(output)

I couldn't find an easy way to handle API call errors so I think we will have to stick with the bravado exceptions for now.

@odra odra requested a review from abompard March 31, 2020 17:01
@odra
Copy link
Contributor Author

odra commented Mar 31, 2020

I am taking a look on how to generate api docs using sphinx but the code should be in good shape for review.

Copy link
Member

@abompard abompard left a comment

Choose a reason for hiding this comment

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

Thanks! I have a few comments if we're going this route.

Also, please add a tox.ini file that checks the unit tests, black, flake8, bandit, licenses and code coverage.

README.md Outdated
```
c = Client.from_url('http://myspecurl.com', base_url='http://fasjson.example.test/fasjson' principal='admin@EXAMPLE.TEST')

output = c.api.v1.whoami().response().result
Copy link
Member

Choose a reason for hiding this comment

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

Could we propose something more direct? Like c.whoami(), ideally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is just uses whatever is in the url path, so /v1/whoami becomes v1.whoami(), to use whoami()directly we need to remove v1 path from the url.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe not removing from the server, but only hide it in the client? It feels like our users shouldn't have to know what boils down to an implementation detail. Same thing for the .response().result part. I'm all ears if you have a different opinion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I meant this is auto generated by bravado, the /v1/whoami thing is read from the api spec... I could do some method naming fu using "_getarr" to retrieve/call methods within the v1 object.. but it doesn't feel right, I don't jhave a problem with "v1", we could remove it from the spec since we only have a version of the api now.

About response().result that bravado again because response() returns a future so you can handle async code if you want to... I could try to use the getattr method here again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

github messed up with my comment, I wanted to write __ getattr __ :P

Copy link
Contributor Author

Choose a reason for hiding this comment

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

an alternative would be to have different specs per api version and add the /v1 part in the basePath field.

## Usage

```
c = Client.from_url('http://myspecurl.com', base_url='http://fasjson.example.test/fasjson' principal='admin@EXAMPLE.TEST')
Copy link
Member

Choose a reason for hiding this comment

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

I think we should have the API server serve the spec at some known endpoint, and have the client automatically pull it from there. End users shouldn't have to know where we publish the spec file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right, this is is just a dummy readme file for now, we could host the spec definition in the root endpoint (/v1)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we could have a default value that could be changed if needed but the value itself needs to be changed once we add this feature in the api

Install dependencies:

```
pip install -U -r requirements.txt
Copy link
Member

Choose a reason for hiding this comment

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

A real python package would be better. Could you wite a setup.py file or a pyproject.toml file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, I just sent it like this for an early feedback, "development" here stand for people who want to contribute to the repository.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can you send me offline (irc, email etc) what values should I use for author name, email, etc.

Copy link
Member

Choose a reason for hiding this comment

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

You can have a look at noggin and / or fasjson if you need inspiration, that's what I would do ;-)

Copy link
Member

Choose a reason for hiding this comment

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

Any news on that item?

README.md Outdated
Running tests:

```
pytest -s
Copy link
Member

Choose a reason for hiding this comment

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

Do we need the -s flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I always used "-s" so pytest won't hide any output from the tests (such as data sent to stdout), I can remove it

README.md Outdated

## License

Licensed under [GPLv3](./LICENSE)
Copy link
Member

Choose a reason for hiding this comment

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

We may want to consider LGPL, as it's a library.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, I just used what we used in fasjson

return super(HttpClient, self).authenticated_request(request_params)


class Client(object):
Copy link
Member

Choose a reason for hiding this comment

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

In python3 you don't need to derive from object.

}
raise errors.ClientError('error loading remote spec data', errno.ECONNABORTED, data=data)

if res.status_code != 200:
Copy link
Member

Choose a reason for hiding this comment

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

You can check the res.ok attribute, it'll cover all the 2xx range.

self.data = data

def __repr__(self):
return f'<{self.__class__.__name__} code={[self.code]} message={self.message} data={self.data}>'
Copy link
Member

Choose a reason for hiding this comment

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

Do you want the code to appear as a list? If the brackets are only for decoration then I think they should be outside the curly braces.

Copy link
Contributor Author

@odra odra Mar 31, 2020

Choose a reason for hiding this comment

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

ah not really, it was a mistake of mine, I will remove it


class ClientError(BaseError):
def __init__(self, message, code, data=None):
super(ClientError, self).__init__(message, code, data=data)
Copy link
Member

Choose a reason for hiding this comment

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

Same here, in Python 3 only super() is required.

requirements.txt Outdated
@@ -0,0 +1,38 @@
attrs==19.3.0
Copy link
Member

Choose a reason for hiding this comment

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

Please only list the dependencies that are directly required, and don't mandate the versions unless it's actually necessary. Otherwise it makes it impossible to integrate in an application that uses the system python.

@odra odra force-pushed the poc3 branch 3 times, most recently from c91806d to 5feb612 Compare April 1, 2020 13:41
@pypingou
Copy link
Member

pypingou commented Apr 1, 2020

The commit messages may need some work, the first commit mentions testing files but changes the LICENSE file for example.

setup.py Outdated
here = os.path.abspath(os.path.dirname(__file__))


def content(path, cwd=None):
Copy link
Member

Choose a reason for hiding this comment

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

Why is the cwd argument sometimes necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was having issues in reading the README file vs the requirements one, it was not able to read the readme file withtout the current working dir var.

Copy link
Member

Choose a reason for hiding this comment

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

OK but why not always use here when building the paths, then? This way youd have one less parameter and you'll know all paths are in the same directory as this file (I like removing things ;-) )

tox.ini Outdated
commands =
rm -rf htmlcov coverage.xml
py.test -vv --cov-config .coveragerc --cov=fasjson_client \
--cov-report term --cov-report xml --cov-report html test/
Copy link
Member

Choose a reason for hiding this comment

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

You can add {posargs} at the end so we can add flags at runtime

setup.py Outdated
],
license="LGPLv3",
install_requires=content('requirements.txt').split('\n'),
tests_requires=content('test_requirements.txt').split('\n'),
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure this works, with the empty lines and the comments in that file? I think they should be filtered out by the content function.

fasjson_client/client.py Outdated Show resolved Hide resolved
raise errors.ClientError("schema validation failed", errno.EPROTO)

@classmethod
def from_url(cls, spec_url, base_url=None, principal=None):
Copy link
Member

Choose a reason for hiding this comment

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

Let's go like this for now, but eventually I'd prefer the spec URL to be deducted from the base URL (maybe a /spec endpoint? Or a header? Is there a standard for that?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

spec_url is where bravado loads the spec from including the base url whcih is documented in the api spec file, base_url is here in case a user wants do overwrite the value used within the spec.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we can have a default value for the spec url but I think we need to push fasjson somewhere first?

Copy link
Member

Choose a reason for hiding this comment

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

If we decide that fasjson publishes the spec at /spec for example (again, if there's a standard location for that, let's use it), then we can just provide a base URL and the client will know where to find the spec.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I created an issue to provide it in the root version path, such as /v1, so I think we can update it once we have it hosted somewhere/defined a production baseurl.

Copy link
Member

Choose a reason for hiding this comment

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

Has it been merged yet? If not could you link to the issue here so we can track it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I created an issue but didn't worked on it - it needs to implement some kind of "white list" which enables us to choose which path should not be authenticated against ldap.

We could set the url from oour git repository while for now if that's ok.

Copy link
Member

Choose a reason for hiding this comment

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

OK, let's go that way for now.

.coveragerc Outdated


[report]
fail_under = 88
Copy link
Member

Choose a reason for hiding this comment

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

Let's start with that but not wait too long to go to 100%, it's harder to do it after the fact.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just used an existing tox.ini file from another fedora-infra repository, that's what was being used there.

Copy link
Member

Choose a reason for hiding this comment

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

OK, could you set it to 100% then? Thanks

tox.ini Outdated
envlist = py36,py37,diff-cover,lint,format

[testenv]
passenv = TRAVIS TRAVIS_*
Copy link
Member

Choose a reason for hiding this comment

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

Are you setting up Travis?

@abompard abompard added this to Ready for review in AAA via automation Apr 7, 2020
Copy link
Member

@abompard abompard left a comment

Choose a reason for hiding this comment

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

I still have a few comments, thanks.

.coveragerc Outdated


[report]
fail_under = 88
Copy link
Member

Choose a reason for hiding this comment

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

OK, could you set it to 100% then? Thanks

Install dependencies:

```
pip install -U -r requirements.txt
Copy link
Member

Choose a reason for hiding this comment

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

Any news on that item?

from requests_gssapi import HTTPSPNEGOAuth
from bravado import requests_client
from bravado.client import SwaggerClient
import gssapi
Copy link
Member

Choose a reason for hiding this comment

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

That comment is still valid I think.

fasjson_client/client.py Outdated Show resolved Hide resolved
raise errors.ClientError("schema validation failed", errno.EPROTO)

@classmethod
def from_url(cls, spec_url, base_url=None, principal=None):
Copy link
Member

Choose a reason for hiding this comment

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

Has it been merged yet? If not could you link to the issue here so we can track it?

setup.py Outdated
here = os.path.abspath(os.path.dirname(__file__))


def content(path, cwd=None):
Copy link
Member

Choose a reason for hiding this comment

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

OK but why not always use here when building the paths, then? This way youd have one less parameter and you'll know all paths are in the same directory as this file (I like removing things ;-) )

test/conftest.py Outdated

@pytest.fixture
def fixture_dir(test_dir):
return f"{test_dir}/fixtures"
Copy link
Member

Choose a reason for hiding this comment

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

Ideally we would join paths with os.path.join() instead of hardcoding slashes (except for URLs of course), but I agree it does not make much of a difference since we're never going to run it on Windows ;-)

requests
requests-mock

# required by vcs looks like
Copy link
Member

Choose a reason for hiding this comment

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

do you mean vcr?

odra and others added 7 commits April 16, 2020 08:53
Signed-off-by: Aurélien Bompard <aurelien@bompard.org>
Signed-off-by: Aurélien Bompard <aurelien@bompard.org>
Signed-off-by: Aurélien Bompard <aurelien@bompard.org>
@abompard abompard merged commit fa67891 into fedora-infra:master Apr 20, 2020
AAA automation moved this from Ready for review to Done within Sprint Apr 20, 2020
@abompard
Copy link
Member

Merging now so others can start working on it.

@abompard
Copy link
Member

This is related to fedora-infra/fasjson#8.

@abompard abompard removed this from Done within Sprint in AAA Apr 21, 2020
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

3 participants