-
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-11671] - add get datasources api key command (#268)
- Loading branch information
1 parent
488c5c1
commit 3363b25
Showing
6 changed files
with
88 additions
and
10 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 getDatasourcesAPIKeyCmd = &cobra.Command{ | ||
Use: "get-datasources-api-key", | ||
Short: "Get the API key for datasources", | ||
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 = fetchDatasourcesAPIKey(tenant); err != nil { | ||
return err | ||
} | ||
|
||
ui.QuietWriter.Println(apiToken.ApiKey) | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
func fetchDatasourcesAPIKey(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 apiToken *auth.ApiKey | ||
if apiToken, err = apiClient.GetDatasourcesAPIKey(tenant); err != nil { | ||
return nil, err | ||
} | ||
|
||
return apiToken, nil | ||
} | ||
|
||
func init() { | ||
AuthCmd.AddCommand(getDatasourcesAPIKeyCmd) | ||
} |
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 was deleted.
Oops, something went wrong.