cs

package
v0.0.0-...-a8acacb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 25, 2024 License: GPL-3.0 Imports: 22 Imported by: 0

README

Centralsource provides a cenrtal place for configs for Nodes.

Nodes connect to a CS instance (a gRPC server) and the CS instance streams changes as they are made. CS also allows changing the config during runtime using token authentication. The current config is saved to a backport path (e.g. /etc/qrystal/cs-backport.yml) for backup and recovery purposes (the recovery code is currently broken).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MissingFromFirst

func MissingFromFirst[T any](m1 map[string]T, m2 map[string]T) []string

func SliceToMap

func SliceToMap(ss []string) map[string]struct{}

Types

type Backport

type Backport struct {
	CC     *central.Config   `yaml:"cc"`
	Tokens map[string]string `yaml:"tokens"`
}

type CanAdminTokens

type CanAdminTokens struct {
	CanPull bool `yaml:"canPull"`
	CanPush bool `yaml:"canPush"`
}

type CanPush

type CanPush struct {
	Any      bool                      `yaml:"any"`
	Networks map[string]CanPushNetwork `yaml:"networks"`
}

type CanPushNetwork

type CanPushNetwork struct {
	Name             string
	CanSeeElement    []string
	CanSeeElementAny bool
}

func (*CanPushNetwork) MarshalYaml

func (c *CanPushNetwork) MarshalYaml() (interface{}, error)

func (*CanPushNetwork) UnmarshalYAML

func (c *CanPushNetwork) UnmarshalYAML(value *yaml.Node) error

type CentralSource

type CentralSource struct {
	Tokens TokenStore
	// contains filtered or unexported fields
}

func New

func New(cc central.Config, backportPath string, db *buntdb.DB) (*CentralSource, error)

func (*CentralSource) AddTokens

func (s *CentralSource) AddTokens(ts []Token) error

func (*CentralSource) Handle

func (c *CentralSource) Handle(addr string, tlsCfg TLS) error

func (*CentralSource) HandleRyo

func (c *CentralSource) HandleRyo(addr string, tlsCfg TLS) error

func (*CentralSource) ReadBackport

func (s *CentralSource) ReadBackport() error

func (*CentralSource) ReplaceCC

func (s *CentralSource) ReplaceCC(cc *central.Config)

type Config

type Config struct {
	Addr         string          `yaml:"addr"`
	RyoAddr      string          `yaml:"ryoAddr"`
	TLS          TLS             `yaml:"tls"`
	CC           *central.Config `yaml:"central"`
	Tokens       *TokensConfig   `yaml:"tokens"`
	BackportPath string          `yaml:"backportPath"`
	DBPath       string          `yaml:"dbPath"`
}

func LoadConfig

func LoadConfig(configPath string) (*Config, error)

type TLS

type TLS struct {
	CertPath string `yaml:"certPath"`
	KeyPath  string `yaml:"keyPath"`
}

type Token

type Token struct {
	Hash util.TokenHash
	Info TokenInfo
}

type TokenConfig

type TokenConfig struct {
	Name             string                 `yaml:"name" json:"name"`
	Hash             *util.TokenHash        `yaml:"hash" json:"hash"`
	Networks         map[string]string      `yaml:"networks" json:"networks"`
	CanPull          bool                   `yaml:"canPull"`
	CanPush          *CanPush               `yaml:"canPush"`
	CanAdminTokens   *CanAdminTokens        `yaml:"canAdminTokens"`
	CanSRVUpdate     bool                   `yaml:"canSRVUpdate"`
	SRVAllowances    []central.SRVAllowance `yaml:"srvAllowances"`
	SRVAllowancesAny bool                   `yaml:"srvAllowancesAny"`
}

type TokenInfo

type TokenInfo struct {
	Name     string
	Networks map[string]string
	CanPull  bool
	CanPush  *CanPush
	// CanAdminTokens specifies whether this token can add *or remove* tokens.
	CanAdminTokens *CanAdminTokens
	// CanSRVUpdate allows updating SRV allowances for peers it can push to.
	CanSRVUpdate bool
	// SRVAllowance is a ORed list of SRV alloances for peers it can push to.
	SRVAllowances []central.SRVAllowance
	// SRVAllowancesAny allows updating SRV allowances without restrictions by SRVAllowances.
	SRVAllowancesAny bool

	Using    bool
	LastUsed time.Time
	// contains filtered or unexported fields
}

func (*TokenInfo) StartUse

func (ti *TokenInfo) StartUse()

func (*TokenInfo) StopUse

func (ti *TokenInfo) StopUse()

func (*TokenInfo) Use

func (ti *TokenInfo) Use()

type TokenStore

type TokenStore struct {
	// contains filtered or unexported fields
}

func (*TokenStore) AddToken

func (s *TokenStore) AddToken(hash util.TokenHash, info TokenInfo, overwrite bool) (err error)

func (*TokenStore) GetTokenByHash

func (s *TokenStore) GetTokenByHash(hashString string) (info TokenInfo, ok bool, err error)

func (*TokenStore) RemoveToken

func (s *TokenStore) RemoveToken(hash util.TokenHash) (err error)

func (*TokenStore) UpdateToken

func (s *TokenStore) UpdateToken(info TokenInfo) (err error)

type TokensConfig

type TokensConfig struct {
	Raw []Token
}

func (*TokensConfig) UnmarshalJSON

func (t *TokensConfig) UnmarshalJSON(data []byte) error

func (*TokensConfig) UnmarshalYAML

func (t *TokensConfig) UnmarshalYAML(value *yaml.Node) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL