environment

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

README

Environment module

This module is used to get information about the running environment of a node.

It is also used to get the organization default configurations defined here according to the running mode.

Usage

To get information about the running environment of the node you can use one of the following:

  1. use environment.Get() to get the information if possible.

  2. use environment.MustGet() to get information or panic on error.

To get organization defined configurations:

  1. use environment.GetConfig() to get the organization configurations for the running mode.

  2. use environment.GetConfigForMode(mode) to get configurations for a specific mode.

Usage Example
env, err := environment.Get()
if err != nil {
    log.Fatal().Err(err).Msg("could not get information about running environment")
}

config, err := environment.GetConfigForMode(env.RunningMode)
if err != nil {
    log.Fatal().Err(err).Msgf("could not get configurations of mode %s", env.RunningMode)
}

Documentation

Index

Constants

View Source
const (
	// RunningDev mode
	RunningDev RunMode = "dev"
	// RunningQA mode
	RunningQA RunMode = "qa"
	// RunningTest mode
	RunningTest RunMode = "test"
	// RunningMain mode
	RunningMain RunMode = "prod"

	// Orphanage is the default farmid where nodes are registered
	// if no farmid were specified on the kernel command line
	OrphanageDev  pkg.FarmID = 0
	OrphanageTest pkg.FarmID = 0
	OrphanageMain pkg.FarmID = 0
)

Possible running mode of a node

Variables

This section is empty.

Functions

func GetSubstrate

func GetSubstrate() (substrate.Manager, error)

GetSubstrate gets a client to subsrate blockchain

Types

type Config

type Config struct {
	Yggdrasil struct {
		Peers []string `json:"peers"`
	} `json:"yggdrasil"`
	Mycelium struct {
		Peers []string `json:"peers"`
	} `json:"mycelium"`
	Users struct {
		Authorized []string `json:"authorized"`
	} `json:"users"`
	RolloutUpgrade struct {
		TestFarms []uint32 `json:"test_farms"`
	} `json:"rollout_upgrade"`
}

Config is configuration set by the organization

func GetConfig

func GetConfig() (base Config, err error)

GetConfig returns extend config for current run mode

func GetConfigForMode

func GetConfigForMode(mode RunMode) (Config, error)

GetConfig returns extend config for specific run mode

func (*Config) Merge

func (c *Config) Merge(cfg Config)

Merge, updates current config with cfg merging and override config based on some update rules.

type Environment

type Environment struct {
	RunningMode RunMode

	FlistURL string
	BinRepo  string

	FarmID pkg.FarmID
	Orphan bool

	FarmSecret   string
	SubstrateURL []string
	// IMPORTANT NOTICE:
	//   SINCE RELAYS FOR A NODE IS STORED ON THE CHAIN IN A LIMITED SPACE
	//   PLEASE MAKE SURE THAT ANY ENV HAS NO MORE THAN FOUR RELAYS CONFIGURED
	RelayURL      []string
	ActivationURL []string
	GraphQL       []string
	KycURL        string

	// private vlan to join
	// if set, zos will use this as its priv vlan
	PrivVlan *uint16

	// pub vlan to join
	// if set, zos will use this as it's pub vlan
	// only in a single nic setup
	PubVlan *uint16

	// PubMac value from environment
	PubMac PubMac
}

Environment holds information about running environment of a node it defines the different constant based on the running mode (dev, test, prod)

func Get

func Get() (Environment, error)

Get return the running environment of the node

func MustGet

func MustGet() Environment

MustGet returns the running environment of the node panics on error

type PubMac

type PubMac string

PubMac specify how the mac address of the public nic (in case of public-config) is calculated

const (
	// PubMacRandom means the mac of the public nic will be chosen by the system
	// the value won't change across reboots, but is based on the node id
	// (default)
	PubMacRandom PubMac = "random"
	// PubMacSwap means the value of the mac is swapped with the physical nic
	// where the public traffic is eventually going through
	PubMacSwap PubMac = "swap"
)

type RunMode

type RunMode string

RunMode type

func (RunMode) String

func (r RunMode) String() string

Jump to

Keyboard shortcuts

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