-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Profile subcommand to export bearer token (#51)
- Loading branch information
1 parent
d403c95
commit 31ccdb1
Showing
3 changed files
with
51 additions
and
7 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
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,42 @@ | ||
package profile | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/urfave/cli/v2" | ||
|
||
"github.com/spacelift-io/spacectl/internal/cmd" | ||
) | ||
|
||
func exportTokenCommand() *cli.Command { | ||
return &cli.Command{ | ||
Name: "export-token", | ||
Usage: "Prints the current token to stdout. In order not to leak, " + | ||
"we suggest piping it to your OS pastebin", | ||
ArgsUsage: cmd.EmptyArgsUsage, | ||
Action: func(ctx *cli.Context) error { | ||
currentProfile := manager.Current() | ||
if currentProfile == nil { | ||
return errors.New("no account is currently selected") | ||
} | ||
|
||
session, err := currentProfile.Credentials.Session(ctx.Context, http.DefaultClient) | ||
if err != nil { | ||
return fmt.Errorf("could not get session: %w", err) | ||
} | ||
|
||
token, err := session.BearerToken(ctx.Context) | ||
if err != nil { | ||
return fmt.Errorf("could not get bearer token: %w", err) | ||
} | ||
|
||
if _, err = fmt.Print(token); err != nil { | ||
return fmt.Errorf("could not print token: %w", err) | ||
} | ||
|
||
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