2020-09-30 05:11:33 +00:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2023-09-08 01:40:02 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-09-30 05:11:33 +00:00
|
|
|
|
|
|
|
package login
|
|
|
|
|
|
|
|
import (
|
|
|
|
"code.gitea.io/tea/modules/interact"
|
2020-12-12 13:28:37 +00:00
|
|
|
"code.gitea.io/tea/modules/task"
|
2020-09-30 05:11:33 +00: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 15:57:48 +00:00
|
|
|
Description: `Add a Gitea login, without args it will create one interactively`,
|
2022-09-13 18:14:02 +00:00
|
|
|
ArgsUsage: " ", // command does not accept arguments
|
2020-09-30 05:11:33 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "name",
|
|
|
|
Aliases: []string{"n"},
|
|
|
|
Usage: "Login name",
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
2020-10-02 15:57:48 +00:00
|
|
|
Name: "url",
|
|
|
|
Aliases: []string{"u"},
|
|
|
|
Value: "https://gitea.com",
|
|
|
|
EnvVars: []string{"GITEA_SERVER_URL"},
|
|
|
|
Usage: "Server URL",
|
2020-09-30 05:11:33 +00:00
|
|
|
},
|
2022-10-31 01:56:23 +00:00
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "no-version-check",
|
|
|
|
Aliases: []string{"nv"},
|
|
|
|
Usage: "Do not check version of Gitea instance",
|
|
|
|
},
|
2020-09-30 05:11:33 +00: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 16:49:29 +00: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 05:11:33 +00:00
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "ssh-key",
|
|
|
|
Aliases: []string{"s"},
|
2022-09-14 19:00:08 +00:00
|
|
|
Usage: "Path to a SSH key/certificate to use, overrides auto-discovery",
|
2020-09-30 05:11:33 +00:00
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "insecure",
|
|
|
|
Aliases: []string{"i"},
|
|
|
|
Usage: "Disable TLS verification",
|
|
|
|
},
|
2022-09-14 19:00:08 +00: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)",
|
|
|
|
},
|
2023-12-09 18:44:26 +00:00
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "helper",
|
|
|
|
Aliases: []string{"j"},
|
|
|
|
Usage: "Add helper",
|
|
|
|
},
|
2020-09-30 05:11:33 +00:00
|
|
|
},
|
|
|
|
Action: runLoginAdd,
|
|
|
|
}
|
|
|
|
|
|
|
|
func runLoginAdd(ctx *cli.Context) error {
|
2020-10-02 15:57:48 +00:00
|
|
|
// if no args create login interactive
|
2020-10-05 18:34:10 +00:00
|
|
|
if ctx.NumFlags() == 0 {
|
2020-10-02 15:57:48 +00:00
|
|
|
return interact.CreateLogin()
|
|
|
|
}
|
|
|
|
|
2022-09-14 19:00:08 +00:00
|
|
|
sshAgent := false
|
|
|
|
if ctx.String("ssh-agent-key") != "" || ctx.String("ssh-agent-principal") != "" {
|
|
|
|
sshAgent = true
|
|
|
|
}
|
|
|
|
|
2020-10-02 15:57:48 +00:00
|
|
|
// else use args to add login
|
2020-12-12 13:28:37 +00:00
|
|
|
return task.CreateLogin(
|
2020-09-30 05:11:33 +00:00
|
|
|
ctx.String("name"),
|
|
|
|
ctx.String("token"),
|
|
|
|
ctx.String("user"),
|
|
|
|
ctx.String("password"),
|
2024-02-14 16:49:29 +00:00
|
|
|
ctx.String("otp"),
|
|
|
|
ctx.String("scopes"),
|
2020-09-30 05:11:33 +00:00
|
|
|
ctx.String("ssh-key"),
|
|
|
|
ctx.String("url"),
|
2022-09-14 19:00:08 +00:00
|
|
|
ctx.String("ssh-agent-principal"),
|
|
|
|
ctx.String("ssh-agent-key"),
|
|
|
|
ctx.Bool("insecure"),
|
2022-10-31 01:56:23 +00:00
|
|
|
sshAgent,
|
2023-12-09 18:44:26 +00:00
|
|
|
!ctx.Bool("no-version-check"),
|
|
|
|
ctx.Bool("helper"),
|
|
|
|
)
|
2020-09-30 05:11:33 +00:00
|
|
|
}
|