forked from grafana/loki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
managed_auth.go
50 lines (42 loc) · 932 Bytes
/
managed_auth.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
package config
import "os"
type AWSEnvironment struct {
RoleARN string
}
type AzureEnvironment struct {
ClientID string
SubscriptionID string
TenantID string
Region string
}
type ManagedAuthConfig struct {
AWS *AWSEnvironment
Azure *AzureEnvironment
}
func discoverManagedAuthConfig() *ManagedAuthConfig {
// AWS
roleARN := os.Getenv("ROLEARN")
// Azure
clientID := os.Getenv("CLIENTID")
tenantID := os.Getenv("TENANTID")
subscriptionID := os.Getenv("SUBSCRIPTIONID")
region := os.Getenv("REGION")
switch {
case roleARN != "":
return &ManagedAuthConfig{
AWS: &AWSEnvironment{
RoleARN: roleARN,
},
}
case clientID != "" && tenantID != "" && subscriptionID != "":
return &ManagedAuthConfig{
Azure: &AzureEnvironment{
ClientID: clientID,
SubscriptionID: subscriptionID,
TenantID: tenantID,
Region: region,
},
}
}
return nil
}