-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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 a new command to set a predefined runner register token and also add a set-token parameter for registration-token API #32878
Changes from all commits
cc18967
1f453af
aeb6603
5833266
a2f23db
4a1d263
43d616d
dcad326
d31fe7c
9993388
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ var ( | |
Usage: "Manage Gitea Actions", | ||
Subcommands: []*cli.Command{ | ||
subcmdActionsGenRunnerToken, | ||
subcmdActionsSetRunnerToken, | ||
}, | ||
} | ||
|
||
|
@@ -36,6 +37,27 @@ var ( | |
}, | ||
}, | ||
} | ||
|
||
subcmdActionsSetRunnerToken = &cli.Command{ | ||
Name: "set-runner-token", | ||
Usage: "Set a new token for a runner to as register token", | ||
Action: runSetActionsRunnerToken, | ||
Aliases: []string{"srt"}, | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "scope", | ||
Aliases: []string{"s"}, | ||
Value: "", | ||
Usage: "{owner}[/{repo}] - leave empty for a global runner", | ||
}, | ||
&cli.StringFlag{ | ||
Name: "token", | ||
Aliases: []string{"t"}, | ||
Value: "", | ||
Usage: "[{token}] - leave empty will generate a new token, otherwise will update the token to database. The token MUST be a 40 digital string containing only [0-9a-zA-Z]", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without a tool, it is difficult for end users to generate it. The whole design should be like this:
Do not introduce more technical debts There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is my previous solution. I created a new subcommand now because you said There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That's not your previous solution. At least I can see huge difference. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The differences:
|
||
}, | ||
}, | ||
} | ||
) | ||
|
||
func runGenerateActionsRunnerToken(c *cli.Context) error { | ||
|
@@ -53,3 +75,20 @@ func runGenerateActionsRunnerToken(c *cli.Context) error { | |
_, _ = fmt.Printf("%s\n", respText.Text) | ||
return nil | ||
} | ||
|
||
func runSetActionsRunnerToken(c *cli.Context) error { | ||
ctx, cancel := installSignals() | ||
defer cancel() | ||
|
||
setting.MustInstalled() | ||
|
||
scope := c.String("scope") | ||
token := c.String("token") | ||
|
||
respText, extra := private.SetActionsRunnerToken(ctx, scope, token) | ||
if extra.HasError() { | ||
return handleCliResponseExtra(extra) | ||
} | ||
_, _ = fmt.Printf("%s\n", respText.Text) | ||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,6 +182,11 @@ func (Action) GetRegistrationToken(ctx *context.APIContext) { | |
// description: name of the organization | ||
// type: string | ||
// required: true | ||
// - name: set_token | ||
// in: body | ||
// description: set a runner register token instead of generating one. | ||
// type: string | ||
// required: false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's really strange that a GET request accepts "set_token" parameter. And it is anti-pattern to make the GET request updates the target.
Does GitHub do so? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The previous API is |
||
// responses: | ||
// "200": | ||
// "$ref": "#/responses/RegistrationToken" | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
But isn't "Set a new token" simply "adding a 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.
Because once the new token is added, all old tokens will be invalided. Only one token will be valid. So that I use
set
rather thanadd
.