Skip to content

Commit 7695310

Browse files
authored
feat: Support sync test connection API tokens (#135)
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)
1 parent 107e98f commit 7695310

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

auth/token.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ import (
1414
)
1515

1616
const (
17-
FirebaseAPIKey = "AIzaSyCxsrwjABEF-dWLzUqmwiL-ct02cnG9GCs"
18-
TokenBaseURL = "https://securetoken.googleapis.com"
19-
EnvVarCloudQueryAPIKey = "CLOUDQUERY_API_KEY"
20-
ExpiryBuffer = 60 * time.Second
21-
tokenFilePath = "cloudquery/token"
22-
syncRunAPIKeyPrefix = "cqsr_"
17+
FirebaseAPIKey = "AIzaSyCxsrwjABEF-dWLzUqmwiL-ct02cnG9GCs"
18+
TokenBaseURL = "https://securetoken.googleapis.com"
19+
EnvVarCloudQueryAPIKey = "CLOUDQUERY_API_KEY"
20+
ExpiryBuffer = 60 * time.Second
21+
tokenFilePath = "cloudquery/token"
22+
syncRunAPIKeyPrefix = "cqsr_"
23+
syncTestConnectionAPIKeyPrefix = "cqstc_"
2324
)
2425

2526
type tokenResponse struct {
@@ -39,6 +40,7 @@ const (
3940
BearerToken
4041
APIKey
4142
SyncRunAPIKey
43+
SyncTestConnectionAPIKey
4244
)
4345

4446
var UndefinedToken = Token{Type: Undefined, Value: ""}
@@ -108,10 +110,14 @@ func (tc *TokenClient) GetToken() (Token, error) {
108110
// GetTokenType returns the type of token that will be returned by GetToken
109111
func (tc *TokenClient) GetTokenType() TokenType {
110112
if token := os.Getenv(EnvVarCloudQueryAPIKey); token != "" {
111-
if strings.HasPrefix(token, syncRunAPIKeyPrefix) {
113+
switch {
114+
case strings.HasPrefix(token, syncRunAPIKeyPrefix):
112115
return SyncRunAPIKey
116+
case strings.HasPrefix(token, syncTestConnectionAPIKeyPrefix):
117+
return SyncTestConnectionAPIKey
118+
default:
119+
return APIKey
113120
}
114-
return APIKey
115121
}
116122
return BearerToken
117123
}

0 commit comments

Comments
 (0)