Skip to content

Commit

Permalink
fix: Verify auth before persisting
Browse files Browse the repository at this point in the history
  • Loading branch information
abhisek committed Oct 11, 2024
1 parent bda53d0 commit 0df9261
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 8 additions & 0 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ func configureAuthCommand() *cobra.Command {
}
}

auth.SetRuntimeCloudTenant(authTenantDomain)
auth.SetRuntimeApiKey(key)

err = auth.Verify()
if err != nil {
logger.Fatalf("Failed to verify auth: %v", err)
}

err = auth.PersistApiKey(key, authTenantDomain)
if err != nil {
logger.Fatalf("Failed to configure auth: %v", err)
Expand Down
8 changes: 6 additions & 2 deletions internal/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (

const (
apiUrlEnvKey = "VET_INSIGHTS_API_URL"
apiKeyEnvKey = "VET_INSIGHTS_API_KEY"
apiKeyAlternateEnvKey = "VET_API_KEY"
apiKeyEnvKey = "VET_API_KEY"
apiKeyAlternateEnvKey = "VET_INSIGHTS_API_KEY"
communityModeEnvKey = "VET_COMMUNITY_MODE"
controlTowerTenantEnvKey = "VET_CONTROL_TOWER_TENANT_ID"

Expand Down Expand Up @@ -236,6 +236,10 @@ func SetRuntimeCloudTenant(domain string) {
os.Setenv(controlTowerTenantEnvKey, domain)
}

func SetRuntimeApiKey(key string) {
os.Setenv(apiKeyEnvKey, key)
}

func loadConfiguration() error {
path, err := os.UserHomeDir()
if err != nil {
Expand Down

0 comments on commit 0df9261

Please sign in to comment.