7
7
"net/http"
8
8
"net/url"
9
9
"os"
10
+ "strings"
10
11
"time"
11
12
12
13
"github.com/cloudquery/cloudquery-api-go/config"
@@ -18,6 +19,7 @@ const (
18
19
EnvVarCloudQueryAPIKey = "CLOUDQUERY_API_KEY"
19
20
ExpiryBuffer = 60 * time .Second
20
21
tokenFilePath = "cloudquery/token"
22
+ syncRunAPIKeyPrefix = "cqsr_"
21
23
)
22
24
23
25
type tokenResponse struct {
@@ -36,6 +38,7 @@ const (
36
38
Undefined TokenType = iota
37
39
BearerToken
38
40
APIKey
41
+ SyncRunAPIKey
39
42
)
40
43
41
44
var UndefinedToken = Token {Type : Undefined , Value : "" }
@@ -66,8 +69,9 @@ func NewTokenClient() *TokenClient {
66
69
// GetToken returns the ID token
67
70
// If CLOUDQUERY_API_KEY is set, it returns that value, otherwise it returns an ID token generated from the refresh token.
68
71
func (tc * TokenClient ) GetToken () (Token , error ) {
69
- if tc .GetTokenType () == APIKey {
70
- return Token {Type : APIKey , Value : os .Getenv (EnvVarCloudQueryAPIKey )}, nil
72
+ tokenType := tc .GetTokenType ()
73
+ if tokenType != BearerToken {
74
+ return Token {Type : tokenType , Value : os .Getenv (EnvVarCloudQueryAPIKey )}, nil
71
75
}
72
76
73
77
// If the token is not expired, return it
@@ -104,6 +108,9 @@ func (tc *TokenClient) GetToken() (Token, error) {
104
108
// GetTokenType returns the type of token that will be returned by GetToken
105
109
func (tc * TokenClient ) GetTokenType () TokenType {
106
110
if token := os .Getenv (EnvVarCloudQueryAPIKey ); token != "" {
111
+ if strings .HasPrefix (token , syncRunAPIKeyPrefix ) {
112
+ return SyncRunAPIKey
113
+ }
107
114
return APIKey
108
115
}
109
116
return BearerToken
0 commit comments