Path: blob/main/components/registry-facade-api/go/config/config.go
2498 views
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package config56import (7"encoding/json"8"os"910"golang.org/x/xerrors"11)1213// ServiceConfig configures this service14type ServiceConfig struct {15Registry Config `json:"registry"`16AuthCfg string `json:"dockerAuth"`17PProfAddr string `json:"pprofAddr"`18PrometheusAddr string `json:"prometheusAddr"`19ReadinessProbeAddr string `json:"readinessProbeAddr"`20}2122// GetConfig loads and validates the configuration23func GetConfig(fn string) (*ServiceConfig, error) {24fc, err := os.ReadFile(fn)25if err != nil {26return nil, err27}2829var cfg ServiceConfig30err = json.Unmarshal(fc, &cfg)31if err != nil {32return nil, err33}3435if cfg.Registry.IPFSCache != nil && cfg.Registry.IPFSCache.Enabled {36if cfg.Registry.RedisCache == nil || !cfg.Registry.RedisCache.Enabled {37return nil, xerrors.Errorf("IPFS cache requires Redis")38}39}4041if cfg.Registry.RedisCache != nil {42rd := cfg.Registry.RedisCache43rd.Password = os.Getenv("REDIS_PASSWORD")44cfg.Registry.RedisCache = rd45}4647return &cfg, nil48}4950type TLS struct {51Authority string `json:"ca"`52Certificate string `json:"crt"`53PrivateKey string `json:"key"`54}5556type RSProvider struct {57Addr string `json:"addr"`58TLS *TLS `json:"tls,omitempty"`59}6061// Config configures the registry62type Config struct {63Port int `json:"port"`64Prefix string `json:"prefix"`65StaticLayer []StaticLayerCfg `json:"staticLayer"`66RemoteSpecProvider []*RSProvider `json:"remoteSpecProvider,omitempty"`67FixedSpecProvider string `json:"fixedSpecFN,omitempty"`68Store string `json:"store"`69RequireAuth bool `json:"requireAuth"`70TLS *TLS `json:"tls"`7172IPFSCache *IPFSCacheConfig `json:"ipfs,omitempty"`7374RedisCache *RedisCacheConfig `json:"redis,omitempty"`75}7677type RedisCacheConfig struct {78Enabled bool `json:"enabled"`7980SingleHostAddress string `json:"singleHostAddr,omitempty"`8182Username string `json:"username,omitempty"`83Password string `json:"-" env:"REDIS_PASSWORD"`8485UseTLS bool `json:"useTLS,omitempty"`86InsecureSkipVerify bool `json:"insecureSkipVerify,omitempty"`87}8889type IPFSCacheConfig struct {90Enabled bool `json:"enabled"`91IPFSAddr string `json:"ipfsAddr"`92}9394// StaticLayerCfg configure statically added layer95type StaticLayerCfg struct {96Ref string `json:"ref"`97Type string `json:"type"`98}99100101