Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/ws-proxy/pkg/config/config.go
2500 views
1
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package config
6
7
import (
8
"encoding/json"
9
"os"
10
11
"golang.org/x/xerrors"
12
13
"github.com/gitpod-io/gitpod/ws-proxy/pkg/proxy"
14
)
15
16
// Config configures this service.
17
type Config struct {
18
Ingress proxy.HostBasedIngressConfig `json:"ingress"`
19
Proxy proxy.Config `json:"proxy"`
20
PProfAddr string `json:"pprofAddr"`
21
PrometheusAddr string `json:"prometheusAddr"`
22
ReadinessProbeAddr string `json:"readinessProbeAddr"`
23
Namespace string `json:"namespace"`
24
WorkspaceManager *WorkspaceManagerConn `json:"wsManager"`
25
}
26
27
type WorkspaceManagerConn struct {
28
Addr string `json:"addr"`
29
TLS struct {
30
CA string `json:"ca"`
31
Cert string `json:"crt"`
32
Key string `json:"key"`
33
} `json:"tls"`
34
}
35
36
// Validate validates the configuration to catch issues during startup and not at runtime.
37
func (c *Config) Validate() error {
38
if err := c.Ingress.Validate(); err != nil {
39
return err
40
}
41
42
if err := c.Proxy.Validate(); err != nil {
43
return err
44
}
45
46
return nil
47
}
48
49
// GetConfig loads and validates the configuration.
50
func GetConfig(fn string) (*Config, error) {
51
fc, err := os.ReadFile(fn)
52
if err != nil {
53
return nil, err
54
}
55
56
var cfg Config
57
err = json.Unmarshal(fc, &cfg)
58
if err != nil {
59
return nil, err
60
}
61
62
err = cfg.Validate()
63
if err != nil {
64
return nil, xerrors.Errorf("config validation error: %w", err)
65
}
66
return &cfg, nil
67
}
68
69