0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-07-11 00:05:01 +00:00

export httpClient from the API

Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
This commit is contained in:
Pavel Boldyrev 2024-02-03 16:56:47 -05:00
parent c1374a5c10
commit 98f16fc97c
No known key found for this signature in database
GPG Key ID: 02A24794ADAC7455
2 changed files with 44 additions and 30 deletions

View File

@ -52,6 +52,9 @@ type Client interface {
// IsRootTicket returns true if the authenticator is configured to use the root directly using a login ticket.
// (root using token is weaker, cannot change VM arch)
IsRootTicket() bool
// HTTP returns a lower-level HTTP client.
HTTP() *http.Client
}
// Connection represents a connection to the Proxmox Virtual Environment API.
@ -298,6 +301,10 @@ func (c *client) IsRootTicket() bool {
return c.auth.IsRootTicket()
}
func (c *client) HTTP() *http.Client {
return c.conn.httpClient
}
// validateResponseCode ensures that a response is valid.
func validateResponseCode(res *http.Response) error {
if res.StatusCode < 200 || res.StatusCode >= 300 {

View File

@ -739,7 +739,7 @@ func fileRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.D
readFileAttrs := readFile
if fileIsURL(d) {
readFileAttrs = readURL
readFileAttrs = readURL(capi.API().HTTP())
}
var diags diag.Diagnostics
@ -838,10 +838,16 @@ func readFile(
//nolint:nonamedreturns
func readURL(
httClient *http.Client,
) func(
ctx context.Context,
sourceFilePath string,
) (fileModificationDate string, fileSize int64, fileTag string, err error) {
res, err := http.Head(sourceFilePath)
return func(
ctx context.Context,
sourceFilePath string,
) (fileModificationDate string, fileSize int64, fileTag string, err error) {
res, err := httClient.Head(sourceFilePath)
if err != nil {
return
}
@ -880,6 +886,7 @@ func readURL(
}
return
}
}
func fileDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {