Path: blob/main/components/ws-proxy/pkg/config/config.go
2500 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"1112"github.com/gitpod-io/gitpod/ws-proxy/pkg/proxy"13)1415// Config configures this service.16type Config struct {17Ingress proxy.HostBasedIngressConfig `json:"ingress"`18Proxy proxy.Config `json:"proxy"`19PProfAddr string `json:"pprofAddr"`20PrometheusAddr string `json:"prometheusAddr"`21ReadinessProbeAddr string `json:"readinessProbeAddr"`22Namespace string `json:"namespace"`23WorkspaceManager *WorkspaceManagerConn `json:"wsManager"`24}2526type WorkspaceManagerConn struct {27Addr string `json:"addr"`28TLS struct {29CA string `json:"ca"`30Cert string `json:"crt"`31Key string `json:"key"`32} `json:"tls"`33}3435// Validate validates the configuration to catch issues during startup and not at runtime.36func (c *Config) Validate() error {37if err := c.Ingress.Validate(); err != nil {38return err39}4041if err := c.Proxy.Validate(); err != nil {42return err43}4445return nil46}4748// GetConfig loads and validates the configuration.49func GetConfig(fn string) (*Config, error) {50fc, err := os.ReadFile(fn)51if err != nil {52return nil, err53}5455var cfg Config56err = json.Unmarshal(fc, &cfg)57if err != nil {58return nil, err59}6061err = cfg.Validate()62if err != nil {63return nil, xerrors.Errorf("config validation error: %w", err)64}65return &cfg, nil66}676869