Skip to content

Commit

Permalink
Use existing HTTPClient
Browse files Browse the repository at this point in the history
  • Loading branch information
BartoszBlizniak committed Jun 13, 2023
1 parent 6b494d8 commit be27499
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions cloudsmith/data_source_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func dataSourcePackageRead(d *schema.ResourceData, m interface{}) error {
d.SetId(fmt.Sprintf("%s_%s_%s", namespace, repository, pkg.GetSlugPerm()))

if download {
outputPath, err := downloadPackage(pkg.GetCdnUrl(), downloadDir, pc.GetAPIKey())
outputPath, err := downloadPackage(pkg.GetCdnUrl(), downloadDir, pc)
if err != nil {
return err
}
Expand All @@ -54,15 +54,15 @@ func dataSourcePackageRead(d *schema.ResourceData, m interface{}) error {
return nil
}

func downloadPackage(url string, downloadDir string, apiKey string) (string, error) {
func downloadPackage(url string, downloadDir string, pc *providerConfig) (string, error) {
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return "", err
}

req.Header.Add("Authorization", fmt.Sprintf("Token %s", apiKey))
req.Header.Add("Authorization", fmt.Sprintf("Token %s", pc.GetAPIKey()))

client := &http.Client{}
client := pc.APIClient.GetConfig().HTTPClient
resp, err := client.Do(req)
if err != nil {
return "", err
Expand Down

0 comments on commit be27499

Please sign in to comment.