Commit 4542f327 authored by Simon Schürg's avatar Simon Schürg 🚀
Browse files

Cleanup and refactoring

parent 022e2280
......@@ -10,10 +10,12 @@ import (
"github.com/spf13/viper"
)
// Credentials is an interface with login method
type Credentials interface {
Login()
}
// BaseCredentials is the super-struct of all credential structs
type BaseCredentials struct {
issuer string
clientID string
......@@ -44,7 +46,7 @@ var loginCmd = &cobra.Command{
Short: "Performs an OpenID Connect Login and retreive tokens.",
Long: `Performs an OpenID Connect Login and retreive two JWT - an access token and a refresh token.`,
Run: func(cmd *cobra.Command, args []string) {
if Profile == "" {
if profile == "" {
fmt.Printf("The login command requires either a subcommand or the profile flag to be set.\n\n")
cmd.Help()
os.Exit(1)
......@@ -54,12 +56,13 @@ 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 %s could not be loaded from config file")
log.Panicf("Profile could not be loaded from config file")
}
return profile
}
......@@ -70,7 +73,7 @@ var loginACCmd = &cobra.Command{
Long: `Performs OpenID Connect Authorization Code Authorization`,
Run: func(cmd *cobra.Command, args []string) {
// log.Fatalln("This command is not yet implemented!")
internal.AuthorizationCodeAuth(ClientId, ClientSecret, Issuer)
internal.AuthorizationCodeAuth(clientID, clientSecret, issuer)
},
}
......@@ -79,7 +82,7 @@ var loginROPCmd = &cobra.Command{
Short: "Performs OpenID Connect Resource Owner Password Credentials Authorization",
Long: `Performs OpenID Connect Resource Owner Password Credentials Authorization`,
Run: func(cmd *cobra.Command, args []string) {
internal.ResourceOwnerCredentialsAuth(Issuer, ClientId, Username, Password)
internal.ResourceOwnerCredentialsAuth(issuer, clientID, username, password)
},
}
......@@ -88,7 +91,7 @@ var loginCCCmd = &cobra.Command{
Short: "Performs OpenID Connect Client Credentials Authorization",
Long: `Performs OpenID Connect Client Credentials Authorization`,
Run: func(cmd *cobra.Command, args []string) {
internal.ClientCredenitalsAuth(Issuer, ClientId, ClientSecret)
internal.ClientCredenitalsAuth(issuer, clientID, clientSecret)
},
}
......@@ -97,43 +100,43 @@ var refreshCmd = &cobra.Command{
Short: "Performs OpenID Connect refresh",
Long: `Performs OpenID Connect refresh`,
Run: func(cmd *cobra.Command, args []string) {
internal.RefreshToken(Issuer, ClientId, ClientSecret)
internal.RefreshToken(issuer, clientID, clientSecret)
},
}
var ToClipboard bool
var ClientId string
var ClientSecret string
var Issuer string
var Username string
var Password string
var Profile string
var RefreshToken string
var toClipboard bool
var clientID string
var clientSecret string
var issuer string
var username string
var password string
var profile string
var refreshToken string
func init() {
rootCmd.AddCommand(loginCmd)
loginCmd.Flags().StringVar(&Profile, "profile", "", "Use login information (profile) from actl config")
loginCmd.Flags().StringVar(&profile, "profile", "", "Use login information (profile) from actl config")
loginCmd.AddCommand(loginACCmd)
loginACCmd.Flags().StringVar(&Issuer, "issuer", "", "OpenID Connect Issuer")
loginACCmd.Flags().StringVar(&ClientId, "client_id", "", "Client ID")
loginACCmd.Flags().StringVar(&ClientSecret, "client_secret", "", "Client Secret")
loginACCmd.Flags().BoolVarP(&ToClipboard, "clipboard", "c", false, "Copy Access Token to system clipboard")
loginACCmd.Flags().StringVar(&issuer, "issuer", "", "OpenID Connect Issuer")
loginACCmd.Flags().StringVar(&clientID, "client_id", "", "Client ID")
loginACCmd.Flags().StringVar(&clientSecret, "client_secret", "", "Client Secret")
loginACCmd.Flags().BoolVarP(&toClipboard, "clipboard", "c", false, "Copy Access Token to system clipboard")
loginCmd.AddCommand(loginCCCmd)
loginCCCmd.Flags().StringVar(&Issuer, "issuer", "", "OpenID Connect Issuer")
loginCCCmd.Flags().StringVar(&ClientId, "client_id", "", "Client ID")
loginCCCmd.Flags().StringVar(&ClientSecret, "client_secret", "", "Client Secret")
loginCCCmd.Flags().StringVar(&issuer, "issuer", "", "OpenID Connect Issuer")
loginCCCmd.Flags().StringVar(&clientID, "client_id", "", "Client ID")
loginCCCmd.Flags().StringVar(&clientSecret, "client_secret", "", "Client Secret")
loginCmd.AddCommand(loginROPCmd)
loginROPCmd.Flags().StringVar(&Issuer, "issuer", "", "OpenID Connect Issuer")
loginROPCmd.Flags().StringVar(&ClientId, "client_id", "", "Client ID")
loginROPCmd.Flags().StringVar(&Username, "username", "", "Username")
loginROPCmd.Flags().StringVar(&Password, "password", "", "Password")
loginROPCmd.Flags().StringVar(&issuer, "issuer", "", "OpenID Connect Issuer")
loginROPCmd.Flags().StringVar(&clientID, "client_id", "", "Client ID")
loginROPCmd.Flags().StringVar(&username, "username", "", "Username")
loginROPCmd.Flags().StringVar(&password, "password", "", "Password")
loginCmd.AddCommand(refreshCmd)
refreshCmd.Flags().StringVar(&Issuer, "issuer", "", "OpenID Connect Issuer")
refreshCmd.Flags().StringVar(&ClientId, "client_id", "", "Client ID")
refreshCmd.Flags().StringVar(&RefreshToken, "refresh_token", "", "Refresh Token")
refreshCmd.Flags().StringVar(&issuer, "issuer", "", "OpenID Connect Issuer")
refreshCmd.Flags().StringVar(&clientID, "client_id", "", "Client ID")
refreshCmd.Flags().StringVar(&refreshToken, "refresh_token", "", "Refresh Token")
}
......@@ -12,7 +12,7 @@ import (
var (
cfgFile string
Verbose bool
verbose bool
)
// rootCmd represents the base command when called without any subcommands
......@@ -43,7 +43,7 @@ func init() {
// will be global for your application.
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.actl.toml)")
rootCmd.PersistentFlags().BoolVarP(&Verbose, "verbose", "v", false, "verbose output")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "verbose output")
// Cobra also supports local flags, which will only run
// when this action is called directly.
......
......@@ -7,14 +7,10 @@ require (
github.com/asdine/storm/v3 v3.2.1
github.com/atotto/clipboard v0.1.2
github.com/coreos/go-oidc v2.2.1+incompatible
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/fatih/color v1.9.0 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/go-openapi/strfmt v0.19.6 // indirect
github.com/google/uuid v1.1.2
github.com/hokaccha/go-prettyjson v0.0.0-20190818114111-108c894c2c0e // indirect
github.com/int128/oauth2cli v1.13.0
github.com/jedib0t/go-pretty v4.3.0+incompatible
github.com/jedib0t/go-pretty/v6 v6.0.5
github.com/magiconair/properties v1.8.4 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
......@@ -31,7 +27,6 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.7.1
github.com/square/go-jose/v3 v3.0.0-20200630053402-0a67ce9b0693
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0 // indirect
golang.org/x/net v0.0.0-20201010224723-4f7140c49acb // indirect
golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43
......
This diff is collapsed.
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