-
Notifications
You must be signed in to change notification settings - Fork 64
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 scope support to access tokens #185
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Marco Slaviero <marco@thinkst.com>
can anyone merge this |
} | ||
|
||
// CreateToken creates a Personal Access Token and returns the token field only once | ||
func (c *Client) CreateToken(description string) (*Token, error) { | ||
data, err := json.Marshal(hubTokenRequest{Description: description}) | ||
func (c *Client) CreateToken(description string, scope string) (*Token, error) { |
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.
nit:
func (c *Client) CreateToken(description string, scope string) (*Token, error) { | |
func (c *Client) CreateToken(description, scope string) (*Token, error) { |
scopes := []string{scope} | ||
scopes[0] = "repo:" + scope | ||
tokenRequest.Scopes = scopes |
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.
Am I missing something? Why can’t it be
scopes := []string{scope} | |
scopes[0] = "repo:" + scope | |
tokenRequest.Scopes = scopes | |
tokenRequest.Scopes = []string{"repo:" + scope} |
?
if len(t.Scopes) == 0 { | ||
return "", 0 | ||
} | ||
return t.Scopes[0][5:], len(t.Scopes[0]) - 5 |
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 guess 5
is because it’s the length of "repo:"
, could we factor out the string and use len()
?
"admin", | ||
"write", | ||
"read", | ||
"public_read": |
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 would extract these into a []string
and use it with strings.Join
to build the description for the flag l.78
Is there new update here? Or code review required? |
- What I did
Add support for token scopes. Access Tokens created in the web interface can take a single scope value but this isn't available in
hub-tool
. This change lets the user create tokens with a specific scope.- How I did it
Two user-facing changes:
--scope
parameter totoken create
.token ls
- How to verify it
The following calls add tokens with the specified scopes:
Showing the added column in
token ls
:- Description for the changelog
Add scope support to access tokens
- A picture of a cute animal (not mandatory)