mirror of
https://github.com/go-gitea/gitea
synced 2024-12-22 22:17:53 +01:00
Allow setting access token scope by CLI (#22648)
Followup for #20908 to allow setting the scopes when creating new access token via CLI. Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: John Olheiser <john.olheiser@gmail.com>
This commit is contained in:
parent
15c035775a
commit
3f2e721372
15
cmd/admin.go
15
cmd/admin.go
@ -180,6 +180,11 @@ var (
|
|||||||
Name: "raw",
|
Name: "raw",
|
||||||
Usage: "Display only the token value",
|
Usage: "Display only the token value",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "scopes",
|
||||||
|
Value: "",
|
||||||
|
Usage: "Comma separated list of scopes to apply to access token",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: runGenerateAccessToken,
|
Action: runGenerateAccessToken,
|
||||||
}
|
}
|
||||||
@ -698,9 +703,15 @@ func runGenerateAccessToken(c *cli.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
accessTokenScope, err := auth_model.AccessTokenScope(c.String("scopes")).Normalize()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
t := &auth_model.AccessToken{
|
t := &auth_model.AccessToken{
|
||||||
Name: c.String("token-name"),
|
Name: c.String("token-name"),
|
||||||
UID: user.ID,
|
UID: user.ID,
|
||||||
|
Scope: accessTokenScope,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := auth_model.NewAccessToken(t); err != nil {
|
if err := auth_model.NewAccessToken(t); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user