Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Simon Schürg
actl
Commits
1a7bd3bc
Commit
1a7bd3bc
authored
Mar 06, 2021
by
Simon Schürg
🚀
Browse files
Add parser for pre defined login credentials in config
parent
a8981d5e
Changes
1
Hide whitespace changes
Inline
Side-by-side
cmd/login.go
View file @
1a7bd3bc
...
...
@@ -2,7 +2,6 @@ package cmd
import
(
"fmt"
"log"
"os"
"git.schuerg.net/simon/actl/internal"
...
...
@@ -21,26 +20,42 @@ type BaseCredentials struct {
clientID
string
}
type
a
uthCodeCredentials
struct
{
type
A
uthCodeCredentials
struct
{
BaseCredentials
}
type
passwordCredentials
struct
{
BaseCredentials
username
string
password
string
func
(
c
AuthCodeCredentials
)
Login
()
{
fmt
.
Println
(
"LOGIN"
)
}
type
PasswordCredentials
struct
{
// login_type string `mapstructure:"login_typ,squash"`
Username
string
`mapstructure:`
// password string `mapstructure:"password,squash"`
}
type
clientCredentials
struct
{
func
(
c
PasswordCredentials
)
Login
()
{
fmt
.
Println
(
"LOGIN"
)
}
type
ClientCredentials
struct
{
BaseCredentials
clientSecret
string
}
type
refreshCredentials
struct
{
func
(
c
ClientCredentials
)
Login
()
{
fmt
.
Println
(
"LOGIN"
)
}
type
RefreshCredentials
struct
{
BaseCredentials
refreshToken
string
}
func
(
c
RefreshCredentials
)
Login
()
{
fmt
.
Println
(
"LOGIN"
)
}
// type LoginProfile struct {
// LoginType string
// Issuer string
...
...
@@ -81,12 +96,31 @@ var loginCmd = &cobra.Command{
// GetProfile loads profiles from config
func
GetProfile
(
profileID
string
)
Credentials
{
logins
:=
viper
.
GetViper
()
.
GetStringMap
(
"logins"
)
fmt
.
Println
(
logins
)
profile
,
ok
:=
logins
[
profileID
]
.
(
Credentials
)
if
!
ok
{
log
.
Panicf
(
"Profile could not be loaded from config file"
)
for
k
,
v
:=
range
logins
{
if
k
!=
profileID
{
continue
}
configKey
:=
fmt
.
Sprintf
(
"logins.%s"
,
k
)
switch
v
.
(
map
[
string
]
interface
{})[
"login_type"
]
.
(
string
)
{
case
"password"
:
var
profile
PasswordCredentials
err
:=
viper
.
UnmarshalKey
(
configKey
,
&
profile
)
internal
.
FatalOnError
(
err
)
return
profile
case
"client"
:
var
profile
ClientCredentials
err
:=
viper
.
UnmarshalKey
(
configKey
,
&
profile
)
internal
.
FatalOnError
(
err
)
return
profile
case
"code"
:
var
profile
AuthCodeCredentials
err
:=
viper
.
UnmarshalKey
(
configKey
,
&
profile
)
internal
.
FatalOnError
(
err
)
return
profile
}
}
return
profile
// Profile not found
return
nil
}
var
loginACCmd
=
&
cobra
.
Command
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment