Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions kibble/api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,19 @@ func LoadConfig(cfg *models.Config) (models.ServiceConfig, error) {
config[k] = v
}
}

for k, v := range cfg.ConfigOverrides {
config[k] = v
}

return config, nil
}

// LoadFeatureToggles - load all and merge
func LoadFeatureToggles(cfg *models.Config) (models.FeatureToggles, error) {

var loaded models.FeatureToggles
config := make(models.FeatureToggles)
toggles := make(models.FeatureToggles)

paths := []string{
fmt.Sprintf("%s/services/shopping/feature_toggles", cfg.SiteURL),
Expand All @@ -79,8 +84,13 @@ func LoadFeatureToggles(cfg *models.Config) (models.FeatureToggles, error) {
}

for k, v := range loaded {
config[k] = v
toggles[k] = v
}
}
return config, nil

for k, v := range cfg.ToggleOverrides {
toggles[k] = v
}

return toggles, nil
}
34 changes: 27 additions & 7 deletions kibble/cmd/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"kibble/config"
"kibble/render"
"kibble/utils"
"os"
"strconv"

"github.com/spf13/cobra"
)
Expand All @@ -26,6 +28,9 @@ var port int32
var watch bool
var serve bool

var configOverrides map[string]string = make(map[string]string)
var toggleOverrides map[string]string = make(map[string]string)

// renderCmd represents the render command
var renderCmd = &cobra.Command{
Use: "render",
Expand All @@ -34,16 +39,29 @@ var renderCmd = &cobra.Command{

Kibble is used to build and develop custom sites to run on the SHIFT72 platform.`,
Run: func(cmd *cobra.Command, args []string) {
logLevel := utils.ConvertToLoggingLevel(verbose)
utils.ConfigureStandardLogging(logLevel)

cfg := config.LoadConfig(runAsAdmin, apiKey, disableCache)
_ = config.CheckVersion(cfg)
for k, v := range configOverrides {
cfg.ConfigOverrides[k] = v
}

for k, v := range toggleOverrides {
value, err := strconv.ParseBool(v)
if err != nil {
log.Errorf("--toggle %s: invalid boolean value %s\n", k, v)
os.Exit(1)
}

cfg.ToggleOverrides[k] = value
}

if watch || serve {
log := utils.ConfigureWatchedLogging(utils.ConvertToLoggingLevel(verbose))
cfg := config.LoadConfig(runAsAdmin, apiKey, disableCache)
_ = config.CheckVersion(cfg)
render.Watch(cfg.SourcePath(), cfg.BuildPath(), cfg, port, log, watch)
watchLogger := utils.ConfigureWatchedLogging(logLevel)
render.Watch(cfg.SourcePath(), cfg.BuildPath(), cfg, port, watchLogger, watch)
} else {
utils.ConfigureStandardLogging(utils.ConvertToLoggingLevel(verbose))
cfg := config.LoadConfig(runAsAdmin, apiKey, disableCache)
_ = config.CheckVersion(cfg)
render.Render(cfg.SourcePath(), cfg.BuildPath(), cfg)
}
},
Expand All @@ -54,4 +72,6 @@ func init() {
renderCmd.Flags().Int32VarP(&port, "port", "p", 8080, "Port to listen on")
renderCmd.Flags().BoolVar(&watch, "watch", false, "Watch for changes")
renderCmd.Flags().BoolVar(&serve, "serve", false, "Serve the site, but dont watch for changes")
renderCmd.Flags().StringToStringVar(&configOverrides, "config", make(map[string]string), "Set site configuration values for this build")
renderCmd.Flags().StringToStringVar(&toggleOverrides, "toggle", make(map[string]string), "Set site feature toggles for this build")
}
7 changes: 5 additions & 2 deletions kibble/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
package cmd

import (
"fmt"
"os"

logging "github.com/op/go-logging"
"github.com/spf13/cobra"
)

Expand All @@ -26,6 +26,8 @@ var disableCache bool
var verbose bool
var apiKey string

var log *logging.Logger

// RootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Use: "kibble",
Expand All @@ -38,12 +40,13 @@ for the SHIFT72 Video Platform.`,
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
if err := RootCmd.Execute(); err != nil {
fmt.Println(err)
log.Errorf("%v", err)
os.Exit(-1)
}
}

func init() {
log = logging.MustGetLogger("kibble")
RootCmd.PersistentFlags().BoolVar(&runAsAdmin, "admin", false, "Render using admin credentials")
RootCmd.PersistentFlags().StringVar(&apiKey, "api-key", "", "Api key to authenicate with")
RootCmd.PersistentFlags().BoolVar(&disableCache, "disable-cache", false, "Prevent caching")
Expand Down
2 changes: 2 additions & 0 deletions kibble/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ func LoadConfig(runAsAdmin bool, apiKey string, disableCache bool) *models.Confi
LiveReload: models.LiveReloadConfig{
LaunchBrowser: true,
},
ConfigOverrides: map[string]string{},
ToggleOverrides: map[string]bool{},
}
err = json.Unmarshal(file, &cfg)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kibble/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ require (
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be // indirect
github.com/shurcooL/sanitized_anchor_name v0.0.0-20170918181015-86672fcb3f95 // indirect
github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/spf13/pflag v1.0.0 // indirect
github.com/spf13/pflag v1.0.6 // indirect
golang.org/x/net v0.0.0-20190311183353-d8887717615a // indirect
golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664 // indirect
golang.org/x/text v0.3.2 // indirect
Expand Down
2 changes: 2 additions & 0 deletions kibble/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ github.com/spf13/cobra v0.0.0-20170929161612-e5f66de850af h1:Qrv36iBHVS2H6QeH+ef
github.com/spf13/cobra v0.0.0-20170929161612-e5f66de850af/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.0 h1:oaPbdDe/x0UncahuwiPxW1GYJyilRAdsPnq3e1yaPcI=
github.com/spf13/pflag v1.0.0/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
Expand Down
4 changes: 4 additions & 0 deletions kibble/models/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ type Config struct {
DefaultDateFormat string `json:"defaultDateFormat"`
DefaultTimeFormat string `json:"defaultTimeFormat"`
CoreTemplateVersion string `json:"coreTemplateVersion"`

// allows overriding config variables
ConfigOverrides map[string]string `json:"configOverrides"`
ToggleOverrides map[string]bool `json:"toggleOverrides"`
}

// LiveReloadConfig - configuration options for the live_reloader
Expand Down
Loading