Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ Once pushed, a [GitHub Action](https://github.com/redhat-developer/app-services-

> NOTE: To create a pre-release, the tag should have appropriate suffix, e.g v0.20.1-alpha1

### Environment variables

RHOASCONFIG="./config.json" - custom configuration location (useful for testing)
RHOAS_CONTEXT="./context.json" - custom context location
RHOAS_TELEMETRY=false - Enables/Disables telemetry (should happen automatically in non tty sessions)
EDITOR=Code -w - controls CLI editor
KUBECONFIG=./config.json - custom kubernetes config used for other commands

### Changelog generation

[git-chglog](https://github.com/git-chglog/git-chglog) is used to generate a changelog for the current release.
Expand Down
32 changes: 6 additions & 26 deletions pkg/cmd/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,26 +156,24 @@ func runLogin(opts *options) (err error) {
return err
}
}

if opts.offlineToken != "" {
if err = loginWithOfflineToken(opts); err != nil {
spinner.Stop()
opts.Logger.Info()
return err
}
}
spinner.Stop()

cfg, err := opts.Config.Load()
if err != nil {
return err
}

if opts.offlineToken != "" {
cfg.RefreshToken = opts.offlineToken
}

cfg.APIUrl = gatewayURL.String()
cfg.Insecure = opts.insecureSkipTLSVerify
cfg.ClientID = opts.clientID
cfg.AuthURL = opts.authURL
cfg.Scopes = opts.scopes
// Reset access token on login to avoid reusing previous users valid token
cfg.AccessToken = ""

if err = opts.Config.Save(cfg); err != nil {
return err
Expand All @@ -199,24 +197,6 @@ func runLogin(opts *options) (err error) {
return nil
}

func loginWithOfflineToken(opts *options) (err error) {
cfg, err := opts.Config.Load()
if err != nil {
return err
}
cfg.Insecure = opts.insecureSkipTLSVerify
cfg.ClientID = opts.clientID
cfg.AuthURL = opts.authURL
cfg.Scopes = opts.scopes
cfg.RefreshToken = opts.offlineToken

if err = opts.Config.Save(cfg); err != nil {
return err
}

return err
}

func createTransport(insecure bool) *http.Transport {
// #nosec 402
return &http.Transport{
Expand Down
8 changes: 7 additions & 1 deletion pkg/core/auth/token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,13 @@ func GetExpiry(tokenStr string, now time.Time) (expires bool,

// GetUsername extracts the username claim value from the JWT
func GetUsername(tokenStr string) (username string, ok bool) {
accessTkn, _ := Parse(tokenStr)
if tokenStr == "" {
return "", false
}
accessTkn, err := Parse(tokenStr)
if err != nil {
return "", false
}
tknClaims, _ := MapClaims(accessTkn)
u, ok := tknClaims["preferred_username"]
if ok {
Expand Down
17 changes: 0 additions & 17 deletions pkg/core/cmdutil/profile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@
package profile

import (
"os"
"strconv"

"github.com/spf13/cobra"
)

const DevPreviewEnv = "RHOAS_DEV"

// ApplyDevPreviewLabel adds visual element displayed in help
func ApplyDevPreviewLabel(cmd *cobra.Command) {
cmd.Short = "[beta] " + cmd.Short
Expand All @@ -24,15 +19,3 @@ func ApplyDevPreviewLabel(cmd *cobra.Command) {
func DevPreviewAnnotation() map[string]string {
return map[string]string{"channel": "preview"}
}

// DevModeEnabled Check if development mode is enabled
func DevModeEnabled() bool {
rawEnvVal := os.Getenv(DevPreviewEnv)

boolVal, err := strconv.ParseBool(rawEnvVal)
if err != nil {
return false
}

return boolVal
}