Skip to content

Commit

Permalink
ec_extension: fix upload request wrapper to get filePath string
Browse files Browse the repository at this point in the history
  • Loading branch information
snowhork committed Jan 4, 2021
1 parent 31a44fb commit e7e1343
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ec/ecresource/extensionresource/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func createResource(ctx context.Context, d *schema.ResourceData, meta interface{
d.SetId(*model.ID)

if _, ok := d.GetOk("file_path"); ok {
if err := uploadRequest(client, d); err != nil {
if err := uploadRequest(client, d.Get("file_path").(string)); err != nil {
return diag.FromErr(multierror.NewPrefixed("failed to upload file", err))
}
}
Expand Down
6 changes: 3 additions & 3 deletions ec/ecresource/extensionresource/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ func deleteRequest(client *api.API, d *schema.ResourceData) error {
return nil
}

func uploadRequest(client *api.API, d *schema.ResourceData) error {
reader, err := os.Open(d.Get("file_path").(string))
func uploadRequest(client *api.API, filePath string) error {
reader, err := os.Open(filePath)
if err != nil {
return multierror.NewPrefixed("failed open file", err)
}

if _, err := client.V1API.Extensions.UploadExtension(
extensions.NewUploadExtensionParams().WithExtensionID(d.Id()).
WithFile(runtime.NamedReader(d.Get("file_path").(string), reader)),
WithFile(runtime.NamedReader(filePath, reader)),
client.AuthWriter); err != nil {
return apierror.Wrap(err)
}
Expand Down
2 changes: 1 addition & 1 deletion ec/ecresource/extensionresource/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func updateResource(ctx context.Context, d *schema.ResourceData, meta interface{
}

if _, ok := d.GetOk("file_path"); ok && d.HasChange("file_hash") {
if err := uploadRequest(client, d); err != nil {
if err := uploadRequest(client, d.Get("file_path").(string)); err != nil {
return diag.FromErr(multierror.NewPrefixed("failed to upload file", err))
}
}
Expand Down

0 comments on commit e7e1343

Please sign in to comment.