Skip to content

Commit

Permalink
fix: pass ctx
Browse files Browse the repository at this point in the history
  • Loading branch information
tenstad committed Apr 14, 2024
1 parent ef58def commit 3767ac4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions internal/provider/remote_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package provider

import (
"bytes"
"context"
"fmt"
"strings"

Expand Down Expand Up @@ -40,21 +41,21 @@ type RemoteClient struct {
sshClient *ssh.Client
}

func (c *RemoteClient) WriteFile(content string, path string, permissions string, sudo bool) error {
func (c *RemoteClient) WriteFile(ctx context.Context, content string, path string, permissions string, sudo bool) error {
if sudo {
return c.WriteFileShell(content, path)
}
return c.WriteFileSCP(content, path, permissions)
return c.WriteFileSCP(ctx, content, path, permissions)
}

func (c *RemoteClient) WriteFileSCP(content string, path string, permissions string) error {
func (c *RemoteClient) WriteFileSCP(ctx context.Context, content string, path string, permissions string) error {
scpClient, err := c.GetSCPClient()
if err != nil {
return err
}
defer scpClient.Close()

return scpClient.CopyFile(strings.NewReader(content), path, permissions)
return scpClient.CopyFile(ctx, strings.NewReader(content), path, permissions)
}

func (c *RemoteClient) WriteFileShell(content string, path string) error {
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/resource_remote_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func resourceRemoteFileCreate(ctx context.Context, d *schema.ResourceData, meta
owner = d.Get("owner_name").(string)
}

err = client.WriteFile(content, path, permissions, sudo)
err = client.WriteFile(ctx, content, path, permissions, sudo)
if err != nil {
return diag.Errorf("unable to create remote file: %s", err.Error())
}
Expand Down

0 comments on commit 3767ac4

Please sign in to comment.