Skip to content

Commit

Permalink
Remove the ability to override the access token per operation.
Browse files Browse the repository at this point in the history
Prepares us for expanding the access token options on the profile level.
  • Loading branch information
bojanz committed Dec 23, 2021
1 parent 8a46ad2 commit b4a5a49
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ broom staging list-products

## Authentication

An access token can be set on the profile (via `broom add --token`) or provided per-operation (via `broom --token`).
This is the usual way of sending API keys.
An access token can be set on the profile via `broom add --token`. This is the usual way of sending API keys.

For more advanced use cases, Broom supports fetching an access token through an external command:
```
Expand Down
20 changes: 8 additions & 12 deletions cmd/broom/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func profileCmd(args []string) {
help = flags.BoolP("help", "h", false, "Display this help text and exit")
body = flags.StringP("body", "b", "", "Body string, containing one or more body parameters")
query = flags.StringP("query", "q", "", "Query string, containing one or more query parameters")
token = flags.StringP("token", "t", "", "Access token. Overrides the one from the profile")
verbose = flags.BoolP("verbose", "v", false, "Print the HTTP status and headers hefore the response body")
)
flags.Usage = func() {
Expand Down Expand Up @@ -92,15 +91,12 @@ func profileCmd(args []string) {
fmt.Fprintln(os.Stderr, "Error:", err)
os.Exit(1)
}
if *token == "" {
// No access token specified, take it from the profile.
*token = profileCfg.Token
if profileCfg.TokenCmd != "" {
*token, err = broom.RetrieveToken(profileCfg.TokenCmd)
if err != nil {
fmt.Fprintln(os.Stderr, "Error:", err)
os.Exit(1)
}
token := profileCfg.Token
if profileCfg.TokenCmd != "" {
token, err = broom.RetrieveToken(profileCfg.TokenCmd)
if err != nil {
fmt.Fprintln(os.Stderr, "Error:", err)
os.Exit(1)
}
}

Expand All @@ -112,8 +108,8 @@ func profileCmd(args []string) {
if operation.HasBody() {
req.Header.Set("Content-Type", operation.BodyFormat)
}
if *token != "" {
req.Header.Set("Authorization", fmt.Sprintf("Bearer %v", *token))
if token != "" {
req.Header.Set("Authorization", fmt.Sprintf("Bearer %v", token))
}
for _, header := range *headers {
kv := strings.SplitN(header, ":", 2)
Expand Down

0 comments on commit b4a5a49

Please sign in to comment.