-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
51 lines (43 loc) · 1.24 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package scwaudittrail
import (
"errors"
"time"
)
type Config struct {
// Polling frequency
Interval string `mapstructure:"interval"`
// Number of events to fetch per API call
MaxEventsPerRequest uint32 `mapstructure:"max_events_per_request"`
// Scaleway API access key
AccessKey string `mapstructure:"access_key"`
// Scaleway API secret key
SecretKey string `mapstructure:"secret_key"`
// Scaleway organization ID to monitor
OrganizationID string `mapstructure:"organization_id"`
// Scaleway region to monitor
Region string `mapstructure:"region"`
// Scaleway API URL
APIURL string `mapstructure:"api_url"`
// for mock
makeClient func(*Config) (Client, error)
}
var (
errBadInterval = errors.New("when defined, the interval has to be set to at least 1 minute (1m)")
errBadEventsPerRequest = errors.New("max_events_per_request must be greater or equal to 1")
)
func (cfg *Config) Validate() error {
interval, _ := time.ParseDuration(cfg.Interval)
if interval.Minutes() < 1 {
return errBadInterval
}
if cfg.MaxEventsPerRequest < 1 {
return errBadEventsPerRequest
}
return nil
}
func (cfg *Config) getScwClient() (Client, error) {
if cfg.makeClient == nil {
cfg.makeClient = newScalewayClient
}
return cfg.makeClient(cfg)
}