Skip to content

Commit

Permalink
Fix mandatory packages
Browse files Browse the repository at this point in the history
- Fixed an issue with the packer being mandatory as a dependency
  • Loading branch information
cjlapao committed Nov 13, 2024
1 parent 69b0a88 commit ea2972c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 26 deletions.
79 changes: 54 additions & 25 deletions internal/deploy/devops_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,36 +79,65 @@ func (c *DevOpsServiceClient) RestartServer() error {
return nil
}

func (c *DevOpsServiceClient) InstallDependencies() ([]string, error) {
installed_dependencies := []string{}
_, ok := c.client.(*localclient.LocalClient)
if !ok {
if err := c.InstallBrew(); err != nil {
return installed_dependencies, err
func containsDependency(arr []string, value string) bool {

Check failure on line 82 in internal/deploy/devops_service.go

View workflow job for this annotation

GitHub Actions / Build

func `containsDependency` is unused (unused)
for _, v := range arr {
if v == value {
return true
}
}
return false
}

gitPresent := c.findPath("git")
if gitPresent == "" {
if err := c.InstallGit(); err != nil {
return installed_dependencies, err
}
installed_dependencies = append(installed_dependencies, "git")
}
func (c *DevOpsServiceClient) InstallDependencies(listToInstall []string) ([]string, error) {
installed_dependencies := []string{}
_, ok := c.client.(*localclient.LocalClient)

packerPresent := c.findPath("packer")
if packerPresent == "" {
if err := c.InstallPacker(); err != nil {
return installed_dependencies, err
}
installed_dependencies = append(installed_dependencies, "packer")
}
if err := c.InstallBrew(); err != nil {
return installed_dependencies, err
}
installed_dependencies = append(installed_dependencies, "brew")

vagrantPresent := c.findPath("vagrant")
if vagrantPresent == "" {
if err := c.InstallVagrant(); err != nil {
return installed_dependencies, err
if !ok {
for _, dep := range listToInstall {
switch dep {
case "brew":
brewPresent := c.findPath("brew")
if brewPresent == "" {
if err := c.InstallBrew(); err != nil {
return installed_dependencies, err
}
installed_dependencies = append(installed_dependencies, "brew")
}
case "git":
gitPresent := c.findPath("git")
brewPresent := c.findPath("brew")
if gitPresent == "" && brewPresent == "" {
if err := c.InstallGit(); err != nil {
return installed_dependencies, err
}
installed_dependencies = append(installed_dependencies, "git")
}
case "packer":
packerPresent := c.findPath("packer")
brewPresent := c.findPath("brew")
if packerPresent == "" && brewPresent == "" {
if err := c.InstallPacker(); err != nil {
return installed_dependencies, err
}
installed_dependencies = append(installed_dependencies, "packer")
}
case "vagrant":
vagrantPresent := c.findPath("vagrant")
brewPresent := c.findPath("brew")
if vagrantPresent == "" && brewPresent == "" {
if err := c.InstallVagrant(); err != nil {
return installed_dependencies, err
}
installed_dependencies = append(installed_dependencies, "vagrant")
}
default:
return installed_dependencies, errors.New("Unsupported dependency")
}
installed_dependencies = append(installed_dependencies, "vagrant")
}
} else {
return installed_dependencies, errors.New("Unsupported client")
Expand Down
8 changes: 7 additions & 1 deletion internal/deploy/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"strings"

"terraform-provider-parallels-desktop/internal/common"
"terraform-provider-parallels-desktop/internal/deploy/schemas"
"terraform-provider-parallels-desktop/internal/interfaces"
Expand Down Expand Up @@ -851,9 +852,14 @@ func (r *DeployResource) installParallelsDesktop(parallelsClient *DevOpsServiceC
diag := diag.Diagnostics{}
var installDependenciesError error
var installed_dependencies []string
mandatoryDependencies := []string{
"brew",
"git",
"vagrant",
}

// installing dependencies
installed_dependencies, installDependenciesError = parallelsClient.InstallDependencies()
installed_dependencies, installDependenciesError = parallelsClient.InstallDependencies(mandatoryDependencies)
if installDependenciesError != nil {
if uninstallErrors := parallelsClient.UninstallDependencies(installed_dependencies); len(uninstallErrors) > 0 {
for _, uninstallError := range uninstallErrors {
Expand Down

0 comments on commit ea2972c

Please sign in to comment.