mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-07-01 19:12:59 +00:00
* feat(core): add query url metadata endpoint to nodes client api Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * feat(core): move storage api code to nodestorage folder Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * feat(core): add download url api Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * feat(storage): add resource_download_file Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * feat(storage): finish new resource_download_file Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * feat(storage): generate docs for new download file resource, update other docs and examples Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * feat(storage): add basic acc tests for resource download_file Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * fix(test): lint new test file Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * feat(storage): warning instead of error when file already exists on resource download file Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * feat(storage): better validation in resource download file, delete upload task on error Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * feat(storage): better err message in resource download file Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * fix(core): removed unnecessary toint in custom type bool Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * fix(storage): typo in resource download file error Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * feat(storage): download file resource review - 1 Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * feat(storage): finish resource download file after review Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * fix(storage): error instead of warnings in parse int errors in sizeRequiresReplaceModifier Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * fix(docs): remove unwanted changes in virtual_environment_file.md Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * fix(test): fix download file base acceptance tests Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * fix(test): fix resource download file acc tests Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * fix(test): last fix resource download file acc test Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> * fix: use PVE-compatible jammy LXC image, fix few typos Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --------- Signed-off-by: Rafał Safin <rafal.safin@rafsaf.pl> Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Co-authored-by: Rafał Safin <rafal.safin@rafsaf.pl> Co-authored-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
/*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
package storage
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/bpg/terraform-provider-proxmox/proxmox/api"
|
|
)
|
|
|
|
// DownloadFileByURL downloads the file using URL.
|
|
func (c *Client) DownloadFileByURL(
|
|
ctx context.Context,
|
|
d *DownloadURLPostRequestBody,
|
|
uploadTimeout int64,
|
|
) error {
|
|
resBody := &DownloadURLResponseBody{}
|
|
|
|
err := c.DoRequest(ctx, http.MethodPost, c.ExpandPath("download-url"), d, resBody)
|
|
if err != nil {
|
|
return fmt.Errorf("error download file by URL: %w", err)
|
|
}
|
|
|
|
if resBody.TaskID == nil {
|
|
return api.ErrNoDataObjectInResponse
|
|
}
|
|
|
|
taskErr := c.Tasks().WaitForTask(ctx, *resBody.TaskID, int(uploadTimeout), 5)
|
|
if taskErr != nil {
|
|
err = fmt.Errorf(
|
|
"error download file to datastore %s: failed waiting for url download - %w",
|
|
c.StorageName,
|
|
taskErr,
|
|
)
|
|
|
|
deleteErr := c.Tasks().DeleteTask(context.WithoutCancel(ctx), *resBody.TaskID)
|
|
if deleteErr != nil {
|
|
return fmt.Errorf("%w \n %w", err, deleteErr)
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|