Skip to content

Commit

Permalink
oidc-token implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioLangaritaBenitez committed Aug 14, 2024
1 parent faea8b2 commit 0b6663f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
11 changes: 9 additions & 2 deletions cmd/cluster_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,17 @@ func clusterAddFunc(cmd *cobra.Command, args []string) error {
var err error

oidcAccountName, _ := cmd.Flags().GetString("oidc-account-name")
oidcToken, _ := cmd.Flags().GetString("oidc-token")
if oidcAccountName != "" {
if len(args) != 2 {
cmd.SilenceUsage = false
return errors.New("if the \"--oidc-account-name\" flag is set only 2 arguments are allowed")
}
} else if oidcToken != "" {
if len(args) != 2 {
cmd.SilenceUsage = false
return errors.New("if the \"--oidc-token\" flag is set only 2 arguments are allowed")
}
} else {
if len(args) == 2 {
cmd.SilenceUsage = false
Expand Down Expand Up @@ -76,7 +82,7 @@ func clusterAddFunc(cmd *cobra.Command, args []string) error {

disableSSL, _ := cmd.Flags().GetBool("disable-ssl")

err = conf.AddCluster(configPath, identifier, endpoint, username, pass, oidcAccountName, !disableSSL)
err = conf.AddCluster(configPath, identifier, endpoint, username, pass, oidcAccountName, oidcToken, !disableSSL)
if err != nil {
return err
}
Expand All @@ -88,7 +94,7 @@ func clusterAddFunc(cmd *cobra.Command, args []string) error {

func makeClusterAddCmd() *cobra.Command {
clusterAddCmd := &cobra.Command{
Use: "add IDENTIFIER ENDPOINT {USERNAME {PASSWORD | --password-stdin} | --oidc-account-name ACCOUNT}",
Use: "add IDENTIFIER ENDPOINT {USERNAME {PASSWORD | --password-stdin} | --oidc-account-name ACCOUNT | --oidc-token TOKEN}",
Short: "Add a new existing cluster to oscar-cli",
Args: cobra.RangeArgs(2, 4),
Aliases: []string{"a"},
Expand All @@ -98,6 +104,7 @@ func makeClusterAddCmd() *cobra.Command {
clusterAddCmd.Flags().Bool("disable-ssl", false, "disable verification of ssl certificates for the added cluster")
clusterAddCmd.Flags().Bool("password-stdin", false, "take the password from stdin")
clusterAddCmd.Flags().StringP("oidc-account-name", "o", "", "OIDC account name to authenticate using oidc-agent. Note that oidc-agent must be started and properly configured\n(See: https://indigo-dc.gitbook.io/oidc-agent/)")
clusterAddCmd.Flags().StringP("oidc-token", "t", "", "OIDC token to authenticate using oidc-token. Note that oidc-token must be started and properly configured\n(See: https://mytoken.data.kit.edu/)")

return clusterAddCmd
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type Cluster struct {
AuthUser string `json:"auth_user,omitempty"`
AuthPassword string `json:"auth_password,omitempty"`
OIDCAccountName string `json:"oidc_account_name,omitempty"`
OIDCToken string `json:"oidc_token,omitempty"`
SSLVerify bool `json:"ssl_verify"`
Memory string `json:"memory"`
LogLevel string `json:"log_level"`
Expand Down Expand Up @@ -108,6 +109,11 @@ func (cluster *Cluster) GetClient(args ...int) *http.Client {
token: token,
transport: transport,
}
} else if cluster.OIDCToken != "" {
transport = &tokenRoundTripper{
token: cluster.OIDCToken,
transport: transport,
}
} else {
// Use basic auth
transport = &basicAuthRoundTripper{
Expand Down
3 changes: 2 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,14 @@ func (config *Config) writeConfig(configPath string) (err error) {
}

// AddCluster adds a new cluster to the config
func (config *Config) AddCluster(configPath string, id string, endpoint string, authUser string, authPassword string, oidcAccountName string, sslVerify bool) error {
func (config *Config) AddCluster(configPath string, id string, endpoint string, authUser string, authPassword string, oidcAccountName string, oidcToken string, sslVerify bool) error {
// Add (or overwrite) the new cluster
config.Oscar[id] = &cluster.Cluster{
Endpoint: endpoint,
AuthUser: authUser,
AuthPassword: authPassword,
OIDCAccountName: oidcAccountName,
OIDCToken: oidcToken,
SSLVerify: sslVerify,
Memory: defaultMemory,
LogLevel: defaultLogLevel,
Expand Down

0 comments on commit 0b6663f

Please sign in to comment.