mirror of
https://codeberg.org/scip/ephemerup.git
synced 2025-12-17 04:30:57 +01:00
changes:
- added unit tests
- put all subcmds into one file
- use io.Writer for output, better for testing
- added upload form support
- added api docs
- generalized db engine
- added mail notify support for forms
- enhanced server/SetupAuthStore() to also look up form ids
- added form template (put into .go file by Makefile
- renamed project
This commit is contained in:
44
cmd/root.go
44
cmd/root.go
@@ -29,8 +29,8 @@ import (
|
||||
flag "github.com/spf13/pflag"
|
||||
|
||||
"github.com/alecthomas/repr"
|
||||
"github.com/tlinden/cenophane/api"
|
||||
"github.com/tlinden/cenophane/cfg"
|
||||
"github.com/tlinden/ephemerup/api"
|
||||
"github.com/tlinden/ephemerup/cfg"
|
||||
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@@ -59,19 +59,20 @@ func Execute() error {
|
||||
f.BoolVarP(&conf.Debug, "debug", "d", false, "Enable debugging")
|
||||
f.StringVarP(&conf.Listen, "listen", "l", ":8080", "listen to custom ip:port (use [ip]:port for ipv6)")
|
||||
f.StringVarP(&conf.StorageDir, "storagedir", "s", "/tmp", "storage directory for uploaded files")
|
||||
f.StringVarP(&conf.ApiPrefix, "apiprefix", "a", "/api", "API endpoint path")
|
||||
f.StringVarP(&conf.ApiPrefix, "apiprefix", "a", "", "API endpoint path")
|
||||
f.StringVarP(&conf.Url, "url", "u", "", "HTTP endpoint w/o path")
|
||||
f.StringVarP(&conf.DbFile, "dbfile", "D", "/tmp/uploads.db", "Bold database file to use")
|
||||
f.StringVarP(&conf.Super, "super", "", "", "The API Context which has permissions on all contexts")
|
||||
f.StringVarP(&conf.Frontpage, "frontpage", "", "welcome to upload api, use /api enpoint!",
|
||||
"Content or filename to be displayed on / in case someone visits")
|
||||
f.StringVarP(&conf.Formpage, "formpage", "", "", "Content or filename to be displayed for forms (must be a go template)")
|
||||
|
||||
// server settings
|
||||
f.BoolVarP(&conf.V4only, "ipv4", "4", false, "Only listen on ipv4")
|
||||
f.BoolVarP(&conf.V6only, "ipv6", "6", false, "Only listen on ipv6")
|
||||
|
||||
f.BoolVarP(&conf.Prefork, "prefork", "p", false, "Prefork server threads")
|
||||
f.StringVarP(&conf.AppName, "appname", "n", "cenod "+conf.GetVersion(), "App name to say hi as")
|
||||
f.StringVarP(&conf.AppName, "appname", "n", "ephemerupd "+conf.GetVersion(), "App name to say hi as")
|
||||
f.IntVarP(&conf.BodyLimit, "bodylimit", "b", 10250000000, "Max allowed upload size in bytes")
|
||||
|
||||
f.Parse(os.Args[1:])
|
||||
@@ -91,10 +92,10 @@ func Execute() error {
|
||||
configfiles = []string{configfile}
|
||||
} else {
|
||||
configfiles = []string{
|
||||
"/etc/cenod.hcl", "/usr/local/etc/cenod.hcl", // unix variants
|
||||
filepath.Join(os.Getenv("HOME"), ".config", "cenod", "cenod.hcl"),
|
||||
filepath.Join(os.Getenv("HOME"), ".cenod"),
|
||||
"cenod.hcl",
|
||||
"/etc/ephemerupd.hcl", "/usr/local/etc/ephemerupd.hcl", // unix variants
|
||||
filepath.Join(os.Getenv("HOME"), ".config", "ephemerupd", "ephemerupd.hcl"),
|
||||
filepath.Join(os.Getenv("HOME"), ".ephemerupd"),
|
||||
"ephemerupd.hcl",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,9 +109,9 @@ func Execute() error {
|
||||
}
|
||||
|
||||
// env overrides config file
|
||||
k.Load(env.Provider("CENOD_", ".", func(s string) string {
|
||||
k.Load(env.Provider("EPHEMERUPD_", ".", func(s string) string {
|
||||
return strings.Replace(strings.ToLower(
|
||||
strings.TrimPrefix(s, "CENOD_")), "_", ".", -1)
|
||||
strings.TrimPrefix(s, "EPHEMERUPD_")), "_", ".", -1)
|
||||
}), nil)
|
||||
|
||||
// command line overrides env
|
||||
@@ -142,6 +143,23 @@ func Execute() error {
|
||||
}
|
||||
}
|
||||
|
||||
// Formpage?
|
||||
if conf.Formpage != "" {
|
||||
if _, err := os.Stat(conf.Formpage); err == nil {
|
||||
// it's a filename, try to use it
|
||||
content, err := ioutil.ReadFile(conf.Formpage)
|
||||
if err != nil {
|
||||
return errors.New("error loading config: " + err.Error())
|
||||
}
|
||||
|
||||
// replace the filename
|
||||
conf.Formpage = string(content)
|
||||
}
|
||||
} else {
|
||||
// use builtin default
|
||||
conf.Formpage = formtemplate
|
||||
}
|
||||
|
||||
switch {
|
||||
case ShowVersion:
|
||||
fmt.Println(cfg.Getversion())
|
||||
@@ -157,11 +175,11 @@ func Execute() error {
|
||||
|
||||
Multiple env vars are supported in this format:
|
||||
|
||||
CENOD_CONTEXT_$(NAME)="<context>:<key>"
|
||||
EPHEMERUPD_CONTEXT_$(NAME)="<context>:<key>"
|
||||
|
||||
eg:
|
||||
|
||||
CENOD_CONTEXT_SUPPORT="support:tymag-fycyh-gymof-dysuf-doseb-puxyx"
|
||||
EPHEMERUPD_CONTEXT_SUPPORT="support:tymag-fycyh-gymof-dysuf-doseb-puxyx"
|
||||
^^^^^^^- doesn't matter.
|
||||
|
||||
Modifies cfg.Config directly
|
||||
@@ -171,7 +189,7 @@ func GetApicontextsFromEnv(conf *cfg.Config) {
|
||||
|
||||
for _, envvar := range os.Environ() {
|
||||
pair := strings.SplitN(envvar, "=", 2)
|
||||
if strings.HasPrefix(pair[0], "CENOD_CONTEXT_") {
|
||||
if strings.HasPrefix(pair[0], "EPHEMERUPD_CONTEXT_") {
|
||||
c := strings.SplitN(pair[1], ":", 2)
|
||||
if len(c) == 2 {
|
||||
contexts = append(contexts, cfg.Apicontext{Context: c[0], Key: c[1]})
|
||||
|
||||
Reference in New Issue
Block a user