From 89c6987783f3c111aa52dd045a1ac595520cf103 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 May 2024 13:23:36 +0000 Subject: [PATCH 1/3] Bump github.com/xanzy/go-gitlab from 0.103.0 to 0.104.0 in the go group Bumps the go group with 1 update: [github.com/xanzy/go-gitlab](https://github.com/xanzy/go-gitlab). Updates `github.com/xanzy/go-gitlab` from 0.103.0 to 0.104.0 - [Changelog](https://github.com/xanzy/go-gitlab/blob/main/releases_test.go) - [Commits](https://github.com/xanzy/go-gitlab/compare/v0.103.0...v0.104.0) --- updated-dependencies: - dependency-name: github.com/xanzy/go-gitlab dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index b0e4318..0f6408c 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/spf13/cobra v1.8.0 github.com/spf13/viper v1.18.2 github.com/stretchr/testify v1.9.0 - github.com/xanzy/go-gitlab v0.103.0 + github.com/xanzy/go-gitlab v0.104.0 gotest.tools v2.2.0+incompatible ) diff --git a/go.sum b/go.sum index cdc7faf..1512d5d 100644 --- a/go.sum +++ b/go.sum @@ -147,8 +147,8 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= -github.com/xanzy/go-gitlab v0.103.0 h1:J9pTQoq0GsEFqzd6srCM1QfdfKAxSNz6mT6ntrpNF2w= -github.com/xanzy/go-gitlab v0.103.0/go.mod h1:ETg8tcj4OhrB84UEgeE8dSuV/0h4BBL1uOV/qK0vlyI= +github.com/xanzy/go-gitlab v0.104.0 h1:YDuuaTrNdHMuBW+FagO/W4dHvAQOqpCf2pMB45ATbog= +github.com/xanzy/go-gitlab v0.104.0/go.mod h1:ETg8tcj4OhrB84UEgeE8dSuV/0h4BBL1uOV/qK0vlyI= go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= From 03961773331cd564089661e99f3ae4800ea4ae89 Mon Sep 17 00:00:00 2001 From: Gene Liverman Date: Tue, 7 May 2024 11:05:36 -0400 Subject: [PATCH 2/3] Allow legacy --puppetfile flag to be used This allows for utilizing the current version of webhook-go in environments saddled with legacy versions of r10k that don't yet have the new --modules flag. --- README.md | 6 ++++++ api/environment.go | 6 +++++- config/config.go | 18 ++++++++++-------- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 8ca7245..7e5e87b 100644 --- a/README.md +++ b/README.md @@ -209,6 +209,12 @@ Type: bool Description: Deploy modules in environments. Default: `true` +### `use_legacy_puppetfile_flag` + +Type: bool +Description: Use the legacy `--puppetfile` flag instead of `--modules`. This should only be used when your version of r10k doesn't support the newer flag. +Default: `false` + ### `generate_types` Type: bool diff --git a/api/environment.go b/api/environment.go index 5e69e39..79364a2 100644 --- a/api/environment.go +++ b/api/environment.go @@ -63,7 +63,11 @@ func (e EnvironmentController) DeployEnvironment(c *gin.Context) { cmd = append(cmd, "--generate-types") } if conf.R10k.DeployModules { - cmd = append(cmd, "--modules") + if conf.R10k.UseLegacyPuppetfileFlag { + cmd = append(cmd, "--puppetfile") + } else { + cmd = append(cmd, "--modules") + } } // Pass the command to the execute function and act on the result and any error diff --git a/config/config.go b/config/config.go index 1e1adee..640575e 100644 --- a/config/config.go +++ b/config/config.go @@ -35,14 +35,15 @@ type Config struct { ServerUri string `mapstructure:"server_uri"` } `mapstructure:"chatops"` R10k struct { - CommandPath string `mapstructure:"command_path"` - ConfigPath string `mapstructure:"config_path"` - DefaultBranch string `mapstructure:"default_branch"` - Prefix string `mapstructure:"prefix"` - AllowUppercase bool `mapstructure:"allow_uppercase"` - Verbose bool `mapstructure:"verbose"` - DeployModules bool `mapstructure:"deploy_modules"` - GenerateTypes bool `mapstructure:"generate_types"` + CommandPath string `mapstructure:"command_path"` + ConfigPath string `mapstructure:"config_path"` + DefaultBranch string `mapstructure:"default_branch"` + Prefix string `mapstructure:"prefix"` + AllowUppercase bool `mapstructure:"allow_uppercase"` + Verbose bool `mapstructure:"verbose"` + DeployModules bool `mapstructure:"deploy_modules"` + UseLegacyPuppetfileFlag bool `mapstructure:"use_legacy_puppetfile_flag"` + GenerateTypes bool `mapstructure:"generate_types"` } `mapstructure:"r10k"` } @@ -88,6 +89,7 @@ func setDefaults(v *viper.Viper) *viper.Viper { v.SetDefault("r10k.verbose", true) v.SetDefault("r10k.deploy_modules", true) v.SetDefault("r10k.generate_types", true) + v.SetDefault("r10k.use_legacy_puppetfile_flag", false) return v } From 661e497bedeebb31225bd88180527b50cc2500d0 Mon Sep 17 00:00:00 2001 From: Gene Liverman Date: Wed, 1 May 2024 11:11:36 -0400 Subject: [PATCH 3/3] 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 +}