-
Notifications
You must be signed in to change notification settings - Fork 107
/
config.go
148 lines (126 loc) · 4.28 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package main
import (
"fmt"
"os"
"github.com/BurntSushi/toml"
"github.com/osbuild/osbuild-composer/internal/upload/azure"
"github.com/sirupsen/logrus"
)
type composerConfig struct {
Proxy string `toml:"proxy"`
}
type kerberosConfig struct {
Principal string `toml:"principal"`
KeyTab string `toml:"keytab"`
}
type kojiServerConfig struct {
Kerberos *kerberosConfig `toml:"kerberos,omitempty"`
RelaxTimeoutFactor uint `toml:"relax_timeout_factor"`
}
type gcpConfig struct {
Credentials string `toml:"credentials"`
Bucket string `toml:"bucket"`
}
type azureConfig struct {
Credentials string `toml:"credentials"`
UploadThreads int `toml:"upload_threads"`
}
type awsConfig struct {
Credentials string `toml:"credentials"`
Bucket string `toml:"bucket"`
}
type ociConfig struct {
Credentials string `toml:"credentials"`
}
type genericS3Config struct {
Credentials string `toml:"credentials"`
Endpoint string `toml:"endpoint"`
Region string `toml:"region"`
Bucket string `toml:"bucket"`
CABundle string `toml:"ca_bundle"`
SkipSSLVerification bool `toml:"skip_ssl_verification"`
}
type authenticationConfig struct {
OAuthURL string `toml:"oauth_url"`
OfflineTokenPath string `toml:"offline_token"`
ClientId string `toml:"client_id"`
ClientSecretPath string `toml:"client_secret"`
}
type containersConfig struct {
AuthFilePath string `toml:"auth_file_path"`
Domain string `toml:"domain"`
PathPrefix string `toml:"path_prefix"`
CertPath string `toml:"cert_path"`
TLSVerify bool `toml:"tls_verify"`
}
type pulpConfig struct {
Credentials string `toml:"credentials"`
ServerURL string `toml:"server_address"`
}
type executorConfig struct {
Type string `toml:"type"`
IAMProfile string `toml:"iam_profile"`
KeyName string `toml:"key_name"`
CloudWatchGroup string `toml:"cloudwatch_group"`
}
type repositoryMTLSConfig struct {
BaseURL string `toml:"baseurl"`
CA string `toml:"ca"`
MTLSClientKey string `toml:"mtls_client_key"`
MTLSClientCert string `toml:"mtls_client_cert"`
Proxy string `toml:"proxy"`
}
type workerConfig struct {
Composer *composerConfig `toml:"composer"`
Koji map[string]kojiServerConfig `toml:"koji"`
GCP *gcpConfig `toml:"gcp"`
Azure *azureConfig `toml:"azure"`
AWS *awsConfig `toml:"aws"`
GenericS3 *genericS3Config `toml:"generic_s3"`
Authentication *authenticationConfig `toml:"authentication"`
Containers *containersConfig `toml:"containers"`
OCI *ociConfig `toml:"oci"`
Pulp *pulpConfig `toml:"pulp"`
// default value: /api/worker/v1
BasePath string `toml:"base_path"`
DNFJson string `toml:"dnf-json"`
// default value: &{ Type: host }
OSBuildExecutor *executorConfig `toml:"osbuild_executor"`
RepositoryMTLSConfig *repositoryMTLSConfig `toml:"repository_mtls"`
// something like "production" or "staging" to be added to logging
DeploymentChannel string `toml:"deployment_channel"`
}
func parseConfig(file string) (*workerConfig, error) {
// set defaults
config := workerConfig{
BasePath: "/api/worker/v1",
OSBuildExecutor: &executorConfig{
Type: "host",
},
DeploymentChannel: "local",
}
_, err := toml.DecodeFile(file, &config)
if err != nil {
// Return error only when we failed to decode the file.
// A non-existing config isn't an error, use defaults in this case.
if !os.IsNotExist(err) {
return nil, err
}
logrus.Info("Configuration file not found, using defaults")
}
// set defaults for Azure only if the config section is present
if config.Azure != nil {
if config.Azure.UploadThreads == 0 {
config.Azure.UploadThreads = azure.DefaultUploadThreads
} else if config.Azure.UploadThreads < 0 {
return nil, fmt.Errorf("invalid number of Azure upload threads: %d", config.Azure.UploadThreads)
}
}
switch config.OSBuildExecutor.Type {
case "host", "aws.ec2", "qemu.kvm":
// good and supported
default:
return nil, fmt.Errorf("OSBuildExecutor needs to be host, aws.ec2, or qemu.kvm. Got: %s.", config.OSBuildExecutor)
}
return &config, nil
}