-
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.
Merge remote-tracking branch 'origin/main' into maxlevin/sc-11671/cli…
…-add-call-to-getdatasourcesapikey
- Loading branch information
Showing
5 changed files
with
85 additions
and
4 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