From 8c4de32246d2c1ee2fccee9a3130d6025cb17dfa Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 27 Apr 2023 14:57:43 +0200 Subject: [PATCH] Update home config --- Makefile | 5 ++++- cmd/config.go | 11 +++++++++-- go.mod | 2 +- go.sum | 6 ++---- internal/config/config.go | 4 ++-- internal/config/config.yml | 4 ++++ internal/config/home.go | 1 + internal/dis/component/server/home/home.go | 8 ++------ internal/dis/component/server/home/public.go | 7 +++++-- 9 files changed, 30 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index 0792117..34ae705 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,7 @@ -.PHONY: clean all deps +.PHONY: clean all deps live + +live: + sudo CGO_ENABLED=0 go run ./cmd/wdcli $(ARGS) all: wdcli diff --git a/cmd/config.go b/cmd/config.go index 1094643..ba7192a 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -9,7 +9,9 @@ import ( // Config is the configuration command var Config wisski_distillery.Command = cfg{} -type cfg struct{} +type cfg struct { + Human bool `long:"human" description:"Print configuration in human-readable format"` +} func (c cfg) Description() wisski_distillery.Description { return wisski_distillery.Description{ @@ -26,7 +28,12 @@ var errMarshalConfig = exit.Error{ ExitCode: exit.ExitGeneric, } -func (cfg) Run(context wisski_distillery.Context) error { +func (cfg cfg) Run(context wisski_distillery.Context) error { + if cfg.Human { + human := context.Environment.Config.MarshalSensitive() + context.Println(human) + return nil + } if err := context.Environment.Config.Marshal(context.Stdout); err != nil { return errMarshalConfig.Wrap(err) } diff --git a/go.mod b/go.mod index 05ba1a7..425ea0a 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/pquerna/otp v1.4.0 github.com/rs/zerolog v1.29.0 github.com/tkw1536/goprogram v0.3.5 - github.com/tkw1536/pkglib v0.0.0-20230427085354-69b5e047c325 + github.com/tkw1536/pkglib v0.0.0-20230427125619-a4a18a5b7d15 github.com/yuin/goldmark v1.5.4 github.com/yuin/goldmark-meta v1.1.0 golang.org/x/crypto v0.8.0 diff --git a/go.sum b/go.sum index 68c7f33..21d0234 100644 --- a/go.sum +++ b/go.sum @@ -115,10 +115,8 @@ github.com/tdewolff/parse v2.3.4+incompatible/go.mod h1:8oBwCsVmUkgHO8M5iCzSIDtp github.com/tdewolff/test v1.0.7 h1:8Vs0142DmPFW/bQeHRP3MV19m1gvndjUb1sn8yy74LM= github.com/tkw1536/goprogram v0.3.5 h1:S0axKo3R/vGa4zhYqYDKAZEPhAfwUSSeMtVwnAu4sNY= github.com/tkw1536/goprogram v0.3.5/go.mod h1:pYr4dMHOSVurbPQ4KTR0ett8XWNISbsRS6zlh9Nsxa8= -github.com/tkw1536/pkglib v0.0.0-20230409110642-5f57240e294b h1:qeoY+XHCDx1fubOJkLuMSdz4xNWtgeLpxPfxBiEIj4c= -github.com/tkw1536/pkglib v0.0.0-20230409110642-5f57240e294b/go.mod h1:0A1B9Cc5+yJXR3eeB14CqD4dFSbEjjWRo5Pr9M3XYuI= -github.com/tkw1536/pkglib v0.0.0-20230427085354-69b5e047c325 h1:A1XZyL73L+FI/r3P7OLnibAFDlCV0Q8dTU7bwFfAYvo= -github.com/tkw1536/pkglib v0.0.0-20230427085354-69b5e047c325/go.mod h1:0A1B9Cc5+yJXR3eeB14CqD4dFSbEjjWRo5Pr9M3XYuI= +github.com/tkw1536/pkglib v0.0.0-20230427125619-a4a18a5b7d15 h1:sVy3pSreMY5obUOGz2jCaPYbXh+5vklqMJrZZsrII+0= +github.com/tkw1536/pkglib v0.0.0-20230427125619-a4a18a5b7d15/go.mod h1:0A1B9Cc5+yJXR3eeB14CqD4dFSbEjjWRo5Pr9M3XYuI= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo= github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= diff --git a/internal/config/config.go b/internal/config/config.go index b172be5..17b7531 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -80,7 +80,7 @@ func (config Config) MarshalSensitive() string { var configBytes []byte // Marshal marshals this configuration in nicely formatted form. -// Where possible, this will provided yaml comments. +// Where possible, this will maintain yaml comments. // // Previous may optionally provide the bytes of a previous configuration file to replace settings in. // The previous yaml file must be a valid configuration yaml, meaning all fields should be set. @@ -103,7 +103,7 @@ func Marshal(config *Config, previous []byte) ([]byte, error) { } // transplant the configuration yaml into the template - if err := yamlx.Transplant(template, cfg); err != nil { + if err := yamlx.Transplant(template, cfg, true); err != nil { return nil, err } diff --git a/internal/config/config.yml b/internal/config/config.yml index 94bfb28..3146e75 100644 --- a/internal/config/config.yml +++ b/internal/config/config.yml @@ -41,9 +41,13 @@ http: # Configuration for the (public) homepage of the distillery. home: + # the title of the distillery to be set + title: null + # the url to redirect to for more information about this instance of the distillery. # to be configured by default. redirect: null + # configure the list of systems on the homepage. list: diff --git a/internal/config/home.go b/internal/config/home.go index bfe0d17..ea49332 100644 --- a/internal/config/home.go +++ b/internal/config/home.go @@ -4,6 +4,7 @@ import "github.com/FAU-CDI/wisski-distillery/internal/config/validators" // HomeConfig determines options for the homepage of the distillery type HomeConfig struct { + Title string `yaml:"title" default:"WissKI Distillery" validate:"nonempty"` SelfRedirect *validators.URL `yaml:"redirect" default:"https://github.com/FAU-CDI/wisski-distillery" validate:"https"` List HomeListConfig `yaml:"list" recurse:"true"` } diff --git a/internal/dis/component/server/home/home.go b/internal/dis/component/server/home/home.go index d9c3cff..3643c0a 100644 --- a/internal/dis/component/server/home/home.go +++ b/internal/dis/component/server/home/home.go @@ -29,21 +29,17 @@ var ( _ component.Routeable = (*Home)(nil) ) -func (*Home) Routes() component.Routes { +func (home *Home) Routes() component.Routes { return component.Routes{ Prefix: "/", MatchAllDomains: true, CSRF: false, - MenuTitle: "WissKI Distillery", + MenuTitle: home.Config.Home.Title, MenuPriority: component.MenuHome, } } -var ( - menuHome = component.MenuItem{Title: "WissKI Distillery", Path: "/"} -) - func (home *Home) HandleRoute(ctx context.Context, route string) (http.Handler, error) { // generate a default handler dflt, err := home.loadRedirect(ctx) diff --git a/internal/dis/component/server/home/public.go b/internal/dis/component/server/home/public.go index 3a83f6d..7932c28 100644 --- a/internal/dis/component/server/home/public.go +++ b/internal/dis/component/server/home/public.go @@ -7,6 +7,7 @@ import ( "net/http" "strings" + "github.com/FAU-CDI/wisski-distillery/internal/dis/component" "github.com/FAU-CDI/wisski-distillery/internal/dis/component/server/assets" "github.com/FAU-CDI/wisski-distillery/internal/dis/component/server/templating" "github.com/FAU-CDI/wisski-distillery/internal/status" @@ -18,7 +19,6 @@ var publicHTML []byte var publicTemplate = templating.Parse[publicContext]( "public.html", publicHTML, nil, - templating.Title("WissKI Distillery"), templating.Assets(assets.AssetsDefault), ) @@ -49,11 +49,14 @@ type publicContext struct { const logoHTML = template.HTML(``) func (home *Home) publicHandler(ctx context.Context) http.Handler { + title := home.Config.Home.Title tpl := publicTemplate.Prepare( home.Dependencies.Templating, + // set title and menu item + templating.Title(title), templating.Crumbs( - menuHome, + component.MenuItem{Title: title, Path: "/"}, ), )