-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
59 lines (46 loc) · 1.63 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
package openlineage
import (
"context"
"fmt"
"os"
"github.com/ThijsKoot/openlineage-go/pkg/transport"
"github.com/sethvargo/go-envconfig"
"gopkg.in/yaml.v3"
)
type ClientConfig struct {
Transport transport.Config `yaml:"transport"`
// Namespace for events. Defaults to "default"
Namespace string `yaml:"namespace" env:"OPENLINEAGE_NAMESPACE, overwrite, default=default"`
// When true, OpenLineage will not emit events (default: false)
Disabled bool `yaml:"disabled" env:"OPENLINEAGE_DISABLED, overwrite"`
}
// ConfigFromEnv attempts to parse [ClientConfig] from the environment.
// If OPENLINEAGE_CONFIG_FILE is specified, it will be read first.
// Environment variables take precedence over values from the configuration file.
func ConfigFromEnv() (ClientConfig, error) {
var config ClientConfig
configFile := os.Getenv("OPENLINEAGE_CONFIG")
if configFile != "" {
c, err := ConfigFromFile(configFile)
if err != nil {
return ClientConfig{}, fmt.Errorf("parsing OPENLINEAGE_CONFIG_FILE: %w", err)
}
config = c
}
if err := envconfig.Process(context.Background(), &config); err != nil {
return ClientConfig{}, fmt.Errorf("unable to parse config from environment: %w", err)
}
return config, nil
}
// ConfigFromFile reads a configuration file in YAML-format from the specified location.
func ConfigFromFile(location string) (ClientConfig, error) {
f, err := os.ReadFile(location)
if err != nil {
return ClientConfig{}, fmt.Errorf("read config file: %w", err)
}
var cfg ClientConfig
if err := yaml.Unmarshal(f, &cfg); err != nil {
return ClientConfig{}, fmt.Errorf("unmarshal config file: %w", err)
}
return cfg, nil
}