summaryrefslogtreecommitdiff
path: root/src/rhimportd/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/rhimportd/main.go')
-rw-r--r--src/rhimportd/main.go33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/rhimportd/main.go b/src/rhimportd/main.go
index 4b0514b..68b0177 100644
--- a/src/rhimportd/main.go
+++ b/src/rhimportd/main.go
@@ -34,6 +34,7 @@ import (
"os"
"os/signal"
"sync"
+ "time"
)
var (
@@ -66,6 +67,28 @@ func (s *envStringValue) Get() interface{} { return string(*s) }
func (s *envStringValue) String() string { return fmt.Sprintf("%s", *s) }
+type envDurationValue time.Duration
+
+func newEnvDurationValue(key string, dflt time.Duration) (*envDurationValue, error) {
+ if envval, exists := os.LookupEnv(key); exists {
+ var val envDurationValue
+ err := (&val).Set(envval)
+ return &val, err
+ } else {
+ return (*envDurationValue)(&dflt), nil
+ }
+}
+
+func (d *envDurationValue) Set(val string) error {
+ dval, err := time.ParseDuration(val)
+ *d = envDurationValue(dval)
+ return err
+}
+
+func (d *envDurationValue) Get() interface{} { return time.Duration(*d) }
+
+func (d *envDurationValue) String() string { return fmt.Sprintf("%v", *d) }
+
func main() {
webAddr := newEnvStringValue("RHIMPORTD_WEB_ADDR", "localhost:4080")
flag.Var(webAddr, "web-addr", "addr:port to listen on (environment: RHIMPORTD_WEB_ADDR)")
@@ -81,6 +104,14 @@ func main() {
flag.Var(tempDir, "tmp-dir", "path to temporary files (environment: RHIMPORTD_TEMP_DIR)")
localFetchDir := newEnvStringValue("RHIMPORTD_LOCAL_FETCH_DIR", os.TempDir())
flag.Var(localFetchDir, "local-fetch-dir", "base path for local:// urls (environment: RHIMPORTD_LOCAL_FETCH_DIR)")
+
+ uploadMaxAge, err := newEnvDurationValue("RHIMPORTD_UPLOAD_MAX_AGE", 30*time.Minute)
+ if err != nil {
+ rhl.Println("Error parsing RHIMPORTD_UPLOAD_MAX_AGE from environment:", err)
+ return
+ }
+ flag.Var(uploadMaxAge, "upload-max-age", "maximum age of uploaded files before the get deleted (environment: RHIMPORTD_UPLOAD_MAX_AGE)")
+
help := flag.Bool("help", false, "show usage")
flag.Parse()
@@ -112,7 +143,7 @@ func main() {
go func() {
defer wg.Done()
rhl.Println("starting web-ctrl")
- StartControlWeb(webAddr.Get().(string), conf, db.GetInterface(), sessions.GetInterface())
+ StartControlWeb(webAddr.Get().(string), uploadMaxAge.Get().(time.Duration), conf, db.GetInterface(), sessions.GetInterface())
rhl.Println("web-ctrl finished")
}()
}