Skip to content

Commit

Permalink
feat: Support sync test connection API tokens (#135)
Browse files Browse the repository at this point in the history
Similar to #109

Testing a connection is very similar to running a sync job, just with a different CLI command and permissions.
It needs an API token to be able to download plugins and update the status of the test (it won't have access to update usage and progress line sync run API tokens)
  • Loading branch information
erezrokah authored Mar 15, 2024
1 parent 107e98f commit 7695310
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions auth/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import (
)

const (
FirebaseAPIKey = "AIzaSyCxsrwjABEF-dWLzUqmwiL-ct02cnG9GCs"
TokenBaseURL = "https://securetoken.googleapis.com"
EnvVarCloudQueryAPIKey = "CLOUDQUERY_API_KEY"
ExpiryBuffer = 60 * time.Second
tokenFilePath = "cloudquery/token"
syncRunAPIKeyPrefix = "cqsr_"
FirebaseAPIKey = "AIzaSyCxsrwjABEF-dWLzUqmwiL-ct02cnG9GCs"
TokenBaseURL = "https://securetoken.googleapis.com"
EnvVarCloudQueryAPIKey = "CLOUDQUERY_API_KEY"
ExpiryBuffer = 60 * time.Second
tokenFilePath = "cloudquery/token"
syncRunAPIKeyPrefix = "cqsr_"
syncTestConnectionAPIKeyPrefix = "cqstc_"
)

type tokenResponse struct {
Expand All @@ -39,6 +40,7 @@ const (
BearerToken
APIKey
SyncRunAPIKey
SyncTestConnectionAPIKey
)

var UndefinedToken = Token{Type: Undefined, Value: ""}
Expand Down Expand Up @@ -108,10 +110,14 @@ func (tc *TokenClient) GetToken() (Token, error) {
// GetTokenType returns the type of token that will be returned by GetToken
func (tc *TokenClient) GetTokenType() TokenType {
if token := os.Getenv(EnvVarCloudQueryAPIKey); token != "" {
if strings.HasPrefix(token, syncRunAPIKeyPrefix) {
switch {
case strings.HasPrefix(token, syncRunAPIKeyPrefix):
return SyncRunAPIKey
case strings.HasPrefix(token, syncTestConnectionAPIKeyPrefix):
return SyncTestConnectionAPIKey
default:
return APIKey
}
return APIKey
}
return BearerToken
}
Expand Down

0 comments on commit 7695310

Please sign in to comment.