Skip to content

Commit

Permalink
fix(namespace_file): handle trailing slash for deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
Skraye committed Dec 3, 2024
1 parent 281ea39 commit f37816a
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions internal/provider/resource_namespace_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,16 @@ func resourceNamespaceFileCreate(ctx context.Context, d *schema.ResourceData, me
return diag.FromErr(err)
}

filename = d.Get("filename").(string)
filename = d.Get("filename").(string)

// Check if filename starts with a "/"
if !strings.HasPrefix(filename, "/") {
filename = "/" + filename
}
// Check if filename starts with a "/"
if !strings.HasPrefix(filename, "/") {
filename = "/" + filename
}

if err := d.Set("filename", filename); err != nil {
return diag.FromErr(err)
}
if err := d.Set("filename", filename); err != nil {
return diag.FromErr(err)
}

if err := d.Set("content", content); err != nil {
return diag.FromErr(err)
Expand Down Expand Up @@ -153,6 +153,10 @@ func resourceNamespaceFileDelete(ctx context.Context, d *schema.ResourceData, me
namespace, filename := namespaceFileConvertId(d.Id())
tenantId := c.TenantId

if !strings.HasPrefix(filename, "/") {
filename = "/" + filename
}

url := fmt.Sprintf("%s/namespaces/%s/files?path=%s", apiRoot(tenantId), namespace, filename)

_, reqErr := c.request("DELETE", url, nil)
Expand Down

0 comments on commit f37816a

Please sign in to comment.