Skip to content

Commit

Permalink
not sure what else I forgot... 🤔
Browse files Browse the repository at this point in the history
  • Loading branch information
bpg committed May 24, 2023
1 parent d460443 commit 15653f6
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 48 deletions.
5 changes: 0 additions & 5 deletions proxmox/api/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ import (
"github.com/bpg/terraform-provider-proxmox/proxmox/helper"
)

const (
// DefaultRootAccount contains the default username and realm for the root account.
defaultRootAccount = "root@pam"
)

// Authenticate authenticates against the specified endpoint.
func (c *client) Authenticate(ctx context.Context, reset bool) error {
if c.authenticationData != nil && !reset {
Expand Down
2 changes: 1 addition & 1 deletion proxmox/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func (c *client) ExpandPath(path string) string {
}

func (c *client) IsRoot() bool {
return c.username == defaultRootAccount
return c.username == "root@pam"
}

// validateResponseCode ensures that a response is valid.
Expand Down
12 changes: 6 additions & 6 deletions proxmox/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ type API interface {
// Version returns a client for getting the version of the Proxmox Virtual Environment API.
Version() *version.Client

// RESTAPI returns a lower-lever REST API client.
RESTAPI() api.Client
// REST returns a lower-lever REST API client.
REST() api.Client

// SSHAPI returns a lower-lever SSH client.
SSHAPI() ssh.Client
// SSH returns a lower-lever SSH client.
SSH() ssh.Client
}

// Client is an implementation of the Proxmox Virtual Environment API.
Expand Down Expand Up @@ -86,11 +86,11 @@ func (c *Client) Version() *version.Client {
}

// RESTAPI returns a lower-lever REST API client.
func (c *Client) RESTAPI() api.Client {
func (c *Client) REST() api.Client {
return c.a
}

// SSHAPI returns a lower-lever SSH client.s.
func (c *Client) SSHAPI() ssh.Client {
func (c *Client) SSH() ssh.Client {
return c.s
}
28 changes: 3 additions & 25 deletions proxmoxtf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,41 +31,19 @@ func NewProviderConfiguration(
}
}

// GetAPIClient returns the virtual environment client.
// Deprecated: Use API() instead.
func (c *ProviderConfiguration) GetAPIClient() (api.Client, error) {
// GetAPI returns the Proxmox API client.
func (c *ProviderConfiguration) GetAPI() (proxmox.API, error) {
if c.apiClient == nil {
return nil, errors.New(
"you must specify the API access details in the provider configuration",
)
}

return c.apiClient, nil
}

// GetSSHClient returns the SSH client.
// Deprecated: Use API() instead.
func (c *ProviderConfiguration) GetSSHClient() (ssh.Client, error) {
if c.sshClient == nil {
return nil, errors.New(
"you must specify the SSH access details in the provider configuration",
)
}

return c.sshClient, nil
}

// GetAPI returns the Proxmox API client.
func (c *ProviderConfiguration) GetAPI() (proxmox.API, error) {
a, err := c.GetAPIClient()
if err != nil {
return nil, err
}

s, err := c.GetSSHClient()
if err != nil {
return nil, err
}

return proxmox.NewClient(a, s), nil
return proxmox.NewClient(c.apiClient, c.sshClient), nil
}
2 changes: 1 addition & 1 deletion proxmoxtf/resource/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ func fileCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag

remoteFileDir := *datastore.Path

return diag.FromErr(capi.SSHAPI().NodeUpload(ctx, nodeAddress, remoteFileDir, request))
return diag.FromErr(capi.SSH().NodeUpload(ctx, nodeAddress, remoteFileDir, request))
}

if err != nil {
Expand Down
15 changes: 5 additions & 10 deletions proxmoxtf/resource/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,7 @@ func vmCreateClone(ctx context.Context, d *schema.ResourceData, m interface{}) d
}

// Only the root account is allowed to change the CPU architecture, which makes this check necessary.
if api.RESTAPI().IsRoot() ||
if api.REST().IsRoot() ||
cpuArchitecture != dvResourceVirtualEnvironmentVMCPUArchitecture {
updateBody.CPUArchitecture = &cpuArchitecture
}
Expand Down Expand Up @@ -2050,7 +2050,7 @@ func vmCreateCustom(ctx context.Context, d *schema.ResourceData, m interface{})
}

// Only the root account is allowed to change the CPU architecture, which makes this check necessary.
if api.RESTAPI().IsRoot() ||
if api.REST().IsRoot() ||
cpuArchitecture != dvResourceVirtualEnvironmentVMCPUArchitecture {
createBody.CPUArchitecture = &cpuArchitecture
}
Expand Down Expand Up @@ -2238,12 +2238,7 @@ func vmCreateCustomDisks(ctx context.Context, d *schema.ResourceData, m interfac
return diag.FromErr(err)
}

sshClient, err := config.GetSSHClient()
if err != nil {
return diag.FromErr(err)
}

err = sshClient.ExecuteNodeCommands(ctx, nodeAddress, commands)
err = api.SSH().ExecuteNodeCommands(ctx, nodeAddress, commands)
if err != nil {
return diag.FromErr(err)
}
Expand Down Expand Up @@ -2968,7 +2963,7 @@ func vmReadCustom(
} else {
// Default value of "arch" is "" according to the API documentation.
// However, assume the provider's default value as a workaround when the root account is not being used.
if !api.RESTAPI().IsRoot() {
if !api.REST().IsRoot() {
cpu[mkResourceVirtualEnvironmentVMCPUArchitecture] = dvResourceVirtualEnvironmentVMCPUArchitecture
} else {
cpu[mkResourceVirtualEnvironmentVMCPUArchitecture] = ""
Expand Down Expand Up @@ -4163,7 +4158,7 @@ func vmUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.D
cpuUnits := cpuBlock[mkResourceVirtualEnvironmentVMCPUUnits].(int)

// Only the root account is allowed to change the CPU architecture, which makes this check necessary.
if api.RESTAPI().IsRoot() ||
if api.REST().IsRoot() ||
cpuArchitecture != dvResourceVirtualEnvironmentVMCPUArchitecture {
updateBody.CPUArchitecture = &cpuArchitecture
}
Expand Down

0 comments on commit 15653f6

Please sign in to comment.