This repository has been archived by the owner on Oct 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
/
config.go
64 lines (52 loc) · 2.93 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
package admin
import (
"context"
"time"
"github.com/flyteorg/flytestdlib/config"
"github.com/flyteorg/flytestdlib/logger"
)
//go:generate pflags Config --default-var=defaultConfig
const configSectionKey = "admin"
type Config struct {
Endpoint config.URL `json:"endpoint" pflag:",For admin types, specify where the uri of the service is located."`
UseInsecureConnection bool `json:"insecure" pflag:",Use insecure connection."`
MaxBackoffDelay config.Duration `json:"maxBackoffDelay" pflag:",Max delay for grpc backoff"`
PerRetryTimeout config.Duration `json:"perRetryTimeout" pflag:",gRPC per retry timeout"`
MaxRetries int `json:"maxRetries" pflag:",Max number of gRPC retries"`
// Auth can only be used if also running with a secure connection. If UseInsecureConnection is set to true, none
// of the following options will even be referenced.
UseAuth bool `json:"useAuth" pflag:",Whether or not to try to authenticate with options below"`
ClientID string `json:"clientId" pflag:",Client ID"`
ClientSecretLocation string `json:"clientSecretLocation" pflag:",File containing the client secret"`
Scopes []string `json:"scopes" pflag:",List of scopes to request"`
// There are two ways to get the token URL. If the authorization server url is provided, the client will try to use RFC 8414 to
// try to get the token URL. Or it can be specified directly through TokenURL config.
AuthorizationServerURL string `json:"authorizationServerUrl" pflag:",This is the URL to your IDP's authorization server'"`
TokenURL string `json:"tokenUrl" pflag:",Your IDPs token endpoint"`
// See the implementation of the 'grpcAuthorizationHeader' option in Flyte Admin for more information. But
// basically we want to be able to use a different string to pass the token from this client to the the Admin service
// because things might be running in a service mesh (like Envoy) that already uses the default 'authorization' header
AuthorizationHeader string `json:"authorizationHeader" pflag:",Custom metadata header to pass JWT"`
}
var (
defaultConfig = Config{
MaxBackoffDelay: config.Duration{Duration: 8 * time.Second},
PerRetryTimeout: config.Duration{Duration: 15 * time.Second},
MaxRetries: 4,
}
configSection = config.MustRegisterSectionWithUpdates(configSectionKey, &defaultConfig, func(ctx context.Context, newValue config.Config) {
if newValue.(*Config).MaxRetries < 0 {
logger.Panicf(ctx, "Admin configuration given with negative gRPC retry value.")
}
if newValue.(*Config).UseAuth {
logger.Warnf(ctx, "Admin client config has authentication ON with server %s", newValue.(*Config).AuthorizationServerURL)
}
})
)
func GetConfig(ctx context.Context) *Config {
if c, ok := configSection.GetConfig().(*Config); ok {
return c
}
logger.Warnf(ctx, "Failed to retrieve config section [%v].", configSectionKey)
return nil
}