From 661e497bedeebb31225bd88180527b50cc2500d0 Mon Sep 17 00:00:00 2001 From: Gene Liverman Date: Wed, 1 May 2024 11:11:36 -0400 Subject: [PATCH] Use provided r10k command_path Prior to this, the Config struct had a setting under the R10k struct called CommandPath that could be set in the config file, but was ignored as both places that would use it were hard coded to instead use the string `r10k`. This resulted in the application looking in the path for the r10k binary. A default is set in config.go also, but that seems to have also been ignored. This fixes #152 --- README.md | 6 ++++++ api/environment.go | 2 +- api/module.go | 2 +- lib/helpers/r10k-command.go | 14 ++++++++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 lib/helpers/r10k-command.go diff --git a/README.md b/README.md index 7e5e87b..78b4841 100644 --- a/README.md +++ b/README.md @@ -221,6 +221,12 @@ Type: bool Description: Run `puppet generate types` after updating an environment Default: `true` +### `command_path` + +Type: `string` +Description: Allow overriding the default path to r10k. +Default: `/opt/puppetlabs/puppetserver/bin/r10k` + ## Usage Webhook API provides following paths diff --git a/api/environment.go b/api/environment.go index 79364a2..e40dba7 100644 --- a/api/environment.go +++ b/api/environment.go @@ -24,7 +24,7 @@ func (e EnvironmentController) DeployEnvironment(c *gin.Context) { var branch string // Set the base r10k command into a slice of strings - cmd := []string{"r10k", "deploy", "environment"} + cmd := []string{h.GetR10kCommand(), "deploy", "environment"} // Get the configuration conf := config.GetConfig() diff --git a/api/module.go b/api/module.go index 34228a0..436690d 100644 --- a/api/module.go +++ b/api/module.go @@ -24,7 +24,7 @@ func (m ModuleController) DeployModule(c *gin.Context) { var h helpers.Helper // Set the base r10k command into a string slice - cmd := []string{"r10k", "deploy", "module"} + cmd := []string{h.GetR10kCommand(), "deploy", "module"} // Get the configuration conf := config.GetConfig() diff --git a/lib/helpers/r10k-command.go b/lib/helpers/r10k-command.go new file mode 100644 index 0000000..5a62943 --- /dev/null +++ b/lib/helpers/r10k-command.go @@ -0,0 +1,14 @@ +package helpers + +import "github.com/voxpupuli/webhook-go/config" + +const Command = "r10k" + +func (h *Helper) GetR10kCommand() string { + conf := config.GetConfig().R10k + commandPath := conf.CommandPath + if commandPath == "" { + return Command + } + return commandPath +}