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:
parent
c1374a5c10
commit
98f16fc97c
@ -52,6 +52,9 @@ type Client interface {
|
|||||||
// IsRootTicket returns true if the authenticator is configured to use the root directly using a login ticket.
|
// 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)
|
// (root using token is weaker, cannot change VM arch)
|
||||||
IsRootTicket() bool
|
IsRootTicket() bool
|
||||||
|
|
||||||
|
// HTTP returns a lower-level HTTP client.
|
||||||
|
HTTP() *http.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connection represents a connection to the Proxmox Virtual Environment API.
|
// Connection represents a connection to the Proxmox Virtual Environment API.
|
||||||
@ -298,6 +301,10 @@ func (c *client) IsRootTicket() bool {
|
|||||||
return c.auth.IsRootTicket()
|
return c.auth.IsRootTicket()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *client) HTTP() *http.Client {
|
||||||
|
return c.conn.httpClient
|
||||||
|
}
|
||||||
|
|
||||||
// validateResponseCode ensures that a response is valid.
|
// validateResponseCode ensures that a response is valid.
|
||||||
func validateResponseCode(res *http.Response) error {
|
func validateResponseCode(res *http.Response) error {
|
||||||
if res.StatusCode < 200 || res.StatusCode >= 300 {
|
if res.StatusCode < 200 || res.StatusCode >= 300 {
|
||||||
|
@ -739,7 +739,7 @@ func fileRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.D
|
|||||||
|
|
||||||
readFileAttrs := readFile
|
readFileAttrs := readFile
|
||||||
if fileIsURL(d) {
|
if fileIsURL(d) {
|
||||||
readFileAttrs = readURL
|
readFileAttrs = readURL(capi.API().HTTP())
|
||||||
}
|
}
|
||||||
|
|
||||||
var diags diag.Diagnostics
|
var diags diag.Diagnostics
|
||||||
@ -838,48 +838,55 @@ func readFile(
|
|||||||
|
|
||||||
//nolint:nonamedreturns
|
//nolint:nonamedreturns
|
||||||
func readURL(
|
func readURL(
|
||||||
|
httClient *http.Client,
|
||||||
|
) func(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
sourceFilePath string,
|
sourceFilePath string,
|
||||||
) (fileModificationDate string, fileSize int64, fileTag string, err error) {
|
) (fileModificationDate string, fileSize int64, fileTag string, err error) {
|
||||||
res, err := http.Head(sourceFilePath)
|
return func(
|
||||||
if err != nil {
|
ctx context.Context,
|
||||||
return
|
sourceFilePath string,
|
||||||
}
|
) (fileModificationDate string, fileSize int64, fileTag string, err error) {
|
||||||
|
res, err := httClient.Head(sourceFilePath)
|
||||||
defer utils.CloseOrLogError(ctx)(res.Body)
|
|
||||||
|
|
||||||
fileSize = res.ContentLength
|
|
||||||
httpLastModified := res.Header.Get("Last-Modified")
|
|
||||||
|
|
||||||
if httpLastModified != "" {
|
|
||||||
var timeParsed time.Time
|
|
||||||
timeParsed, err = time.Parse(time.RFC1123, httpLastModified)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
timeParsed, err = time.Parse(time.RFC1123Z, httpLastModified)
|
return
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fileModificationDate = timeParsed.UTC().Format(time.RFC3339)
|
defer utils.CloseOrLogError(ctx)(res.Body)
|
||||||
}
|
|
||||||
|
|
||||||
httpTag := res.Header.Get("ETag")
|
fileSize = res.ContentLength
|
||||||
|
httpLastModified := res.Header.Get("Last-Modified")
|
||||||
|
|
||||||
if httpTag != "" {
|
if httpLastModified != "" {
|
||||||
httpTagParts := strings.Split(httpTag, "\"")
|
var timeParsed time.Time
|
||||||
|
timeParsed, err = time.Parse(time.RFC1123, httpLastModified)
|
||||||
|
|
||||||
if len(httpTagParts) > 1 {
|
if err != nil {
|
||||||
fileTag = httpTagParts[1]
|
timeParsed, err = time.Parse(time.RFC1123Z, httpLastModified)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fileModificationDate = timeParsed.UTC().Format(time.RFC3339)
|
||||||
|
}
|
||||||
|
|
||||||
|
httpTag := res.Header.Get("ETag")
|
||||||
|
|
||||||
|
if httpTag != "" {
|
||||||
|
httpTagParts := strings.Split(httpTag, "\"")
|
||||||
|
|
||||||
|
if len(httpTagParts) > 1 {
|
||||||
|
fileTag = httpTagParts[1]
|
||||||
|
} else {
|
||||||
|
fileTag = ""
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
fileTag = ""
|
fileTag = ""
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
fileTag = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func fileDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func fileDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
|
Loading…
Reference in New Issue
Block a user