Skip to content

Commit

Permalink
feat: Use and expose api url env variable (#159)
Browse files Browse the repository at this point in the history
Use `CLOUDQUERY_API_URL` for everything. Other consumers can now also use `managedplugin.APIBaseURL()`

Breaking compatibility very briefly (string becomes a func for a cq-internal functionality) so I'm not doing a `feat!`
  • Loading branch information
disq authored Nov 10, 2023
1 parent e475ca6 commit ec64db6
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions managedplugin/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,20 @@ const (
DefaultDownloadDir = ".cq"
RetryAttempts = 5
RetryWaitTime = 1 * time.Second
APIBaseURL = "https://api.cloudquery.io"
)

func APIBaseURL() string {
const (
envAPIURL = "CLOUDQUERY_API_URL"
apiBaseURL = "https://api.cloudquery.io"
)

if v := os.Getenv(envAPIURL); v != "" {
return v
}
return apiBaseURL
}

// getURLLocation return the URL of the plugin
// this does a few HEAD requests because we had a few breaking changes to where
// we store the plugins on GitHub
Expand Down Expand Up @@ -97,7 +108,7 @@ func DownloadPluginFromHub(ctx context.Context, authToken, localPath, team, name
return http.ErrUseLastResponse
},
}
c, err := cloudquery_api.NewClient(APIBaseURL, cloudquery_api.WithRequestEditorFn(func(ctx context.Context, req *http.Request) error {
c, err := cloudquery_api.NewClient(APIBaseURL(), cloudquery_api.WithRequestEditorFn(func(ctx context.Context, req *http.Request) error {
if authToken != "" {
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", authToken))
}
Expand Down

0 comments on commit ec64db6

Please sign in to comment.