Add option to disable version checking (#520)
Fixes "Only signed in user is allowed to call APIs." as the /api/v1/version returns a 403 when running a gitea where REQUIRE_SIGNIN_VIEW is enabled Co-authored-by: Wim <wim@42.be> Reviewed-on: https://gitea.com/gitea/tea/pulls/520 Reviewed-by: 6543 <6543@obermui.de> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: Wim <42wim@noreply.gitea.io> Co-committed-by: Wim <42wim@noreply.gitea.io>
This commit is contained in:
parent
2a8c1daa67
commit
6a848cb72a
|
@ -30,6 +30,11 @@ var CmdLoginAdd = cli.Command{
|
||||||
EnvVars: []string{"GITEA_SERVER_URL"},
|
EnvVars: []string{"GITEA_SERVER_URL"},
|
||||||
Usage: "Server URL",
|
Usage: "Server URL",
|
||||||
},
|
},
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "no-version-check",
|
||||||
|
Aliases: []string{"nv"},
|
||||||
|
Usage: "Do not check version of Gitea instance",
|
||||||
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "token",
|
Name: "token",
|
||||||
Aliases: []string{"t"},
|
Aliases: []string{"t"},
|
||||||
|
@ -96,5 +101,6 @@ func runLoginAdd(ctx *cli.Context) error {
|
||||||
ctx.String("ssh-agent-principal"),
|
ctx.String("ssh-agent-principal"),
|
||||||
ctx.String("ssh-agent-key"),
|
ctx.String("ssh-agent-key"),
|
||||||
ctx.Bool("insecure"),
|
ctx.Bool("insecure"),
|
||||||
sshAgent)
|
sshAgent,
|
||||||
|
!ctx.Bool("no-version-check"))
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ type Login struct {
|
||||||
SSHAgent bool `yaml:"ssh_agent"`
|
SSHAgent bool `yaml:"ssh_agent"`
|
||||||
SSHKeyFingerprint string `yaml:"ssh_key_agent_pub"`
|
SSHKeyFingerprint string `yaml:"ssh_key_agent_pub"`
|
||||||
SSHPassphrase string `yaml:"-"`
|
SSHPassphrase string `yaml:"-"`
|
||||||
|
VersionCheck bool `yaml:"version_check"`
|
||||||
// User is username from gitea
|
// User is username from gitea
|
||||||
User string `yaml:"user"`
|
User string `yaml:"user"`
|
||||||
// Created is auto created unix timestamp
|
// Created is auto created unix timestamp
|
||||||
|
@ -182,6 +183,11 @@ func (l *Login) Client(options ...gitea.ClientOption) *gitea.Client {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// versioncheck must be prepended in options to make sure we don't hit any version checks in the sdk
|
||||||
|
if !l.VersionCheck {
|
||||||
|
options = append([]gitea.ClientOption{gitea.SetGiteaVersion("")}, options...)
|
||||||
|
}
|
||||||
|
|
||||||
options = append(options, gitea.SetToken(l.Token), gitea.SetHTTPClient(httpClient))
|
options = append(options, gitea.SetToken(l.Token), gitea.SetHTTPClient(httpClient))
|
||||||
|
|
||||||
if ok, err := utils.IsKeyEncrypted(l.SSHKey); ok && err == nil && l.SSHPassphrase == "" {
|
if ok, err := utils.IsKeyEncrypted(l.SSHKey); ok && err == nil && l.SSHPassphrase == "" {
|
||||||
|
|
|
@ -16,9 +16,12 @@ import (
|
||||||
|
|
||||||
// CreateLogin create an login interactive
|
// CreateLogin create an login interactive
|
||||||
func CreateLogin() error {
|
func CreateLogin() error {
|
||||||
var name, token, user, passwd, sshKey, giteaURL, sshCertPrincipal, sshKeyFingerprint string
|
var (
|
||||||
var insecure = false
|
name, token, user, passwd, sshKey, giteaURL, sshCertPrincipal, sshKeyFingerprint string
|
||||||
var sshAgent = false
|
insecure, sshAgent, versionCheck bool
|
||||||
|
)
|
||||||
|
|
||||||
|
versionCheck = true
|
||||||
|
|
||||||
promptI := &survey.Input{Message: "URL of Gitea instance: "}
|
promptI := &survey.Input{Message: "URL of Gitea instance: "}
|
||||||
if err := survey.AskOne(promptI, &giteaURL, survey.WithValidator(survey.Required)); err != nil {
|
if err := survey.AskOne(promptI, &giteaURL, survey.WithValidator(survey.Required)); err != nil {
|
||||||
|
@ -128,7 +131,16 @@ func CreateLogin() error {
|
||||||
if err = survey.AskOne(promptYN, &insecure); err != nil {
|
if err = survey.AskOne(promptYN, &insecure); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
promptYN = &survey.Confirm{
|
||||||
|
Message: "Check version of Gitea instance: ",
|
||||||
|
Default: true,
|
||||||
|
}
|
||||||
|
if err = survey.AskOne(promptYN, &versionCheck); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return task.CreateLogin(name, token, user, passwd, sshKey, giteaURL, sshCertPrincipal, sshKeyFingerprint, insecure, sshAgent)
|
return task.CreateLogin(name, token, user, passwd, sshKey, giteaURL, sshCertPrincipal, sshKeyFingerprint, insecure, sshAgent, versionCheck)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// CreateLogin create a login to be stored in config
|
// CreateLogin create a login to be stored in config
|
||||||
func CreateLogin(name, token, user, passwd, sshKey, giteaURL, sshCertPrincipal, sshKeyFingerprint string, insecure, sshAgent bool) error {
|
func CreateLogin(name, token, user, passwd, sshKey, giteaURL, sshCertPrincipal, sshKeyFingerprint string, insecure, sshAgent, versionCheck bool) error {
|
||||||
// checks ...
|
// checks ...
|
||||||
// ... if we have a url
|
// ... if we have a url
|
||||||
if len(giteaURL) == 0 {
|
if len(giteaURL) == 0 {
|
||||||
|
@ -65,6 +65,7 @@ func CreateLogin(name, token, user, passwd, sshKey, giteaURL, sshCertPrincipal,
|
||||||
SSHKeyFingerprint: sshKeyFingerprint,
|
SSHKeyFingerprint: sshKeyFingerprint,
|
||||||
SSHAgent: sshAgent,
|
SSHAgent: sshAgent,
|
||||||
Created: time.Now().Unix(),
|
Created: time.Now().Unix(),
|
||||||
|
VersionCheck: versionCheck,
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(token) == 0 && sshCertPrincipal == "" && !sshAgent && sshKey == "" {
|
if len(token) == 0 && sshCertPrincipal == "" && !sshAgent && sshKey == "" {
|
||||||
|
|
Loading…
Reference in New Issue