-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package token | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/redhat-developer/app-services-cli/pkg/core/config" | ||
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/iostreams" | ||
"github.com/redhat-developer/app-services-cli/pkg/core/localize" | ||
"github.com/redhat-developer/app-services-cli/pkg/core/logging" | ||
"github.com/redhat-developer/app-services-cli/pkg/shared/connection" | ||
"github.com/redhat-developer/app-services-cli/pkg/shared/factory" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type options struct { | ||
Config config.IConfig | ||
Connection factory.ConnectionFunc | ||
IO *iostreams.IOStreams | ||
Logger logging.Logger | ||
localizer localize.Localizer | ||
} | ||
|
||
func NewAuthTokenCmd(f *factory.Factory) *cobra.Command { | ||
opts := &options{ | ||
Config: f.Config, | ||
Connection: f.Connection, | ||
IO: f.IOStreams, | ||
Logger: f.Logger, | ||
localizer: f.Localizer, | ||
} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "authtoken", | ||
Short: f.Localizer.MustLocalize("token.cmd.shortDescription"), | ||
Long: f.Localizer.MustLocalize("token.cmd.longDescription"), | ||
Example: f.Localizer.MustLocalize("token.cmd.example"), | ||
Args: cobra.NoArgs, | ||
RunE: func(cmd *cobra.Command, _ []string) error { | ||
return runCmd(opts) | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func runCmd(opts *options) (err error) { | ||
cfg, err := opts.Config.Load() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = opts.Connection(connection.DefaultConfigSkipMasAuth) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if cfg.AccessToken != "" { | ||
fmt.Fprintln(opts.IO.Out, cfg.AccessToken) | ||
} else { | ||
opts.Logger.Info(opts.localizer.MustLocalize("token.log.info.tokenUnavailable")) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[token.cmd.shortDescription] | ||
description = "Short description for command" | ||
one = "Output the current token" | ||
|
||
[token.cmd.longDescription] | ||
description = "Long description for command" | ||
one = ''' | ||
View the authentication token of the current user that can be used to | ||
make general API requests against api.openshift.com APIs. | ||
This command outputs the token for the user currently logged in. | ||
''' | ||
|
||
[token.cmd.example] | ||
description = 'Examples of how to use the command' | ||
one = ''' | ||
# Returns header with token used for authorization | ||
$ echo Authorization: BEARER ${rhoas authtoken} | ||
''' | ||
|
||
[token.log.info.tokenUnavailable] | ||
one = 'Token unavailable' |