Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/go_modules/go-b94d833462
Browse files Browse the repository at this point in the history
  • Loading branch information
dhollinger authored May 8, 2024
2 parents 527f648 + c1bfe09 commit a369487
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 17 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,24 @@ 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
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
Expand Down
8 changes: 6 additions & 2 deletions api/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions api/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -58,13 +58,13 @@ func (m ModuleController) DeployModule(c *gin.Context) {
module := data.ModuleName
overrideModule := c.Query("module_name")
// Restrictions to Puppet module names are: 1) begin with lowercase letter, 2) contain lowercase, digits or underscores
match, _ := regexp.MatchString("^[a-z][a-z0-9_]*$", overrideModule)
if !match {
c.JSON(http.StatusInternalServerError, gin.H{"message": "Invalid module name"})
c.Abort()
return
}
if overrideModule != "" {
match, _ := regexp.MatchString("^[a-z][a-z0-9_]*$", overrideModule)
if !match {
c.JSON(http.StatusInternalServerError, gin.H{"message": "Invalid module name"})
c.Abort()
return
}
module = overrideModule
}

Expand Down
18 changes: 10 additions & 8 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down Expand Up @@ -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
}
Expand Down
14 changes: 14 additions & 0 deletions lib/helpers/r10k-command.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit a369487

Please sign in to comment.