Skip to content

Commit

Permalink
feat: env fallback for string accumulator
Browse files Browse the repository at this point in the history
  • Loading branch information
sduc committed Feb 14, 2025
1 parent e9c8229 commit 6eb863d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package cli
import (
"errors"
"fmt"
"os"
"strings"

"github.com/micromdm/nanomdm/storage"
Expand Down Expand Up @@ -38,7 +39,21 @@ func NewStorage() *Storage {
return &Storage{}
}

func fallbackStorage(s *StringAccumulator, envVar string) {
if len(*s) > 0 {
return
}

if envValue := os.Getenv(envVar); envValue != "" {
s.Set(envValue)
}
}

func (s *Storage) Parse(logger log.Logger) (storage.AllStorage, error) {
fallbackStorage(&s.Storage, "STORAGE")
fallbackStorage(&s.DSN, "STORAGE_DSN")
fallbackStorage(&s.Options, "STORAGE_OPTIONS")

if len(s.Storage) != len(s.DSN) {
return nil, errors.New("must have same number of storage and DSN flags")
}
Expand Down

0 comments on commit 6eb863d

Please sign in to comment.