mirror of
https://gitea.com/gitea/tea.git
synced 2024-09-01 04:14:18 -04:00
Unexport generateToken() move CreateLogin into task Create func config.SetDefaultLogin() Unexport loadConfig() & saveConfig unexport config var make SetDefaultLogin() case insensitive update func descriptions move FindSSHKey to task module Reviewed-on: https://gitea.com/gitea/tea/pulls/288 Reviewed-by: Norwin <noerw@noreply.gitea.io> Reviewed-by: Andrew Thornton <art27@cantab.net> Co-Authored-By: 6543 <6543@obermui.de> Co-Committed-By: 6543 <6543@obermui.de>
82 lines
2.0 KiB
Go
82 lines
2.0 KiB
Go
// 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"
|
|
"code.gitea.io/tea/modules/task"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
// CmdLoginAdd represents to login a gitea server.
|
|
var CmdLoginAdd = cli.Command{
|
|
Name: "add",
|
|
Usage: "Add a Gitea login",
|
|
Description: `Add a Gitea login, without args it will create one interactively`,
|
|
Flags: []cli.Flag{
|
|
&cli.StringFlag{
|
|
Name: "name",
|
|
Aliases: []string{"n"},
|
|
Usage: "Login name",
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "url",
|
|
Aliases: []string{"u"},
|
|
Value: "https://gitea.com",
|
|
EnvVars: []string{"GITEA_SERVER_URL"},
|
|
Usage: "Server URL",
|
|
},
|
|
&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"},
|
|
Usage: "Path to a SSH key to use, overrides auto-discovery",
|
|
},
|
|
&cli.BoolFlag{
|
|
Name: "insecure",
|
|
Aliases: []string{"i"},
|
|
Usage: "Disable TLS verification",
|
|
},
|
|
},
|
|
Action: runLoginAdd,
|
|
}
|
|
|
|
func runLoginAdd(ctx *cli.Context) error {
|
|
// if no args create login interactive
|
|
if ctx.NumFlags() == 0 {
|
|
return interact.CreateLogin()
|
|
}
|
|
|
|
// else use args to add login
|
|
return task.CreateLogin(
|
|
ctx.String("name"),
|
|
ctx.String("token"),
|
|
ctx.String("user"),
|
|
ctx.String("password"),
|
|
ctx.String("ssh-key"),
|
|
ctx.String("url"),
|
|
ctx.Bool("insecure"))
|
|
}
|