settings

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EthPrivateKeyEnvVar = "CRE_ETH_PRIVATE_KEY"
	CreTargetEnvVar     = "CRE_TARGET"
)

sensitive information (not in configuration file)

View Source
const (
	WorkflowOwnerSettingName      = "account.workflow-owner-address"
	WorkflowNameSettingName       = "user-workflow.workflow-name"
	WorkflowPathSettingName       = "workflow-artifacts.workflow-path"
	ConfigPathSettingName         = "workflow-artifacts.config-path"
	SecretsPathSettingName        = "workflow-artifacts.secrets-path"
	SethConfigPathSettingName     = "logging.seth-config-path"
	RegistriesSettingName         = "contracts.registries"
	KeystoneSettingName           = "contracts.keystone"
	RpcsSettingName               = "rpcs"
	ExperimentalChainsSettingName = "experimental-chains" // used by simulator when present in target config
)

Config names (YAML field paths)

Variables

View Source
var Flags = flagNames{
	Owner:                Flag{"owner", "o"},
	ProjectRoot:          Flag{"project-root", "R"},
	CliEnvFile:           Flag{"env", "e"},
	CliPublicEnvFile:     Flag{"public-env", "E"},
	Verbose:              Flag{"verbose", "v"},
	Target:               Flag{"target", "T"},
	OverridePreviousRoot: Flag{"override-previous-root", "O"},
	RawTxFlag:            Flag{"unsigned", ""},
	Changeset:            Flag{"changeset", ""},
	Ledger:               Flag{"ledger", ""},
	LedgerDerivationPath: Flag{"ledger-derivation-path", ""},
	NonInteractive:       Flag{"non-interactive", ""},
	SkipConfirmation:     Flag{"yes", "y"},
	ChangesetFile:        Flag{"changeset-file", ""},
}
View Source
var ProjectEnvironmentTemplateContent string
View Source
var ProjectSettingsTemplateContent string

Functions

func AddSkipConfirmation

func AddSkipConfirmation(cmd *cobra.Command)

func AddTxnTypeFlags

func AddTxnTypeFlags(cmd *cobra.Command)

func BuildRPCsListYAML added in v1.2.0

func BuildRPCsListYAML(networks []string, rpcURLs map[string]string) string

BuildRPCsListYAML generates the indented rpcs YAML block for project.yaml. If networks is empty, falls back to the default (ethereum-testnet-sepolia).

func FindEnvFile added in v1.5.0

func FindEnvFile(startDir, fileName string) (string, error)

FindEnvFile walks up from startDir looking for a file named fileName.

func FindOrCreateProjectSettings

func FindOrCreateProjectSettings(startDir string, replacements map[string]string) error

func GenerateFileFromTemplate

func GenerateFileFromTemplate(outputPath string, templateContent string, replacements map[string]string) error

func GenerateGitIgnoreFile

func GenerateGitIgnoreFile(workingDirectory string) (string, error)

func GenerateProjectEnvFile

func GenerateProjectEnvFile(workingDirectory string) (string, error)

func GenerateProjectSettingsFile

func GenerateProjectSettingsFile(workingDirectory string) (string, bool, error)

func GenerateWorkflowSettingsFile

func GenerateWorkflowSettingsFile(workingDirectory string, workflowName string, workflowPath string) (string, error)

func GetAvailableTargets added in v1.3.0

func GetAvailableTargets() ([]string, error)

GetAvailableTargets reads project.yaml and returns the top-level keys that represent target configurations, preserving the order from the file.

func GetChainNameByChainSelector

func GetChainNameByChainSelector(chainSelector uint64) (string, error)

func GetChainSelectorByChainName

func GetChainSelectorByChainName(name string) (uint64, error)

func GetDefaultReplacements

func GetDefaultReplacements() map[string]string

func GetEnvironmentVariable

func GetEnvironmentVariable(filePath, key string) (string, error)

func GetMCMSConfig added in v1.0.6

func GetMCMSConfig(settings *Settings, chainSelector uint64) (*crecontracts.MCMSConfig, error)

func GetReplacementsWithNetworks added in v1.2.0

func GetReplacementsWithNetworks(networks []string, rpcURLs map[string]string) map[string]string

GetReplacementsWithNetworks returns template replacements including a dynamic RPCs list.

func GetRpcUrlSettings

func GetRpcUrlSettings(v *viper.Viper, chainName string) (string, error)

func GetTarget

func GetTarget(v *viper.Viper) (string, error)

func GetWorkflowOwner

func GetWorkflowOwner(v *viper.Viper) (ownerAddress string, ownerType string, err error)

func GetWorkflowPathFromFile added in v1.1.0

func GetWorkflowPathFromFile(workflowYAMLPath string) (string, error)

GetWorkflowPathFromFile reads workflow-path from a workflow.yaml file (same value deploy/simulate get from Settings).

func IsValidChainName

func IsValidChainName(name string) error

func LoadEnv

func LoadEnv(logger *zerolog.Logger, v *viper.Viper, envPath string)

LoadEnv loads environment variables from envPath into the process environment, binds sensitive variables into Viper, and logs outcomes. If envPath is empty no file is loaded and a debug message is emitted. Errors are logged but do not halt execution — the CLI continues so that commands which don't need the env file can still run.

func LoadPublicEnv added in v1.5.0

func LoadPublicEnv(logger *zerolog.Logger, envPath string)

LoadPublicEnv loads variables from envPath into the process environment. Unlike LoadEnv it does not bind sensitive variables into Viper — it is intended for non-sensitive, shared build configuration (e.g. GOTOOLCHAIN).

func LoadSettingsIntoViper

func LoadSettingsIntoViper(v *viper.Viper, cmd *cobra.Command) error

Loads the configuration file (if found) and sets the configuration values via Viper

func LoadedEnvFilePath added in v1.5.0

func LoadedEnvFilePath() string

LoadedEnvFilePath returns the .env path that was successfully loaded, or "".

func LoadedEnvVars added in v1.5.0

func LoadedEnvVars() map[string]string

LoadedEnvVars returns the key-value pairs parsed from the loaded .env file. Returns nil if no file was loaded.

func LoadedPublicEnvFilePath added in v1.5.0

func LoadedPublicEnvFilePath() string

LoadedPublicEnvFilePath returns the .env.public path that was successfully loaded, or "".

func LoadedPublicEnvVars added in v1.5.0

func LoadedPublicEnvVars() map[string]string

LoadedPublicEnvVars returns the key-value pairs parsed from the loaded .env.public file. Returns nil if no file was loaded.

func NormalizeHexKey

func NormalizeHexKey(k string) string

func PatchProjectRPCs added in v1.2.0

func PatchProjectRPCs(projectYAMLPath string, rpcURLs map[string]string) error

PatchProjectRPCs updates RPC URLs in an existing project.yaml file. It uses the yaml.Node API to preserve comments and formatting. Only entries whose chain-name matches a key in rpcURLs are updated.

func ResolveAndLoadEnv added in v1.5.0

func ResolveAndLoadEnv(logger *zerolog.Logger, v *viper.Viper, flagName, defaultFileName string)

ResolveAndLoadEnv resolves the .env file path from the given CLI flag (auto-detecting defaultFileName in parent dirs if the flag is empty), then loads it and binds sensitive variables into Viper.

func ResolveAndLoadPublicEnv added in v1.5.0

func ResolveAndLoadPublicEnv(logger *zerolog.Logger, v *viper.Viper, flagName, defaultFileName string)

ResolveAndLoadPublicEnv resolves the public env file path from the given CLI flag (auto-detecting defaultFileName in parent dirs if the flag is empty), then loads it into the process environment.

func ResolveEnvVars added in v1.5.0

func ResolveEnvVars(s string) (string, error)

ResolveEnvVars replaces all ${VAR_NAME} references in s with their corresponding environment variable values. It returns an error if any referenced variable is not set.

func SetWorkflowPathInFile added in v1.1.0

func SetWorkflowPathInFile(workflowYAMLPath, newPath string) error

SetWorkflowPathInFile sets workflow-path in workflow.yaml (both staging-settings and production-settings) and writes the file.

func ShouldSkipGetOwner

func ShouldSkipGetOwner(cmd *cobra.Command) bool

For commands that don't need the private key, we skip getting the owner address. ShouldSkipGetOwner returns true if the command is `simulate` and `--broadcast` is false or not set. `cre help` should skip as well.

Types

type CLDSettings added in v1.0.6

type CLDSettings struct {
	CLDPath                   string `mapstructure:"cld-path" yaml:"cld-path"`
	Environment               string `mapstructure:"environment" yaml:"environment"`
	Domain                    string `mapstructure:"domain" yaml:"domain"`
	MergeProposals            bool   `mapstructure:"merge-proposals" yaml:"merge-proposals"`
	WorkflowRegistryQualifier string `mapstructure:"workflow-registry-qualifier" yaml:"workflow-registry-qualifier"`
	ChangesetFile             string `mapstructure:"changeset-file" yaml:"changeset-file"`
	MCMSSettings              struct {
		MinDelay          string `mapstructure:"min-delay" yaml:"min-delay"`
		MCMSAction        string `mapstructure:"mcms-action" yaml:"mcms-action"`
		OverrideRoot      bool   `mapstructure:"override-root" yaml:"override-root"`
		TimelockQualifier string `mapstructure:"timelock-qualifier" yaml:"timelock-qualifier"`
		ValidDuration     string `mapstructure:"valid-duration" yaml:"valid-duration"`
	} `mapstructure:"mcms-settings" yaml:"mcms-settings"`
}

type CREStorageSettings

type CREStorageSettings struct {
	ServiceTimeout time.Duration `mapstructure:"servicetimeout"`
	HTTPTimeout    time.Duration `mapstructure:"httptimeout"`
}

type Contract

type Contract struct {
	Name          string `mapstructure:"name" yaml:"name"`
	Address       string `mapstructure:"address" yaml:"address"`
	ChainSelector uint64 `mapstructure:"chain-selector" yaml:"chain-selector"`
}

type ContractGroups

type ContractGroups struct {
	Registries []Contract `mapstructure:"registries" yaml:"registries"`
	KeyStone   []Contract `mapstructure:"keystone" yaml:"keystone"`
}

type ExperimentalChain added in v1.0.7

type ExperimentalChain struct {
	ChainSelector uint64 `mapstructure:"chain-selector" yaml:"chain-selector"`
	RPCURL        string `mapstructure:"rpc-url" yaml:"rpc-url"`
	Forwarder     string `mapstructure:"forwarder" yaml:"forwarder"`
}

ExperimentalChain represents an EVM chain not in official chain-selectors. Automatically used by the simulator when present in the target's experimental-chains config. The ChainSelector is used as the selector key for EVM clients and forwarders.

func GetExperimentalChains added in v1.0.7

func GetExperimentalChains(v *viper.Viper) ([]ExperimentalChain, error)

GetExperimentalChains reads the experimental-chains list from the current target. Returns an empty slice if the key is not set or unmarshalling fails.

type Flag

type Flag struct {
	Name  string
	Short string
}

type ProjectEnv

type ProjectEnv struct {
	FilePath       string
	GitHubAPIToken string
	EthPrivateKey  string
}

type RpcEndpoint

type RpcEndpoint struct {
	ChainName string `mapstructure:"chain-name" yaml:"chain-name"`
	// TODO: in the future, we can have a distinction between "public URL" and "private URL", with only one of them present at the time
	// "public URL" would be URL hidden behind the VPN or URL from ChainList, something that doesn't contain sensitive API tokens, e.g.
	// url_public: https://rpcs.cldev.sh/ethereum/sepolia
	// "private URL" can be feeded to the settings file by specifying the env var name where the real URL is kept, e.g.
	// url_private: RPC_URL_ETH_SEPOLIA
	Url string `mapstructure:"url" yaml:"url"`
}

type Settings

type Settings struct {
	Workflow        WorkflowSettings
	User            UserSettings
	StorageSettings WorkflowStorageSettings
	CLDSettings     CLDSettings
}

Settings holds user, project, and workflow configurations.

func New

func New(logger *zerolog.Logger, v *viper.Viper, cmd *cobra.Command, registryChainName string) (*Settings, error)

New initializes and loads settings from YAML config files and the environment. Environment loading (.env + BindEnv) is handled earlier in PersistentPreRunE so that all commands see the variables consistently.

type UserSettings

type UserSettings struct {
	TargetName    string
	EthPrivateKey string
	EthUrl        string
}

UserSettings stores user-specific configurations.

type WorkflowSettings

type WorkflowSettings struct {
	UserWorkflowSettings struct {
		WorkflowOwnerAddress string `mapstructure:"workflow-owner-address" yaml:"workflow-owner-address"`
		WorkflowOwnerType    string `mapstructure:"workflow-owner-type" yaml:"workflow-owner-type"`
		WorkflowName         string `mapstructure:"workflow-name" yaml:"workflow-name"`
	} `mapstructure:"user-workflow" yaml:"user-workflow"`
	WorkflowArtifactSettings struct {
		WorkflowPath string `mapstructure:"workflow-path" yaml:"workflow-path"`
		ConfigPath   string `mapstructure:"config-path" yaml:"config-path"`
		SecretsPath  string `mapstructure:"secrets-path" yaml:"secrets-path"`
	} `mapstructure:"workflow-artifacts" yaml:"workflow-artifacts"`
	LoggingSettings struct {
		SethConfigPath string `mapstructure:"seth-config-path" yaml:"seth-config-path"`
	} `mapstructure:"logging" yaml:"logging"`
	RPCs []RpcEndpoint `mapstructure:"rpcs" yaml:"rpcs"`
}

type WorkflowStorageSettings

type WorkflowStorageSettings struct {
	CREStorage CREStorageSettings `mapstructure:"cre_storage"`
}

func LoadWorkflowStorageSettings

func LoadWorkflowStorageSettings(logger *zerolog.Logger, v *viper.Viper) WorkflowStorageSettings

Jump to

Keyboard shortcuts

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