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 API for token management #2

Merged
merged 1 commit into from
Dec 24, 2016

Conversation

pyhedgehog
Copy link
Contributor

  • New class gogs_client.entries.TokenInfo.
  • New method gogs_client.interface.get_tokens() - returns list of TokenInfo.
  • New method gogs_client.interface.create_token() - returns new TokenInfo.
  • New method gogs_client.interface.ensure_token() - returns new or old auth.Token.

@coveralls
Copy link

coveralls commented Dec 22, 2016

Coverage Status

Coverage increased (+0.4%) to 92.857% when pulling 74faf4d on pyhedgehog:feature/token into 8ca42a1 on unfoldingWord-dev:master.

"""
Returns tokens defined for specified user.
If no user specified uses user authenticated by the given authentication.
Right now, authentication must be UsernamePassword (not Token).
Copy link
Contributor

Choose a reason for hiding this comment

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

Why must auth be UsernamePassword? self.authenticated_user(..) and self._get(..) should be able to handle any authentication type.

Copy link
Contributor Author

@pyhedgehog pyhedgehog Dec 22, 2016

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, 👍

"""
Creates new token if token with specified name for specified user does not exists.
If no user specified uses user authenticated by the given authentication.
Right now, authentication must be UsernamePassword (not Token).
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto, why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Authentication must be UsernamePassword is server requirement.



class GogsApi(object):
"""
A Gogs client, serving as a wrapper around the Gogs HTTP API.
A Gogs API entries, serving as a wrapper around the Gogs HTTP API.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this need to change? API entries is a little misleading, since there isn't a one-to-one correspondence between these functions and the Gogs API endpoints.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because this is not consistent client with preset access configuration and persistent session (keep-alive and so on). This is collection of unrelated API wrappers.
Sorry. I've reverted this accidental change.

@@ -240,3 +240,46 @@ def pull(self):
:rtype: bool
"""
return self._pull


class TokenInfo(object):
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 need to be a separate class? Can we just add a name property to the existing Token class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Merged.

@coveralls
Copy link

coveralls commented Dec 22, 2016

Coverage Status

Coverage increased (+0.4%) to 92.771% when pulling 74075fb on pyhedgehog:feature/token into 8ca42a1 on unfoldingWord-dev:master.

@coveralls
Copy link

coveralls commented Dec 22, 2016

Coverage Status

Coverage increased (+0.4%) to 92.771% when pulling 68c76e9 on pyhedgehog:feature/token into 8ca42a1 on unfoldingWord-dev:master.

@@ -242,14 +243,14 @@ def pull(self):
return self._pull


class TokenInfo(object):
class TokenInfo(Token):
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we just add a new property (name) to the existing Token class, instead of introducing a new subclass? I think it would be best to keep the class hierarchies simple, and don't see a pressing need for a subclass here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

:param str username: username of owner of new token

:return: token authenticator
:rtype: Token
Copy link
Contributor

Choose a reason for hiding this comment

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

As things currently stand, shouldn't this be TokenInfo? For instance, this method could return self.create_token(..), which is of type TokenInfo.

I still would suggest scraping the TokenInfo class altogether (see other comment), but want to make sure I'm not missing something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I understand your auth.Token should not be bound to json parsing.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see what's wrong with giving auth.Token a from_json(..) method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@coveralls
Copy link

coveralls commented Dec 23, 2016

Coverage Status

Coverage increased (+0.4%) to 92.793% when pulling 930246e on pyhedgehog:feature/token into 8ca42a1 on unfoldingWord-dev:master.

@pyhedgehog
Copy link
Contributor Author

@ethantkoenig, am I right that all questions are answered and all requests fulfilled?

@ethantkoenig
Copy link
Contributor

@pyhedgehog I would still like to combine Token and TokenInfo. Repeating my earlier comment, I don't see what's wrong with giving auth.Token a from_json(..) method (which you cited as a reason for not combining them).

@coveralls
Copy link

coveralls commented Dec 24, 2016

Coverage Status

Coverage increased (+0.3%) to 92.749% when pulling ea139fe on pyhedgehog:feature/token into 8ca42a1 on unfoldingWord-dev:master.

@pyhedgehog
Copy link
Contributor Author

@ethantkoenig, Merged.

@ethantkoenig
Copy link
Contributor

@pyhedgehog LGTM. Rebase down to a single commit, and I'll merge. Thanks for the contribution!

@coveralls
Copy link

coveralls commented Dec 24, 2016

Coverage Status

Coverage increased (+0.3%) to 92.749% when pulling 65e82cf on pyhedgehog:feature/token into da455d1 on unfoldingWord-dev:master.

@pyhedgehog
Copy link
Contributor Author

@ethantkoenig, Done.

@ethantkoenig ethantkoenig merged commit 8fa5efb into unfoldingWord-dev:master Dec 24, 2016
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.

3 participants