-
Notifications
You must be signed in to change notification settings - Fork 594
feat: support storage iso local paths #1406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import ( | |
| "io" | ||
| "net/http" | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
|
|
||
| pveSDK "github.com/Telmate/proxmox-api-go/proxmox" | ||
|
|
@@ -71,15 +72,25 @@ func resourceStorageIsoCreate(ctx context.Context, d *schema.ResourceData, meta | |
| node := d.Get("pve_node").(string) | ||
|
|
||
| client := pconf.Client | ||
| file, err := os.CreateTemp(os.TempDir(), fileName) | ||
| if err != nil { | ||
| return diag.FromErr(err) | ||
| } | ||
| err = _downloadFile(url, file) | ||
| if err != nil { | ||
| return diag.FromErr(err) | ||
|
|
||
| var file *os.File | ||
| var err error | ||
| if filepath.IsAbs(url) { | ||
| file, err = os.Open(url) | ||
| if err != nil { | ||
| return diag.FromErr(err) | ||
| } | ||
| } else { | ||
| file, err = os.CreateTemp(os.TempDir(), fileName) | ||
| if err != nil { | ||
| return diag.FromErr(err) | ||
| } | ||
| err = _downloadFile(url, file) | ||
| if err != nil { | ||
| return diag.FromErr(err) | ||
| } | ||
| file.Seek(0, 0) | ||
|
Comment on lines
+84
to
+92
|
||
| } | ||
| file.Seek(0, 0) | ||
| defer file.Close() | ||
| err = client.Upload(ctx, node, storage, isoContentType, fileName, file) | ||
| if err != nil { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic assumes any absolute path is a local file, but HTTP/HTTPS URLs also contain absolute paths (e.g., 'https://example.com/file.iso'). This will cause HTTP URLs to be treated as local file paths. Consider checking if the URL starts with a scheme like 'http://' or 'https://' instead of using
filepath.IsAbs().