-
Notifications
You must be signed in to change notification settings - Fork 18
/
config.go
69 lines (58 loc) · 2.46 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package server
import (
"errors"
"fmt"
"github.com/raystack/guardian/internal/store"
"github.com/raystack/guardian/jobs"
"github.com/raystack/guardian/pkg/auth"
"github.com/raystack/guardian/pkg/tracing"
"github.com/raystack/guardian/plugins/notifiers"
"github.com/raystack/salt/config"
)
type DefaultAuth struct {
HeaderKey string `mapstructure:"header_key" default:"X-Auth-Email"`
}
type Auth struct {
Provider string `mapstructure:"provider" default:"default"`
Default DefaultAuth `mapstructure:"default"`
OIDC auth.OIDCAuth `mapstructure:"oidc"`
}
type Jobs struct {
FetchResources jobs.Job `mapstructure:"fetch_resources"`
RevokeExpiredGrants jobs.Job `mapstructure:"revoke_expired_grants"`
ExpiringGrantNotification jobs.Job `mapstructure:"expiring_grant_notification"`
RevokeGrantsByUserCriteria jobs.Job `mapstructure:"revoke_grants_by_user_criteria"`
// Deprecated: use ExpiringGrantNotification instead
ExpiringAccessNotification jobs.Job `mapstructure:"expiring_access_notification"`
// Deprecated: use RevokeExpiredGrants instead
RevokeExpiredAccess jobs.Job `mapstructure:"revoke_expired_access"`
}
type Config struct {
Port int `mapstructure:"port" default:"8080"`
EncryptionSecretKeyKey string `mapstructure:"encryption_secret_key"`
Notifier notifiers.Config `mapstructure:"notifier"`
LogLevel string `mapstructure:"log_level" default:"info"`
DB store.Config `mapstructure:"db"`
// Deprecated: use Auth.Default.HeaderKey instead note on the AuthenticatedUserHeaderKey
AuthenticatedUserHeaderKey string `mapstructure:"authenticated_user_header_key"`
AuditLogTraceIDHeaderKey string `mapstructure:"audit_log_trace_id_header_key" default:"X-Trace-Id"`
Jobs Jobs `mapstructure:"jobs"`
Telemetry tracing.Config `mapstructure:"telemetry"`
Auth Auth `mapstructure:"auth"`
}
func LoadConfig(configFile string) (Config, error) {
var cfg Config
loader := config.NewLoader(config.WithFile(configFile))
if err := loader.Load(&cfg); err != nil {
if errors.As(err, &config.ConfigFileNotFoundError{}) {
fmt.Println(err)
return cfg, nil
}
return Config{}, err
}
// keep for backward-compatibility
if cfg.AuthenticatedUserHeaderKey != "" {
cfg.Auth.Default.HeaderKey = cfg.AuthenticatedUserHeaderKey
}
return cfg, nil
}