Skip to content

Commit

Permalink
Add a option to force override module name
Browse files Browse the repository at this point in the history
The module name is implied from the git repository name. However, both
r10k and puppet are very particular about module naming, and the
implicit rewrites rules can get in the way. Puppet will understand any
amount of dashes in the project name as `<vendor>-<module>`, rewriting
`-` to `/`. For git repositories, there are often arbitrary naming rules
with copious amounts of these control characters in repository names,
making it nearly impossible to serve both worlds at the same time.

This URL parameter (module_name) allows to override the module name
directly in the URL, ignoring the git repository name.
  • Loading branch information
raincz committed Mar 1, 2024
1 parent ca971dd commit 02b337c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion api/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package api
import (
"fmt"
"net/http"
"regexp"

"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -54,8 +55,21 @@ func (m ModuleController) DeployModule(c *gin.Context) {
cmd = append(cmd, branch)
}

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 != "" {
module = overrideModule
}

// Append module name and r10k configuration to the cmd string slice
cmd = append(cmd, data.ModuleName)
cmd = append(cmd, module)
cmd = append(cmd, fmt.Sprintf("--config=%s", h.GetR10kConfig()))

// Set additional optional r10k flags if they are set
Expand Down

0 comments on commit 02b337c

Please sign in to comment.