Skip to content

Commit

Permalink
Merge pull request #47 from launchrctl/41-branding_vars
Browse files Browse the repository at this point in the history
41 branding vars
  • Loading branch information
davidferlay authored Jun 10, 2024
2 parents 33b7d0b + d07b6dc commit 8fb4140
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 20 deletions.
63 changes: 63 additions & 0 deletions server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"net/url"
"os"
"path/filepath"
"sort"

"github.com/launchrctl/launchr/pkg/log"
Expand All @@ -24,6 +25,68 @@ type launchrServer struct {
apiPrefix string
}

type launchrWebConfig struct {
VarsFile string `yaml:"vars_file"`
Variables []string `yaml:"variables"`
}

func parseVarsFile(path string) (map[string]interface{}, error) {
var data map[string]interface{}
var rawData []byte

rawData, err := os.ReadFile(filepath.Clean(path))
if err != nil {
return data, err
}

err = yaml.Unmarshal(rawData, &data)
if err != nil {
return data, err
}

return data, nil
}

func (l *launchrServer) GetCustomisationConfig(w http.ResponseWriter, _ *http.Request) {
var launchrConfig *launchrWebConfig
err := l.cfg.Get("web", &launchrConfig)
if err != nil {
log.Debug(err.Error())
sendError(w, http.StatusInternalServerError, "error getting config")
return
}

customisation := make(CustomisationConfig)
if launchrConfig == nil {
log.Debug("Launchr config doesn't exist")
} else {
if launchrConfig.VarsFile != "" {
vars := make(map[string]bool)
for _, item := range launchrConfig.Variables {
vars[item] = true
}

gvFile, err := parseVarsFile(launchrConfig.VarsFile)
if err != nil {
log.Debug(err.Error())
sendError(w, http.StatusInternalServerError, "error getting group vars file")
return
}

if len(launchrConfig.Variables) > 0 {
for key, value := range gvFile {
if _, ok := vars[key]; ok {
customisation[key] = value
}
}
}
}
}

w.WriteHeader(http.StatusOK)
_ = json.NewEncoder(w).Encode(customisation)
}

func (l *launchrServer) GetOneRunningActionByID(w http.ResponseWriter, _ *http.Request, id ActionId, runID ActionRunInfoId) {
ri, ok := l.actionMngr.RunInfoByID(runID)
if !ok {
Expand Down
71 changes: 51 additions & 20 deletions server/openapi.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions server/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ info:
name: Apache 2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html
paths:
/customisation:
get:
summary: Customisation config
operationId: getCustomisationConfig
responses:
'200':
description: config response
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Customisation'
default:
$ref: '#/components/responses/DefaultError'
/actions:
get:
summary: Lists all actions
Expand Down Expand Up @@ -172,6 +187,11 @@ components:
minimum: 1
maximum: 100
schemas:
Customisation:
type: object
x-go-name: "CustomisationConfig"
x-go-type: "map[string]interface{}"
x-go-type-skip-optional-pointer: true
ActionShort:
allOf:
- type: object
Expand Down

0 comments on commit 8fb4140

Please sign in to comment.