2020-09-30 01:11:33 -04:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2023-09-07 21:40:02 -04:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-09-30 01:11:33 -04:00
|
|
|
|
|
|
|
package login
|
|
|
|
|
|
|
|
import (
|
|
|
|
"code.gitea.io/tea/modules/interact"
|
2020-12-12 08:28:37 -05:00
|
|
|
"code.gitea.io/tea/modules/task"
|
2020-09-30 01:11:33 -04:00
|
|
|
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
// CmdLoginAdd represents to login a gitea server.
|
|
|
|
var CmdLoginAdd = cli.Command{
|
|
|
|
Name: "add",
|
|
|
|
Usage: "Add a Gitea login",
|
2020-10-02 11:57:48 -04:00
|
|
|
Description: `Add a Gitea login, without args it will create one interactively`,
|
2022-09-13 14:14:02 -04:00
|
|
|
ArgsUsage: " ", // command does not accept arguments
|
2020-09-30 01:11:33 -04:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "name",
|
|
|
|
Aliases: []string{"n"},
|
|
|
|
Usage: "Login name",
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
2020-10-02 11:57:48 -04:00
|
|
|
Name: "url",
|
|
|
|
Aliases: []string{"u"},
|
|
|
|
Value: "https://gitea.com",
|
|
|
|
EnvVars: []string{"GITEA_SERVER_URL"},
|
|
|
|
Usage: "Server URL",
|
2020-09-30 01:11:33 -04:00
|
|
|
},
|
2022-10-30 21:56:23 -04:00
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "no-version-check",
|
|
|
|
Aliases: []string{"nv"},
|
|
|
|
Usage: "Do not check version of Gitea instance",
|
|
|
|
},
|
2020-09-30 01:11:33 -04:00
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "token",
|
|
|
|
Aliases: []string{"t"},
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"GITEA_SERVER_TOKEN"},
|
|
|
|
Usage: "Access token. Can be obtained from Settings > Applications",
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "user",
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"GITEA_SERVER_USER"},
|
|
|
|
Usage: "User for basic auth (will create token)",
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "password",
|
|
|
|
Aliases: []string{"pwd"},
|
|
|
|
Value: "",
|
|
|
|
EnvVars: []string{"GITEA_SERVER_PASSWORD"},
|
|
|
|
Usage: "Password for basic auth (will create token)",
|
|
|
|
},
|
2024-02-14 11:49:29 -05:00
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "otp",
|
|
|
|
EnvVars: []string{"GITEA_SERVER_OTP"},
|
|
|
|
Usage: "OTP token for auth, if necessary",
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "scopes",
|
|
|
|
EnvVars: []string{"GITEA_SCOPES"},
|
|
|
|
Usage: "Token scopes to add when creating a new token, separated by a comma",
|
|
|
|
},
|
2020-09-30 01:11:33 -04:00
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "ssh-key",
|
|
|
|
Aliases: []string{"s"},
|
2022-09-14 15:00:08 -04:00
|
|
|
Usage: "Path to a SSH key/certificate to use, overrides auto-discovery",
|
2020-09-30 01:11:33 -04:00
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "insecure",
|
|
|
|
Aliases: []string{"i"},
|
|
|
|
Usage: "Disable TLS verification",
|
|
|
|
},
|
2022-09-14 15:00:08 -04:00
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "ssh-agent-principal",
|
|
|
|
Aliases: []string{"c"},
|
|
|
|
Usage: "Use SSH certificate with specified principal to login (needs a running ssh-agent with certificate loaded)",
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "ssh-agent-key",
|
|
|
|
Aliases: []string{"a"},
|
|
|
|
Usage: "Use SSH public key or SSH fingerprint to login (needs a running ssh-agent with ssh key loaded)",
|
|
|
|
},
|
2024-08-26 07:34:36 -04:00
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "helper",
|
|
|
|
Aliases: []string{"j"},
|
|
|
|
Usage: "Add helper",
|
|
|
|
},
|
2020-09-30 01:11:33 -04:00
|
|
|
},
|
|
|
|
Action: runLoginAdd,
|
|
|
|
}
|
|
|
|
|
|
|
|
func runLoginAdd(ctx *cli.Context) error {
|
2020-10-02 11:57:48 -04:00
|
|
|
// if no args create login interactive
|
2020-10-05 14:34:10 -04:00
|
|
|
if ctx.NumFlags() == 0 {
|
2020-10-02 11:57:48 -04:00
|
|
|
return interact.CreateLogin()
|
|
|
|
}
|
|
|
|
|
2022-09-14 15:00:08 -04:00
|
|
|
sshAgent := false
|
|
|
|
if ctx.String("ssh-agent-key") != "" || ctx.String("ssh-agent-principal") != "" {
|
|
|
|
sshAgent = true
|
|
|
|
}
|
|
|
|
|
2020-10-02 11:57:48 -04:00
|
|
|
// else use args to add login
|
2020-12-12 08:28:37 -05:00
|
|
|
return task.CreateLogin(
|
2020-09-30 01:11:33 -04:00
|
|
|
ctx.String("name"),
|
|
|
|
ctx.String("token"),
|
|
|
|
ctx.String("user"),
|
|
|
|
ctx.String("password"),
|
2024-02-14 11:49:29 -05:00
|
|
|
ctx.String("otp"),
|
|
|
|
ctx.String("scopes"),
|
2020-09-30 01:11:33 -04:00
|
|
|
ctx.String("ssh-key"),
|
|
|
|
ctx.String("url"),
|
2022-09-14 15:00:08 -04:00
|
|
|
ctx.String("ssh-agent-principal"),
|
|
|
|
ctx.String("ssh-agent-key"),
|
|
|
|
ctx.Bool("insecure"),
|
2022-10-30 21:56:23 -04:00
|
|
|
sshAgent,
|
2024-08-26 07:34:36 -04:00
|
|
|
!ctx.Bool("no-version-check"),
|
|
|
|
ctx.Bool("helper"),
|
|
|
|
)
|
2020-09-30 01:11:33 -04:00
|
|
|
}
|