2020-09-30 13:11:33 +08:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package login
|
|
|
|
|
|
|
|
import (
|
|
|
|
"code.gitea.io/tea/modules/interact"
|
2020-12-12 21:28:37 +08:00
|
|
|
"code.gitea.io/tea/modules/task"
|
2020-09-30 13:11:33 +08: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 23:57:48 +08:00
|
|
|
Description: `Add a Gitea login, without args it will create one interactively`,
|
2020-09-30 13:11:33 +08:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "name",
|
|
|
|
Aliases: []string{"n"},
|
|
|
|
Usage: "Login name",
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
2020-10-02 23:57:48 +08:00
|
|
|
Name: "url",
|
|
|
|
Aliases: []string{"u"},
|
|
|
|
Value: "https://gitea.com",
|
|
|
|
EnvVars: []string{"GITEA_SERVER_URL"},
|
|
|
|
Usage: "Server URL",
|
2020-09-30 13:11:33 +08: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)",
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "ssh-key",
|
|
|
|
Aliases: []string{"s"},
|
2020-12-11 21:42:41 +08:00
|
|
|
Usage: "Path to a SSH key to use, overrides auto-discovery",
|
2020-09-30 13:11:33 +08:00
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "insecure",
|
|
|
|
Aliases: []string{"i"},
|
|
|
|
Usage: "Disable TLS verification",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: runLoginAdd,
|
|
|
|
}
|
|
|
|
|
|
|
|
func runLoginAdd(ctx *cli.Context) error {
|
2020-10-02 23:57:48 +08:00
|
|
|
// if no args create login interactive
|
2020-10-06 02:34:10 +08:00
|
|
|
if ctx.NumFlags() == 0 {
|
2020-10-02 23:57:48 +08:00
|
|
|
return interact.CreateLogin()
|
|
|
|
}
|
|
|
|
|
|
|
|
// else use args to add login
|
2020-12-12 21:28:37 +08:00
|
|
|
return task.CreateLogin(
|
2020-09-30 13:11:33 +08:00
|
|
|
ctx.String("name"),
|
|
|
|
ctx.String("token"),
|
|
|
|
ctx.String("user"),
|
|
|
|
ctx.String("password"),
|
|
|
|
ctx.String("ssh-key"),
|
|
|
|
ctx.String("url"),
|
|
|
|
ctx.Bool("insecure"))
|
|
|
|
}
|