Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/registry-facade-api/go/config/config.go
2498 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
14
// ServiceConfig configures this service
15
type ServiceConfig struct {
16
Registry Config `json:"registry"`
17
AuthCfg string `json:"dockerAuth"`
18
PProfAddr string `json:"pprofAddr"`
19
PrometheusAddr string `json:"prometheusAddr"`
20
ReadinessProbeAddr string `json:"readinessProbeAddr"`
21
}
22
23
// GetConfig loads and validates the configuration
24
func GetConfig(fn string) (*ServiceConfig, error) {
25
fc, err := os.ReadFile(fn)
26
if err != nil {
27
return nil, err
28
}
29
30
var cfg ServiceConfig
31
err = json.Unmarshal(fc, &cfg)
32
if err != nil {
33
return nil, err
34
}
35
36
if cfg.Registry.IPFSCache != nil && cfg.Registry.IPFSCache.Enabled {
37
if cfg.Registry.RedisCache == nil || !cfg.Registry.RedisCache.Enabled {
38
return nil, xerrors.Errorf("IPFS cache requires Redis")
39
}
40
}
41
42
if cfg.Registry.RedisCache != nil {
43
rd := cfg.Registry.RedisCache
44
rd.Password = os.Getenv("REDIS_PASSWORD")
45
cfg.Registry.RedisCache = rd
46
}
47
48
return &cfg, nil
49
}
50
51
type TLS struct {
52
Authority string `json:"ca"`
53
Certificate string `json:"crt"`
54
PrivateKey string `json:"key"`
55
}
56
57
type RSProvider struct {
58
Addr string `json:"addr"`
59
TLS *TLS `json:"tls,omitempty"`
60
}
61
62
// Config configures the registry
63
type Config struct {
64
Port int `json:"port"`
65
Prefix string `json:"prefix"`
66
StaticLayer []StaticLayerCfg `json:"staticLayer"`
67
RemoteSpecProvider []*RSProvider `json:"remoteSpecProvider,omitempty"`
68
FixedSpecProvider string `json:"fixedSpecFN,omitempty"`
69
Store string `json:"store"`
70
RequireAuth bool `json:"requireAuth"`
71
TLS *TLS `json:"tls"`
72
73
IPFSCache *IPFSCacheConfig `json:"ipfs,omitempty"`
74
75
RedisCache *RedisCacheConfig `json:"redis,omitempty"`
76
}
77
78
type RedisCacheConfig struct {
79
Enabled bool `json:"enabled"`
80
81
SingleHostAddress string `json:"singleHostAddr,omitempty"`
82
83
Username string `json:"username,omitempty"`
84
Password string `json:"-" env:"REDIS_PASSWORD"`
85
86
UseTLS bool `json:"useTLS,omitempty"`
87
InsecureSkipVerify bool `json:"insecureSkipVerify,omitempty"`
88
}
89
90
type IPFSCacheConfig struct {
91
Enabled bool `json:"enabled"`
92
IPFSAddr string `json:"ipfsAddr"`
93
}
94
95
// StaticLayerCfg configure statically added layer
96
type StaticLayerCfg struct {
97
Ref string `json:"ref"`
98
Type string `json:"type"`
99
}
100
101