-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sc-11670] - add call to createclienttoken (#267)
- Loading branch information
1 parent
cd022c1
commit 488c5c1
Showing
6 changed files
with
92 additions
and
29 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,52 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"groundcover.com/pkg/api" | ||
"groundcover.com/pkg/auth" | ||
"groundcover.com/pkg/ui" | ||
) | ||
|
||
var generateClientTokenCmd = &cobra.Command{ | ||
Use: "generate-client-token", | ||
Short: "Get Client Token for Grafana API", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
var err error | ||
|
||
var tenant *api.TenantInfo | ||
if tenant, err = fetchTenant(); err != nil { | ||
return err | ||
} | ||
|
||
var apiToken *auth.ApiKey | ||
if apiToken, err = fetchClientToken(tenant); err != nil { | ||
return err | ||
} | ||
|
||
ui.QuietWriter.Println(apiToken.ApiKey) | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
func fetchClientToken(tenant *api.TenantInfo) (*auth.ApiKey, error) { | ||
var err error | ||
|
||
var auth0Token *auth.Auth0Token | ||
if auth0Token, err = auth.LoadAuth0Token(); err != nil { | ||
return nil, err | ||
} | ||
|
||
apiClient := api.NewClient(auth0Token) | ||
|
||
var clientToken *auth.ApiKey | ||
if clientToken, err = apiClient.GetOrCreateClientToken(tenant); err != nil { | ||
return nil, err | ||
} | ||
|
||
return clientToken, nil | ||
} | ||
|
||
func init() { | ||
AuthCmd.AddCommand(generateClientTokenCmd) | ||
} |
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
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,5 @@ | ||
package auth | ||
|
||
const ( | ||
GENERATE_CLIENT_TOKEN_API_KEY_ENDPOINT = "system/generate-client-token" | ||
) |