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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ imscli authorize user help

The complete documentation of the project is available in the [DOCUMENTATION.md](DOCUMENTATION.md) file.

## Development Notes

### PersistentPreRunE and subcommands

The root command defines a `PersistentPreRunE` that loads configuration from flags, environment variables, and config files (see `cmd/root.go`). In cobra, if a subcommand defines its own `PersistentPreRunE`, it **overrides** the parent's — the root's `PersistentPreRunE` will not run for that subcommand or its children. If you need to add a `PersistentPreRunE` to a subcommand, you must explicitly call the parent's first.

## Contributing

Contributions are welcomed! Read the [Contributing Guide](CONTRIBUTING.md) for more information.
Expand Down
2 changes: 1 addition & 1 deletion cmd/admin/organizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func OrganizationsCmd(imsConfig *ims.Config) *cobra.Command {
},
}
cmd.Flags().StringVarP(&imsConfig.Guid, "guid", "g", "", "User ID.")
cmd.Flags().StringVarP(&imsConfig.AuthSrc, "authSrc", "s", "", "Authorization source.")
cmd.Flags().StringVarP(&imsConfig.AuthSrc, "authSrc", "A", "", "Authorization source.")
cmd.Flags().StringVarP(&imsConfig.ClientID, "clientID", "c", "", "IMS client ID.")
cmd.Flags().StringVarP(&imsConfig.ServiceToken, "serviceToken", "t", "", "Service token.")
cmd.Flags().StringVarP(&imsConfig.OrgsAPIVersion, "orgsApiVersion", "a", "v5", "Admin organizations API version.")
Expand Down
2 changes: 1 addition & 1 deletion cmd/admin/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func ProfileCmd(imsConfig *ims.Config) *cobra.Command {
},
}
cmd.Flags().StringVarP(&imsConfig.Guid, "guid", "g", "", "User ID.")
cmd.Flags().StringVarP(&imsConfig.AuthSrc, "authSrc", "s", "", "Authorization source.")
cmd.Flags().StringVarP(&imsConfig.AuthSrc, "authSrc", "A", "", "Authorization source.")
cmd.Flags().StringVarP(&imsConfig.ClientID, "clientID", "c", "", "IMS client ID.")
cmd.Flags().StringVarP(&imsConfig.ServiceToken, "serviceToken", "t", "", "Service token.")
cmd.Flags().StringVarP(&imsConfig.ProfileAPIVersion, "profileApiVersion", "a", "v1", "Admin profile API version.")
Expand Down
4 changes: 2 additions & 2 deletions cmd/authz/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ func JWTCmd(imsConfig *ims.Config) *cobra.Command {
}

cmd.Flags().StringVarP(&imsConfig.ClientID, "clientID", "c", "", "IMS Client ID.")
cmd.Flags().StringVarP(&imsConfig.ClientSecret, "clientSecret", "s", "", "IMS Client secret.")
cmd.Flags().StringVarP(&imsConfig.ClientSecret, "clientSecret", "p", "", "IMS Client secret.")
cmd.Flags().StringVarP(&imsConfig.Organization, "organization", "o", "", "IMS Organization.")
cmd.Flags().StringVarP(&imsConfig.Account, "account", "a", "", "Technical Account ID.")
cmd.Flags().StringVarP(&imsConfig.Account, "account", "A", "", "Technical Account ID.")
cmd.Flags().StringVarP(&imsConfig.PrivateKeyPath, "privateKey", "k", "", "Private Key file.")
cmd.Flags().StringSliceVarP(&imsConfig.Metascopes, "metascopes", "m", []string{}, "Metascopes to request.")

Expand Down
3 changes: 1 addition & 2 deletions cmd/authz/pkce.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ func UserPkceCmd(imsConfig *ims.Config) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true

imsConfig.PKCE = true
resp, err := imsConfig.AuthorizeUser()
resp, err := imsConfig.AuthorizeUserPKCE()
if err != nil {
return fmt.Errorf("error in user authorization: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/authz/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func ServiceCmd(imsConfig *ims.Config) *cobra.Command {

cmd.Flags().StringVarP(&imsConfig.ClientID, "clientID", "c", "", "IMS client ID.")
cmd.Flags().StringVarP(&imsConfig.ClientSecret, "clientSecret", "p", "", "IMS client secret.")
cmd.Flags().StringVarP(&imsConfig.AuthorizationCode, "authorizationCode", "a", "", "Permanent authorization code.")
cmd.Flags().StringVarP(&imsConfig.AuthorizationCode, "authorizationCode", "x", "", "Permanent authorization code.")

return cmd
}
1 change: 0 additions & 1 deletion cmd/dcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func registerCmd(imsConfig *ims.Config) *cobra.Command {
},
}

cmd.Flags().StringVarP(&imsConfig.RegisterURL, "url", "u", "", "Registration endpoint URL.")
cmd.Flags().StringVarP(&imsConfig.ClientName, "clientName", "n", "", "Client application name.")
cmd.Flags().StringSliceVarP(&imsConfig.RedirectURIs, "redirectURIs", "r", []string{}, "Redirect URIs (comma-separated or multiple flags).")

Expand Down
43 changes: 0 additions & 43 deletions cmd/invalidate/access_token.go

This file was deleted.

45 changes: 0 additions & 45 deletions cmd/invalidate/device_token.go

This file was deleted.

98 changes: 98 additions & 0 deletions cmd/invalidate/invalidate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Copyright 2021 Adobe. All rights reserved.
// This file is licensed to you under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may obtain a copy
// of the License at http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under
// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
// OF ANY KIND, either express or implied. See the License for the specific language
// governing permissions and limitations under the License.

package invalidate

import (
"fmt"

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

type tokenDef struct {
use string
alias string
label string
flagName string
field *string
successMsg string
extraFlags func(cmd *cobra.Command, imsConfig *ims.Config)
}

func tokenCmd(imsConfig *ims.Config, def tokenDef) *cobra.Command {
cmd := &cobra.Command{
Use: def.use,
Aliases: []string{def.alias},
Short: fmt.Sprintf("Invalidate %s.", def.label),
Long: fmt.Sprintf("Invalidate %s.", def.label),
RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true

err := imsConfig.InvalidateToken()
if err != nil {
return fmt.Errorf("error invalidating the %s: %w", def.label, err)
}
fmt.Println(def.successMsg)
return nil
},
}

cmd.Flags().StringVarP(def.field, def.flagName, "t", "", def.label+".")
cmd.Flags().StringVarP(&imsConfig.ClientID, "clientID", "c", "", "IMS Client ID.")
if def.extraFlags != nil {
def.extraFlags(cmd, imsConfig)
}

return cmd
}

func AccessTokenCmd(imsConfig *ims.Config) *cobra.Command {
return tokenCmd(imsConfig, tokenDef{
use: "accessToken", alias: "acc", label: "access token",
flagName: "accessToken", field: &imsConfig.AccessToken,
successMsg: "Token invalidated successfully.",
})
}

func RefreshTokenCmd(imsConfig *ims.Config) *cobra.Command {
return tokenCmd(imsConfig, tokenDef{
use: "refreshToken", alias: "ref", label: "refresh token",
flagName: "refreshToken", field: &imsConfig.RefreshToken,
successMsg: "Refresh token successfully invalidated.",
extraFlags: func(cmd *cobra.Command, c *ims.Config) {
cmd.Flags().BoolVarP(&c.Cascading, "cascading", "C", false,
"Also invalidate all tokens obtained with the refresh token.")
},
})
}

func DeviceTokenCmd(imsConfig *ims.Config) *cobra.Command {
return tokenCmd(imsConfig, tokenDef{
use: "deviceToken", alias: "dev", label: "device token",
flagName: "deviceToken", field: &imsConfig.DeviceToken,
successMsg: "Token invalidated successfully.",
extraFlags: func(cmd *cobra.Command, c *ims.Config) {
cmd.Flags().BoolVarP(&c.Cascading, "cascading", "C", false,
"Also invalidate all tokens obtained with the device token.")
},
})
}

func ServiceTokenCmd(imsConfig *ims.Config) *cobra.Command {
return tokenCmd(imsConfig, tokenDef{
use: "serviceToken", alias: "svc", label: "service token",
flagName: "serviceToken", field: &imsConfig.ServiceToken,
successMsg: "Service token successfully invalidated.",
extraFlags: func(cmd *cobra.Command, c *ims.Config) {
cmd.Flags().StringVarP(&c.ClientSecret, "clientSecret", "p", "", "IMS Client Secret.")
},
})
}
45 changes: 0 additions & 45 deletions cmd/invalidate/refresh_token.go

This file was deleted.

44 changes: 0 additions & 44 deletions cmd/invalidate/service_token.go

This file was deleted.

8 changes: 4 additions & 4 deletions cmd/refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ func refreshCmd(imsConfig *ims.Config) *cobra.Command {
return fmt.Errorf("error during the token refresh: %w", err)
}
if imsConfig.FullOutput {
data := map[string]interface{}{
"access_token": resp.AccessToken,
"refresh_token": resp.RefreshToken,
}
data := struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
}{resp.AccessToken, resp.RefreshToken}
jsonData, err := json.MarshalIndent(data, "", " ")
if err != nil {
return fmt.Errorf("error marshalling full JSON response: %w", err)
Expand Down
Loading