diff --git a/cmd/ocm/token/cmd.go b/cmd/ocm/token/cmd.go index b9299710..85221fbf 100644 --- a/cmd/ocm/token/cmd.go +++ b/cmd/ocm/token/cmd.go @@ -20,6 +20,7 @@ import ( "encoding/base64" "fmt" "os" + "time" "github.com/dgrijalva/jwt-go" "github.com/spf13/cobra" @@ -33,6 +34,7 @@ var args struct { payload bool signature bool refresh bool + generate bool } var Cmd = &cobra.Command{ @@ -69,6 +71,12 @@ func init() { false, "Print the refresh token instead of the access token.", ) + flags.BoolVar( + &args.generate, + "generate", + false, + "Generate a new token.", + ) } func run(cmd *cobra.Command, argv []string) error { @@ -83,8 +91,12 @@ func run(cmd *cobra.Command, argv []string) error { if args.signature { count++ } + if args.generate { + count++ + } + if count > 1 { - return fmt.Errorf("Options '--payload', '--header' and '--signature' are mutually exclusive") + return fmt.Errorf("Options '--payload', '--header', '--signature', and '--generate' are mutually exclusive") } // Load the configuration file: @@ -111,10 +123,21 @@ func run(cmd *cobra.Command, argv []string) error { return fmt.Errorf("Can't create connection: %v", err) } - // Get the tokens: - accessToken, refreshToken, err := connection.Tokens() - if err != nil { - return fmt.Errorf("Can't get token: %v", err) + var accessToken string + var refreshToken string + + if args.generate { + // Get new tokens: + accessToken, refreshToken, err = connection.Tokens(15 * time.Minute) + if err != nil { + return fmt.Errorf("Can't get new tokens: %v", err) + } + } else { + // Get the tokens: + accessToken, refreshToken, err = connection.Tokens() + if err != nil { + return fmt.Errorf("Can't get token: %v", err) + } } // Select the token according to the options: diff --git a/go.mod b/go.mod index 5f4a6ffa..baab9159 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/mitchellh/go-homedir v1.1.0 github.com/onsi/ginkgo v1.11.0 github.com/onsi/gomega v1.7.0 - github.com/openshift-online/ocm-sdk-go v0.1.128 + github.com/openshift-online/ocm-sdk-go v0.1.129 github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4 github.com/prometheus/client_golang v1.2.1 // indirect github.com/prometheus/client_model v0.0.0-20191202183732-d1d2010b5bee // indirect diff --git a/go.sum b/go.sum index 35cfacb4..c8d0d949 100644 --- a/go.sum +++ b/go.sum @@ -149,6 +149,8 @@ github.com/openshift-online/ocm-sdk-go v0.1.123 h1:2jB6fCf1ikeKWoxcQA7+f8VFzA58t github.com/openshift-online/ocm-sdk-go v0.1.123/go.mod h1:3i3a/LEYtC7DMor3N94PTPn1+0qq+Fk+iLjt1Z0WVCs= github.com/openshift-online/ocm-sdk-go v0.1.128 h1:AlX7PkZOuZJPBzMM2CgF22YGMp6M9+UUPp8bfGORTDM= github.com/openshift-online/ocm-sdk-go v0.1.128/go.mod h1:3i3a/LEYtC7DMor3N94PTPn1+0qq+Fk+iLjt1Z0WVCs= +github.com/openshift-online/ocm-sdk-go v0.1.129 h1:LjqS4OfpTspoDk6+R8IqoqSt4DJl7hhSSHkZswlXSpk= +github.com/openshift-online/ocm-sdk-go v0.1.129/go.mod h1:3i3a/LEYtC7DMor3N94PTPn1+0qq+Fk+iLjt1Z0WVCs= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4 h1:49lOXmGaUpV9Fz3gd7TFZY106KVlPVa5jcYD1gaQf98= github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=