11package configs
22
33import (
4+ "fmt"
45 "github-issue-schedule/internal/pkg/utils"
56 "io/ioutil"
67 "log"
@@ -10,7 +11,12 @@ import (
1011
1112// Configuration to run the program
1213type Configuration struct {
13- BufferWindowDays uint8 `yaml:"buffer_window_days"`
14+ // BufferWindowDays indicates how many days in advance a reminder
15+ // issue should be created. Use a signed integer so configs can
16+ // express reasonable values without worrying about overflow when
17+ // comparing against days-calculated-from-the-clock. Negative values
18+ // are invalid and the reader enforces this.
19+ BufferWindowDays int `yaml:"buffer_window_days"`
1420 Projects []Project `yaml:"projects"`
1521}
1622
@@ -44,5 +50,23 @@ func ReadConfiguration() Configuration {
4450 if err != nil {
4551 log .Fatalf ("Error while parsing the config file %v, Err: %v" , configFile , err )
4652 }
53+
54+ if err := config .validate (); err != nil {
55+ log .Fatalf ("invalid configuration: %v" , err )
56+ }
57+
4758 return config
4859}
60+
61+ // validate checks that fields in Configuration contain reasonable
62+ // values. callers may use this directly in tests; ReadConfiguration
63+ // itself fatals on any error.
64+ func (c * Configuration ) validate () error {
65+ if c .BufferWindowDays < 0 {
66+ return fmt .Errorf ("buffer_window_days must be non-negative" )
67+ }
68+ if c .BufferWindowDays > 100000 {
69+ return fmt .Errorf ("buffer_window_days is unreasonably large (%d)" , c .BufferWindowDays )
70+ }
71+ return nil
72+ }
0 commit comments