settings

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2025 License: MIT Imports: 21 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"
)

Config names (YAML field paths)

Variables

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

Functions

func AddRawTxFlag

func AddRawTxFlag(cmd *cobra.Command)

func AddSkipConfirmation

func AddSkipConfirmation(cmd *cobra.Command)

func AddTxnTypeFlags

func AddTxnTypeFlags(cmd *cobra.Command)

func BindEnv

func BindEnv(v *viper.Viper) error

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, stdin io.Reader) (string, error)

func GenerateProjectSettingsFile

func GenerateProjectSettingsFile(workingDirectory string, stdin io.Reader) (string, bool, error)

func GenerateWorkflowSettingsFile

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

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 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 IsValidChainName

func IsValidChainName(name string) error

func LoadEnv

func LoadEnv(envPath string) error

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 NormalizeHexKey

func NormalizeHexKey(k string) string

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 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 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
}

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 the `.env` file or system environment.

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