forked from mtusi2026/mtusi2026lab7
Prepare verified laboratory 7 implementation and evidence
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package lifecycle
|
||||
|
||||
import (
|
||||
"backend/internal/adapter/freshness"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
func FromEnvironment() (*freshness.Watcher, error) {
|
||||
path := os.Getenv("SECRET_FRESHNESS_FILE")
|
||||
if path == "" {
|
||||
return nil, nil
|
||||
}
|
||||
age := 120
|
||||
if s := os.Getenv("SECRET_MAX_AGE_SECONDS"); s != "" {
|
||||
n, e := strconv.Atoi(s)
|
||||
if e != nil || n < 1 || n > 3600 {
|
||||
return nil, ErrConfiguration
|
||||
}
|
||||
age = n
|
||||
}
|
||||
return freshness.New(freshness.Ports{Read: freshness.FileReader(path), Now: time.Now, NewTicker: freshness.SystemTicker}, time.Duration(age)*time.Second, min(5*time.Second, time.Duration(age)*time.Second))
|
||||
}
|
||||
Reference in New Issue
Block a user