Skip to content

Commit db8684d

Browse files
Merge pull request #124 from andre-djsystem/master
Implementantion for #122
2 parents 158a1a5 + eff1b16 commit db8684d

File tree

2 files changed

+43
-11
lines changed

2 files changed

+43
-11
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ boss upgrade
8484
boss upgrade --dev
8585
```
8686

87+
### > login
88+
This command Register login to repo
89+
```
90+
boss login <repo>
91+
boss adduser <repo>
92+
boss add-user <repo>
93+
boss login <repo> -u UserName -p Password
94+
boss login <repo> -k PrivateKey -p PassPhrase
95+
```
96+
###### Aliases: adduser, add-user
97+
8798
## Flags
8899

89100
### > Global
@@ -104,7 +115,6 @@ boss --help
104115
```
105116
delphi Configure Delphi version
106117
gc Garbage collector
107-
login Register login to repo
108118
publish Publish package to registry
109119
run Run cmd script
110120
```

cmd/login.go

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@ import (
66
"os/user"
77
"path/filepath"
88
"syscall"
9-
9+
1010
"github.com/hashload/boss/env"
1111
"github.com/hashload/boss/msg"
1212
"github.com/spf13/cobra"
1313
"golang.org/x/term"
1414
)
1515

1616
var removeLogin bool
17+
var useSsh bool
18+
var privateKey string
19+
var userName string
20+
var password string
1721

1822
var loginCmd = &cobra.Command{
1923
Use: "login",
@@ -22,17 +26,21 @@ var loginCmd = &cobra.Command{
2226
boss login <repo>`,
2327
Aliases: []string{"adduser", "add-user"},
2428
Run: func(cmd *cobra.Command, args []string) {
25-
login(removeLogin, args)
29+
login(removeLogin, useSsh, privateKey, userName, password, args)
2630
},
2731
}
2832

2933
func init() {
3034
// TODO add example to remove login or add a new command to logout (equals branch refact-steroids)
3135
loginCmd.Flags().BoolVarP(&removeLogin, "rm", "r", false, "remove login")
36+
loginCmd.Flags().BoolVarP(&useSsh, "ssh", "s", false, "Use SSH")
37+
loginCmd.Flags().StringVarP(&privateKey, "key", "k", "", "Path of ssh private key")
38+
loginCmd.Flags().StringVarP(&userName, "username", "u", "", "Username")
39+
loginCmd.Flags().StringVarP(&password, "password", "p", "", "Password or PassPhrase(with SSH)")
3240
RootCmd.AddCommand(loginCmd)
3341
}
3442

35-
func login(removeLogin bool, args []string) {
43+
func login(removeLogin bool, useSsh bool, privateKey string, userName string, password string, args []string) {
3644
configuration := env.GlobalConfiguration
3745

3846
if removeLogin {
@@ -57,15 +65,29 @@ func login(removeLogin bool, args []string) {
5765
if auth == nil {
5866
auth = &env.Auth{}
5967
}
60-
61-
auth.UseSsh = getParamBoolean("Use SSH")
62-
if auth.UseSsh {
63-
auth.Path = getParamOrDef("Path of ssh private key("+getSshKeyPath()+")", getSshKeyPath())
64-
auth.SetPassPhrase(getPass("PassPhrase"))
68+
69+
if (userName != "") || (privateKey != "") {
70+
auth.UseSsh = useSsh
71+
if auth.UseSsh || (privateKey != "") {
72+
auth.UseSsh = true
73+
auth.Path = privateKey
74+
auth.SetPassPhrase(password)
75+
} else {
76+
auth.SetUser(userName)
77+
auth.SetPass(password)
78+
}
6579
} else {
66-
auth.SetUser(getParamOrDef("Username", ""))
67-
auth.SetPass(getPass("Password"))
80+
auth.UseSsh = getParamBoolean("Use SSH")
81+
82+
if auth.UseSsh {
83+
auth.Path = getParamOrDef("Path of ssh private key("+getSshKeyPath()+")", getSshKeyPath())
84+
auth.SetPassPhrase(getPass("PassPhrase"))
85+
} else {
86+
auth.SetUser(getParamOrDef("Username", ""))
87+
auth.SetPass(getPass("Password"))
88+
}
6889
}
90+
6991
configuration.Auth[repo] = auth
7092
configuration.SaveConfiguration()
7193

0 commit comments

Comments
 (0)