Update home config
This commit is contained in:
parent
44af84abe9
commit
8c4de32246
9 changed files with 30 additions and 18 deletions
5
Makefile
5
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
|
all: wdcli
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,9 @@ import (
|
||||||
// Config is the configuration command
|
// Config is the configuration command
|
||||||
var Config wisski_distillery.Command = cfg{}
|
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 {
|
func (c cfg) Description() wisski_distillery.Description {
|
||||||
return wisski_distillery.Description{
|
return wisski_distillery.Description{
|
||||||
|
|
@ -26,7 +28,12 @@ var errMarshalConfig = exit.Error{
|
||||||
ExitCode: exit.ExitGeneric,
|
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 {
|
if err := context.Environment.Config.Marshal(context.Stdout); err != nil {
|
||||||
return errMarshalConfig.Wrap(err)
|
return errMarshalConfig.Wrap(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
go.mod
2
go.mod
|
|
@ -16,7 +16,7 @@ require (
|
||||||
github.com/pquerna/otp v1.4.0
|
github.com/pquerna/otp v1.4.0
|
||||||
github.com/rs/zerolog v1.29.0
|
github.com/rs/zerolog v1.29.0
|
||||||
github.com/tkw1536/goprogram v0.3.5
|
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 v1.5.4
|
||||||
github.com/yuin/goldmark-meta v1.1.0
|
github.com/yuin/goldmark-meta v1.1.0
|
||||||
golang.org/x/crypto v0.8.0
|
golang.org/x/crypto v0.8.0
|
||||||
|
|
|
||||||
6
go.sum
6
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/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 h1:S0axKo3R/vGa4zhYqYDKAZEPhAfwUSSeMtVwnAu4sNY=
|
||||||
github.com/tkw1536/goprogram v0.3.5/go.mod h1:pYr4dMHOSVurbPQ4KTR0ett8XWNISbsRS6zlh9Nsxa8=
|
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-20230427125619-a4a18a5b7d15 h1:sVy3pSreMY5obUOGz2jCaPYbXh+5vklqMJrZZsrII+0=
|
||||||
github.com/tkw1536/pkglib v0.0.0-20230409110642-5f57240e294b/go.mod h1:0A1B9Cc5+yJXR3eeB14CqD4dFSbEjjWRo5Pr9M3XYuI=
|
github.com/tkw1536/pkglib v0.0.0-20230427125619-a4a18a5b7d15/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/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
|
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 h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo=
|
||||||
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
|
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ func (config Config) MarshalSensitive() string {
|
||||||
var configBytes []byte
|
var configBytes []byte
|
||||||
|
|
||||||
// Marshal marshals this configuration in nicely formatted form.
|
// 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.
|
// 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.
|
// 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
|
// 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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,9 +41,13 @@ http:
|
||||||
|
|
||||||
# Configuration for the (public) homepage of the distillery.
|
# Configuration for the (public) homepage of the distillery.
|
||||||
home:
|
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.
|
# the url to redirect to for more information about this instance of the distillery.
|
||||||
# to be configured by default.
|
# to be configured by default.
|
||||||
redirect: null
|
redirect: null
|
||||||
|
|
||||||
|
|
||||||
# configure the list of systems on the homepage.
|
# configure the list of systems on the homepage.
|
||||||
list:
|
list:
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import "github.com/FAU-CDI/wisski-distillery/internal/config/validators"
|
||||||
|
|
||||||
// HomeConfig determines options for the homepage of the distillery
|
// HomeConfig determines options for the homepage of the distillery
|
||||||
type HomeConfig struct {
|
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"`
|
SelfRedirect *validators.URL `yaml:"redirect" default:"https://github.com/FAU-CDI/wisski-distillery" validate:"https"`
|
||||||
List HomeListConfig `yaml:"list" recurse:"true"`
|
List HomeListConfig `yaml:"list" recurse:"true"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,21 +29,17 @@ var (
|
||||||
_ component.Routeable = (*Home)(nil)
|
_ component.Routeable = (*Home)(nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
func (*Home) Routes() component.Routes {
|
func (home *Home) Routes() component.Routes {
|
||||||
return component.Routes{
|
return component.Routes{
|
||||||
Prefix: "/",
|
Prefix: "/",
|
||||||
MatchAllDomains: true,
|
MatchAllDomains: true,
|
||||||
CSRF: false,
|
CSRF: false,
|
||||||
|
|
||||||
MenuTitle: "WissKI Distillery",
|
MenuTitle: home.Config.Home.Title,
|
||||||
MenuPriority: component.MenuHome,
|
MenuPriority: component.MenuHome,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
|
||||||
menuHome = component.MenuItem{Title: "WissKI Distillery", Path: "/"}
|
|
||||||
)
|
|
||||||
|
|
||||||
func (home *Home) HandleRoute(ctx context.Context, route string) (http.Handler, error) {
|
func (home *Home) HandleRoute(ctx context.Context, route string) (http.Handler, error) {
|
||||||
// generate a default handler
|
// generate a default handler
|
||||||
dflt, err := home.loadRedirect(ctx)
|
dflt, err := home.loadRedirect(ctx)
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"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/assets"
|
||||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/server/templating"
|
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/server/templating"
|
||||||
"github.com/FAU-CDI/wisski-distillery/internal/status"
|
"github.com/FAU-CDI/wisski-distillery/internal/status"
|
||||||
|
|
@ -18,7 +19,6 @@ var publicHTML []byte
|
||||||
var publicTemplate = templating.Parse[publicContext](
|
var publicTemplate = templating.Parse[publicContext](
|
||||||
"public.html", publicHTML, nil,
|
"public.html", publicHTML, nil,
|
||||||
|
|
||||||
templating.Title("WissKI Distillery"),
|
|
||||||
templating.Assets(assets.AssetsDefault),
|
templating.Assets(assets.AssetsDefault),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -49,11 +49,14 @@ type publicContext struct {
|
||||||
const logoHTML = template.HTML(`<img src="/logo.svg" alt="WissKI Distillery Logo" class="biglogo">`)
|
const logoHTML = template.HTML(`<img src="/logo.svg" alt="WissKI Distillery Logo" class="biglogo">`)
|
||||||
|
|
||||||
func (home *Home) publicHandler(ctx context.Context) http.Handler {
|
func (home *Home) publicHandler(ctx context.Context) http.Handler {
|
||||||
|
title := home.Config.Home.Title
|
||||||
|
|
||||||
tpl := publicTemplate.Prepare(
|
tpl := publicTemplate.Prepare(
|
||||||
home.Dependencies.Templating,
|
home.Dependencies.Templating,
|
||||||
|
// set title and menu item
|
||||||
|
templating.Title(title),
|
||||||
templating.Crumbs(
|
templating.Crumbs(
|
||||||
menuHome,
|
component.MenuItem{Title: title, Path: "/"},
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue