diff --git a/internal/authorization/resource.go b/internal/authorization/resource.go index 92e27ef..20ec4eb 100644 --- a/internal/authorization/resource.go +++ b/internal/authorization/resource.go @@ -763,8 +763,14 @@ func updateUsers(ctx context.Context, hostConfig apiclient.HostConfig, data, cur continue } else { tflog.Info(ctx, fmt.Sprintf("User %s created", user.Username.ValueString())) - updateUserClaims(ctx, hostConfig, data, currentData, i) - updateUserRoles(ctx, hostConfig, data, currentData, i) + if diag := updateUserClaims(ctx, hostConfig, data, currentData, i); diag.HasError() { + diagnostics.Append(diag...) + continue + } + if diag := updateUserRoles(ctx, hostConfig, data, currentData, i); diag.HasError() { + diagnostics.Append(diag...) + continue + } data.Users[i].Id = types.StringValue(response.ID) } } else { @@ -779,8 +785,14 @@ func updateUsers(ctx context.Context, hostConfig apiclient.HostConfig, data, cur continue } tflog.Info(ctx, fmt.Sprintf("User %s found, updating id %v", userExists.Name, userExists.ID)) - updateUserClaims(ctx, hostConfig, data, currentData, i) - updateUserRoles(ctx, hostConfig, data, currentData, i) + if diag := updateUserClaims(ctx, hostConfig, data, currentData, i); diag.HasError() { + diagnostics.Append(diag...) + continue + } + if diag := updateUserRoles(ctx, hostConfig, data, currentData, i); diag.HasError() { + diagnostics.Append(diag...) + continue + } data.Users[i].Id = types.StringValue(userExists.ID) } } diff --git a/internal/deploy/api_service_template.go b/internal/deploy/api_service_template.go deleted file mode 100644 index 8fd98a7..0000000 --- a/internal/deploy/api_service_template.go +++ /dev/null @@ -1,94 +0,0 @@ -package deploy - -import ( - "bytes" - "text/template" -) - -var apiServiceTemplate = ` - - - - UserName - root - Label - com.parallels.api-service - ProgramArguments - - {{ .Path }}/pd-api-service - --port={{ .Port }} - - EnvironmentVariables - - ROOT_PASSWORD - {{ .RootPassword }} - SECURITY_PRIVATE_KEY - {{ .EncryptionRsaKey }} - HMAC_SECRET - {{ .HmacSecret }} - LOG_LEVEL - {{ .LogLevel }} - TLS_ENABLED - {{ .EnableTLS }} - TLS_PORT - {{ .HostTLSPort }} - TLS_CERTIFICATE - {{ .TlsCertificate }} - TLS_PRIVATE_KEY - {{ .TlsPrivateKey }} - - RunAtLoad - - KeepAlive - - StandardErrorPath - /tmp/api-service.job.err - StandardOutPath - /tmp/api-service.job.out - -"` - -type TemplateData struct { - Path string - Port string - RootPassword string - EncryptionRsaKey string - HmacSecret string - LogLevel string - EnableTLS string - HostTLSPort string - TlsCertificate string - TlsPrivateKey string -} - -func getApiServicePlist(path string, config ParallelsDesktopApiConfig) (string, error) { - // Define the text template - tmpl, err := template.New("parallels-api").Parse(apiServiceTemplate) - if err != nil { - return "", err - } - - // Execute the template with a value - var tpl bytes.Buffer - templateData := TemplateData{ - Path: path, - Port: config.Port.ValueString(), - RootPassword: config.RootPassword.ValueString(), - EncryptionRsaKey: config.EncryptionRsaKey.ValueString(), - HmacSecret: config.HmacSecret.ValueString(), - LogLevel: config.LogLevel.ValueString(), - HostTLSPort: config.TLSPort.ValueString(), - TlsCertificate: config.TLSCertificate.ValueString(), - TlsPrivateKey: config.TLSPrivateKey.ValueString(), - } - if config.EnableTLS.ValueBool() { - templateData.EnableTLS = "true" - } - - err = tmpl.Execute(&tpl, templateData) - if err != nil { - return "", err - } - - return tpl.String(), nil -} diff --git a/internal/helpers/string.go b/internal/helpers/string.go index d2d7506..8a77da9 100644 --- a/internal/helpers/string.go +++ b/internal/helpers/string.go @@ -45,12 +45,12 @@ func GetHostApiBaseUrl(host string) string { } func ConvertByteToGigabyte(bytes float64) float64 { - gb := float64(bytes) / 1024 / 1024 / 1024 + gb := bytes / 1024 / 1024 / 1024 return math.Round(gb*100) / 100 } func ConvertByteToMegabyte(bytes float64) float64 { - mb := float64(bytes) / 1024 / 1024 + mb := bytes / 1024 / 1024 return math.Round(mb*100) / 100 } diff --git a/internal/provider/provider_test.go b/internal/provider/provider_test.go index ef6599b..9e2bac7 100644 --- a/internal/provider/provider_test.go +++ b/internal/provider/provider_test.go @@ -3,23 +3,23 @@ package provider -import ( - "testing" +// import ( +// "testing" - "github.com/hashicorp/terraform-plugin-framework/providerserver" - "github.com/hashicorp/terraform-plugin-go/tfprotov6" -) +// "github.com/hashicorp/terraform-plugin-framework/providerserver" +// "github.com/hashicorp/terraform-plugin-go/tfprotov6" +// ) -// testAccProtoV6ProviderFactories are used to instantiate a provider during -// acceptance testing. The factory function will be invoked for every Terraform -// CLI command executed to create a provider server to which the CLI can -// reattach. -var testAccProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){ - "scaffolding": providerserver.NewProtocol6WithError(New("test")()), -} +// // testAccProtoV6ProviderFactories are used to instantiate a provider during +// // acceptance testing. The factory function will be invoked for every Terraform +// // CLI command executed to create a provider server to which the CLI can +// // reattach. +// var testAccProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){ +// "scaffolding": providerserver.NewProtocol6WithError(New("test")()), +// } -func testAccPreCheck(t *testing.T) { - // You can add code here to run prior to any test case execution, for example assertions - // about the appropriate environment variables being set are common to see in a pre-check - // function. -} +// func testAccPreCheck(t *testing.T) { +// // You can add code here to run prior to any test case execution, for example assertions +// // about the appropriate environment variables being set are common to see in a pre-check +// // function. +// } diff --git a/internal/ssh/client.go b/internal/ssh/client.go index ea6a009..96440de 100644 --- a/internal/ssh/client.go +++ b/internal/ssh/client.go @@ -18,7 +18,6 @@ type SshAuthorization struct { } type SshClient struct { - client *ssh.Client config *ssh.ClientConfig Host string Port string @@ -47,6 +46,9 @@ func NewSshClient(host, port string, auth SshAuthorization) (*SshClient, error) } signer, err := ssh.ParsePrivateKey(key) + if err != nil { + return nil, err + } config = &ssh.ClientConfig{ User: globalSshClient.Auth.User, Auth: []ssh.AuthMethod{