kuma

Форк
0
/
config.go 
88 строк · 3.2 Кб
1
package intercp
2

3
import (
4
	"time"
5

6
	"github.com/asaskevich/govalidator"
7
	"github.com/pkg/errors"
8
	"go.uber.org/multierr"
9

10
	config_types "github.com/kumahq/kuma/pkg/config/types"
11
)
12

13
func DefaultInterCpConfig() InterCpConfig {
14
	return InterCpConfig{
15
		Catalog: CatalogConfig{
16
			InstanceAddress:   "", // autoconfigured
17
			HeartbeatInterval: config_types.Duration{Duration: 5 * time.Second},
18
			WriterInterval:    config_types.Duration{Duration: 15 * time.Second},
19
		},
20
		Server: InterCpServerConfig{
21
			Port:            5683,
22
			TlsMinVersion:   "TLSv1_2",
23
			TlsCipherSuites: []string{},
24
		},
25
	}
26
}
27

28
type InterCpConfig struct {
29
	// Catalog configuration. Catalog keeps a record of all live CP instances in the zone.
30
	Catalog CatalogConfig `json:"catalog"`
31
	// Intercommunication CP server configuration
32
	Server InterCpServerConfig `json:"server"`
33
}
34

35
func (i *InterCpConfig) Validate() error {
36
	if err := i.Server.Validate(); err != nil {
37
		return errors.Wrap(err, ".Server validation failed")
38
	}
39
	if err := i.Catalog.Validate(); err != nil {
40
		return errors.Wrap(err, ".Catalog validation failed")
41
	}
42
	return nil
43
}
44

45
type CatalogConfig struct {
46
	// InstanceAddress indicates an address on which other control planes can communicate with this CP
47
	// If empty then it's autoconfigured by taking the first IP of the nonloopback network interface.
48
	InstanceAddress string `json:"instanceAddress" envconfig:"kuma_inter_cp_catalog_instance_address"`
49
	// Interval on which CP will send heartbeat to a leader.
50
	HeartbeatInterval config_types.Duration `json:"heartbeatInterval" envconfig:"kuma_inter_cp_catalog_heartbeat_interval"`
51
	// Interval on which CP will write all instances to a catalog.
52
	WriterInterval config_types.Duration `json:"writerInterval" envconfig:"kuma_inter_cp_catalog_writer_interval"`
53
}
54

55
func (i *CatalogConfig) Validate() error {
56
	if i.InstanceAddress != "" && !govalidator.IsDNSName(i.InstanceAddress) && !govalidator.IsIP(i.InstanceAddress) {
57
		return errors.New(".InstanceAddress has to be valid IP or DNS address")
58
	}
59
	return nil
60
}
61

62
type InterCpServerConfig struct {
63
	// Port on which Intercommunication CP server will listen
64
	Port uint16 `json:"port" envconfig:"kuma_inter_cp_server_port"`
65
	// TlsMinVersion defines the minimum TLS version to be used
66
	TlsMinVersion string `json:"tlsMinVersion" envconfig:"kuma_inter_cp_server_tls_min_version"`
67
	// TlsMaxVersion defines the maximum TLS version to be used
68
	TlsMaxVersion string `json:"tlsMaxVersion" envconfig:"kuma_inter_cp_server_tls_max_version"`
69
	// TlsCipherSuites defines the list of ciphers to use
70
	TlsCipherSuites []string `json:"tlsCipherSuites" envconfig:"kuma_inter_cp_server_tls_cipher_suites"`
71
}
72

73
func (i *InterCpServerConfig) Validate() error {
74
	var errs error
75
	if i.Port == 0 {
76
		errs = multierr.Append(errs, errors.New(".Port cannot be zero"))
77
	}
78
	if _, err := config_types.TLSVersion(i.TlsMinVersion); err != nil {
79
		errs = multierr.Append(errs, errors.New(".TlsMinVersion "+err.Error()))
80
	}
81
	if _, err := config_types.TLSVersion(i.TlsMaxVersion); err != nil {
82
		errs = multierr.Append(errs, errors.New(".TlsMaxVersion "+err.Error()))
83
	}
84
	if _, err := config_types.TLSCiphers(i.TlsCipherSuites); err != nil {
85
		errs = multierr.Append(errs, errors.New(".TlsCipherSuites "+err.Error()))
86
	}
87
	return errs
88
}
89

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.