77 "net/http"
88 "net/url"
99 "os"
10+ "strings"
1011 "time"
1112
1213 "github.com/cloudquery/cloudquery-api-go/config"
@@ -18,6 +19,7 @@ const (
1819 EnvVarCloudQueryAPIKey = "CLOUDQUERY_API_KEY"
1920 ExpiryBuffer = 60 * time .Second
2021 tokenFilePath = "cloudquery/token"
22+ syncRunAPIKeyPrefix = "cqsr_"
2123)
2224
2325type tokenResponse struct {
@@ -36,6 +38,7 @@ const (
3638 Undefined TokenType = iota
3739 BearerToken
3840 APIKey
41+ SyncRunAPIKey
3942)
4043
4144var UndefinedToken = Token {Type : Undefined , Value : "" }
@@ -66,8 +69,9 @@ func NewTokenClient() *TokenClient {
6669// GetToken returns the ID token
6770// If CLOUDQUERY_API_KEY is set, it returns that value, otherwise it returns an ID token generated from the refresh token.
6871func (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
7175 }
7276
7377 // If the token is not expired, return it
@@ -104,6 +108,9 @@ func (tc *TokenClient) GetToken() (Token, error) {
104108// GetTokenType returns the type of token that will be returned by GetToken
105109func (tc * TokenClient ) GetTokenType () TokenType {
106110 if token := os .Getenv (EnvVarCloudQueryAPIKey ); token != "" {
111+ if strings .HasPrefix (token , syncRunAPIKeyPrefix ) {
112+ return SyncRunAPIKey
113+ }
107114 return APIKey
108115 }
109116 return BearerToken
0 commit comments