Skip to content

Commit

Permalink
Merge pull request #13 from grycap/devel
Browse files Browse the repository at this point in the history
oidc-agent support
  • Loading branch information
srisco authored Oct 5, 2022
2 parents db606b9 + 57742f9 commit e38898d
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 520 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,17 @@ Add a new existing cluster to oscar-cli.

```
Usage:
oscar-cli cluster add IDENTIFIER ENDPOINT USERNAME {PASSWORD | --password-stdin} [flags]
oscar-cli cluster add IDENTIFIER ENDPOINT {USERNAME {PASSWORD | --password-stdin} | --oidc-account-name ACCOUNT} [flags]
Aliases:
add, a
Flags:
--disable-ssl disable verification of ssl certificates for the added cluster
-h, --help help for add
--password-stdin take the password from stdin
--disable-ssl disable verification of ssl certificates for the added cluster
-h, --help help for add
-o, --oidc-account-name string OIDC account name to authenticate using oidc-agent. Note that oidc-agent must be started and properly configured
(See: https://indigo-dc.gitbook.io/oidc-agent/)
--password-stdin take the password from stdin
Global Flags:
--config string set the location of the config file (YAML or JSON)
Expand Down
49 changes: 32 additions & 17 deletions cmd/cluster_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package cmd
import (
"errors"
"fmt"
"io/ioutil"
"io"
"os"
"strings"

Expand All @@ -32,25 +32,39 @@ func clusterAddFunc(cmd *cobra.Command, args []string) error {
// Get the arguments
identifier := args[0]
endpoint := args[1]
username := args[2]
var username string
var pass string
var err error
passStdin, _ := cmd.Flags().GetBool("password-stdin")
if passStdin {
if len(args) != 3 {

oidcAccountName, _ := cmd.Flags().GetString("oidc-account-name")
if oidcAccountName != "" {
if len(args) != 2 {
cmd.SilenceUsage = false
return errors.New("if the \"--password-stdin\" flag is set only 3 arguments are allowed")
}
pass, err = readPassStdin()
if err != nil {
return err
return errors.New("if the \"--oidc-account-name\" flag is set only 2 arguments are allowed")
}
} else {
if len(args) != 4 {
if len(args) == 2 {
cmd.SilenceUsage = false
return errors.New("you must provide the password")
return errors.New("you must provide the username")
}
username = args[2]
passStdin, _ := cmd.Flags().GetBool("password-stdin")
if passStdin {
if len(args) != 3 {
cmd.SilenceUsage = false
return errors.New("if the \"--password-stdin\" flag is set only 3 arguments are allowed")
}
pass, err = readPassStdin()
if err != nil {
return err
}
} else {
if len(args) != 4 {
cmd.SilenceUsage = false
return errors.New("you must provide the password")
}
pass = args[3]
}
pass = args[3]
}

conf, err := config.ReadConfig(configPath)
Expand All @@ -62,7 +76,7 @@ func clusterAddFunc(cmd *cobra.Command, args []string) error {

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

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

func makeClusterAddCmd() *cobra.Command {
clusterAddCmd := &cobra.Command{
Use: "add IDENTIFIER ENDPOINT USERNAME {PASSWORD | --password-stdin}",
Use: "add IDENTIFIER ENDPOINT {USERNAME {PASSWORD | --password-stdin} | --oidc-account-name ACCOUNT}",
Short: "Add a new existing cluster to oscar-cli",
Args: cobra.RangeArgs(3, 4),
Args: cobra.RangeArgs(2, 4),
Aliases: []string{"a"},
RunE: clusterAddFunc,
}

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/)")

return clusterAddCmd
}

func readPassStdin() (string, error) {
bytes, err := ioutil.ReadAll(os.Stdin)
bytes, err := io.ReadAll(os.Stdin)
if err != nil {
return "", err
}
Expand Down
49 changes: 26 additions & 23 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,61 @@ module github.com/grycap/oscar-cli
go 1.18

require (
github.com/aws/aws-sdk-go v1.44.59
github.com/briandowns/spinner v1.18.1
github.com/aws/aws-sdk-go v1.44.109
github.com/briandowns/spinner v1.19.0
github.com/fatih/color v1.13.0
github.com/go-logr/logr v1.2.3 // indirect
github.com/goccy/go-yaml v1.9.5
github.com/grycap/oscar/v2 v2.5.0
github.com/grycap/oscar/v2 v2.5.1
github.com/json-iterator/go v1.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/spf13/cobra v1.5.0
golang.org/x/net v0.0.0-20220708220712-1185a9018129 // indirect
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
golang.org/x/net v0.0.0-20221002022538-bcab6841153b // indirect
golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec // indirect
golang.org/x/text v0.3.7 // indirect
k8s.io/api v0.24.3 // indirect
k8s.io/klog/v2 v2.70.1 // indirect
k8s.io/api v0.25.2 // indirect
k8s.io/klog/v2 v2.80.1 // indirect
)

require github.com/indigo-dc/liboidcagent-go v0.3.0

require (
github.com/adrg/xdg v0.4.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/swag v0.21.1 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/gnostic v0.6.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/grycap/cdmi-client-go v0.1.1 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/oauth2 v0.0.0-20220718184931-c8730f7fcb92 // indirect
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 // indirect
golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
golang.org/x/crypto v0.0.0-20220926161630-eccd6366d1be // indirect
golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1 // indirect
golang.org/x/term v0.0.0-20220919170432-7a66f970e087 // indirect
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apimachinery v0.24.3 // indirect
k8s.io/client-go v0.24.3 // indirect
k8s.io/kube-openapi v0.0.0-20220627174259-011e075b9cb8 // indirect
k8s.io/utils v0.0.0-20220713171938-56c0de1e6f5e // indirect
k8s.io/apimachinery v0.25.2 // indirect
k8s.io/client-go v0.25.2 // indirect
k8s.io/kube-openapi v0.0.0-20220928191237-829ce0c27909 // indirect
k8s.io/utils v0.0.0-20220922133306-665eaaec4324 // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading

0 comments on commit e38898d

Please sign in to comment.