feat: allow homepage customization
Some checks reported warnings
arcad/arcast/pipeline/head This commit is unstable
Some checks reported warnings
arcad/arcast/pipeline/head This commit is unstable
This commit is contained in:
@ -20,7 +20,8 @@ type Config struct {
|
||||
}
|
||||
|
||||
type HTTPConfig struct {
|
||||
Address string `json:"address"`
|
||||
Address string `json:"address"`
|
||||
CustomDir string `json:"customDir"`
|
||||
}
|
||||
|
||||
type HTTPSConfig struct {
|
||||
@ -40,7 +41,7 @@ type AppsConfig struct {
|
||||
DefaultApp string `json:"defaultApp"`
|
||||
}
|
||||
|
||||
type TransformFunc func(ctx context.Context, conf *Config) error
|
||||
type TransformFunc func(ctx context.Context, filename string, conf *Config) error
|
||||
|
||||
func DefaultConfigFile(ctx context.Context) string {
|
||||
configDir, err := os.UserConfigDir()
|
||||
@ -69,7 +70,7 @@ func LoadOrCreate(ctx context.Context, filename string, conf *Config, funcs ...T
|
||||
}
|
||||
|
||||
for _, fn := range funcs {
|
||||
if err := fn(ctx, conf); err != nil {
|
||||
if err := fn(ctx, filename, conf); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
}
|
||||
@ -99,7 +100,8 @@ func DefaultConfig() *Config {
|
||||
InstanceID: server.NewRandomInstanceID(),
|
||||
AllowedOrigins: []string{},
|
||||
HTTP: HTTPConfig{
|
||||
Address: ":45555",
|
||||
Address: ":45555",
|
||||
CustomDir: "",
|
||||
},
|
||||
HTTPS: HTTPSConfig{
|
||||
Address: ":45556",
|
||||
|
28
pkg/config/custom_files.go
Normal file
28
pkg/config/custom_files.go
Normal file
@ -0,0 +1,28 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"gitlab.com/wpetit/goweb/logger"
|
||||
)
|
||||
|
||||
func CreateCustomDir(ctx context.Context, filename string, conf *Config) error {
|
||||
if conf.HTTP.CustomDir != "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
configDir := filepath.Dir(filename)
|
||||
customFilesDir := filepath.Join(configDir, "custom")
|
||||
|
||||
if err := os.MkdirAll(customFilesDir, 0755); err != nil {
|
||||
logger.Error(ctx, "could not create custom files directory", logger.CapturedE(errors.WithStack(err)))
|
||||
return nil
|
||||
}
|
||||
|
||||
conf.HTTP.CustomDir = customFilesDir
|
||||
|
||||
return nil
|
||||
}
|
@ -3,4 +3,5 @@ package config
|
||||
var DefaultTransforms = []TransformFunc{
|
||||
GenerateSelfSignedCert,
|
||||
RenewExpiredSelfSignedCert,
|
||||
CreateCustomDir,
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ import (
|
||||
"gitlab.com/wpetit/goweb/logger"
|
||||
)
|
||||
|
||||
func GenerateSelfSignedCert(ctx context.Context, conf *Config) error {
|
||||
func GenerateSelfSignedCert(ctx context.Context, filename string, conf *Config) error {
|
||||
if !conf.HTTPS.SelfSigned.Enabled {
|
||||
return nil
|
||||
}
|
||||
@ -42,13 +42,13 @@ func GenerateSelfSignedCert(ctx context.Context, conf *Config) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func RenewExpiredSelfSignedCert(ctx context.Context, conf *Config) error {
|
||||
func RenewExpiredSelfSignedCert(ctx context.Context, filename string, conf *Config) error {
|
||||
if !conf.HTTPS.SelfSigned.Enabled {
|
||||
return nil
|
||||
}
|
||||
|
||||
if conf.HTTPS.Cert == nil || conf.HTTPS.Key == nil {
|
||||
if err := GenerateSelfSignedCert(ctx, conf); err != nil {
|
||||
if err := GenerateSelfSignedCert(ctx, filename, conf); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
}
|
||||
@ -62,7 +62,7 @@ func RenewExpiredSelfSignedCert(ctx context.Context, conf *Config) error {
|
||||
if err != nil {
|
||||
logger.Error(ctx, "could not parse x509 certificate, regenerating one", logger.CapturedE(errors.WithStack(err)))
|
||||
|
||||
if err := GenerateSelfSignedCert(ctx, conf); err != nil {
|
||||
if err := GenerateSelfSignedCert(ctx, filename, conf); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
}
|
||||
@ -74,7 +74,7 @@ func RenewExpiredSelfSignedCert(ctx context.Context, conf *Config) error {
|
||||
|
||||
logger.Warn(ctx, "self-signed certificate has expired, regenerating one", logger.CapturedE(errors.WithStack(err)))
|
||||
|
||||
if err := GenerateSelfSignedCert(ctx, conf); err != nil {
|
||||
if err := GenerateSelfSignedCert(ctx, filename, conf); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user