Commit 1a7bd3bc authored by Simon Schürg's avatar Simon Schürg 🚀
Browse files

Add parser for pre defined login credentials in config

parent a8981d5e
......@@ -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 authCodeCredentials struct {
type AuthCodeCredentials 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{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment