Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion cmd/admin/organizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"fmt"

"github.com/adobe/imscli/ims"
"github.com/adobe/imscli/output"
"github.com/spf13/cobra"
)

Expand All @@ -32,7 +33,7 @@ func OrganizationsCmd(imsConfig *ims.Config) *cobra.Command {
if err != nil {
return fmt.Errorf("error in get admin organizations cmd: %w", err)
}
fmt.Println(resp)
output.PrintPrettyJSON(resp)
return nil
},
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/admin/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"fmt"

"github.com/adobe/imscli/ims"
"github.com/adobe/imscli/output"
"github.com/spf13/cobra"
)

Expand All @@ -30,7 +31,7 @@ func ProfileCmd(imsConfig *ims.Config) *cobra.Command {
if err != nil {
return fmt.Errorf("error in get admin profile cmd: %w", err)
}
fmt.Println(resp)
output.PrintPrettyJSON(resp)
return nil
},
}
Expand Down
20 changes: 20 additions & 0 deletions ims/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
package ims

import (
"fmt"
"net/url"

"github.com/adobe/ims-go/ims"
)

type Config struct {
Expand Down Expand Up @@ -61,6 +64,23 @@ type RefreshInfo struct {
RefreshToken string
}

func (i Config) resolveToken() (string, ims.TokenType, error) {
switch {
case i.AccessToken != "":
return i.AccessToken, ims.AccessToken, nil
case i.RefreshToken != "":
return i.RefreshToken, ims.RefreshToken, nil
case i.DeviceToken != "":
return i.DeviceToken, ims.DeviceToken, nil
case i.ServiceToken != "":
return i.ServiceToken, ims.ServiceToken, nil
case i.AuthorizationCode != "":
return i.AuthorizationCode, ims.AuthorizationCode, nil
default:
return "", "", fmt.Errorf("no token provided")
}
}

func validateURL(u string) bool {
parsedURL, err := url.Parse(u)
if err != nil {
Expand Down
19 changes: 2 additions & 17 deletions ims/invalidate.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,8 @@ func (i Config) InvalidateToken() error {
return fmt.Errorf("create client: %w", err)
}

var token string
var tokenType ims.TokenType

switch {
case i.AccessToken != "":
token = i.AccessToken
tokenType = ims.AccessToken
case i.RefreshToken != "":
token = i.RefreshToken
tokenType = ims.RefreshToken
case i.DeviceToken != "":
token = i.DeviceToken
tokenType = ims.DeviceToken
case i.ServiceToken != "":
token = i.ServiceToken
tokenType = ims.ServiceToken
default:
token, tokenType, err := i.resolveToken()
if err != nil {
return fmt.Errorf("unexpected error, broken parameter validation")
}

Expand Down
19 changes: 2 additions & 17 deletions ims/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,8 @@ func (i Config) ValidateToken() (TokenInfo, error) {
return TokenInfo{}, fmt.Errorf("create client: %w", err)
}

var token string
var tokenType ims.TokenType

switch {
case i.AccessToken != "":
token = i.AccessToken
tokenType = ims.AccessToken
case i.RefreshToken != "":
token = i.RefreshToken
tokenType = ims.RefreshToken
case i.DeviceToken != "":
token = i.DeviceToken
tokenType = ims.DeviceToken
case i.AuthorizationCode != "":
token = i.AuthorizationCode
tokenType = ims.AuthorizationCode
default:
token, tokenType, err := i.resolveToken()
if err != nil {
return TokenInfo{}, fmt.Errorf("unexpected error, broken validation")
}

Expand Down