-
Notifications
You must be signed in to change notification settings - Fork 15
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
Add API for token management #2
Conversation
""" | ||
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). |
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 must auth
be UsernamePassword
? self.authenticated_user(..)
and self._get(..)
should be able to handle any authentication type.
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.
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.
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). |
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.
Ditto, why?
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.
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. |
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 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.
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.
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): |
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 need to be a separate class? Can we just add a name
property to the existing Token
class?
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.
Merged.
@@ -242,14 +243,14 @@ def pull(self): | |||
return self._pull | |||
|
|||
|
|||
class TokenInfo(object): | |||
class TokenInfo(Token): |
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.
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.
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.
:param str username: username of owner of new token | ||
|
||
:return: token authenticator | ||
:rtype: Token |
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.
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.
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.
As far as I understand your auth.Token should not be bound to json parsing.
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 don't see what's wrong with giving auth.Token
a from_json(..)
method.
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.
@ethantkoenig, am I right that all questions are answered and all requests fulfilled? |
@pyhedgehog I would still like to combine |
@ethantkoenig, Merged. |
@pyhedgehog LGTM. Rebase down to a single commit, and I'll merge. Thanks for the contribution! |
ea139fe
to
65e82cf
Compare
@ethantkoenig, Done. |
gogs_client.entries.TokenInfo
.gogs_client.interface.get_tokens()
- returns list of TokenInfo.gogs_client.interface.create_token()
- returns new TokenInfo.gogs_client.interface.ensure_token()
- returns new or old auth.Token.