confix

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

README


sidebar_position: 1

Confix

Confix is a configuration management tool that allows you to manage your configuration via CLI.

It is based on the CometBFT RFC 019.

Installation

Add Config Command

To add the confix tool, it's required to add the ConfigCommand to your application's root command file (e.g. <appd>/cmd/root.go).

Import the confixCmd package:

import "cosmossdk.io/tools/confix/cmd"

Find the following line:

initRootCmd(rootCmd, encodingConfig)

After that line, add the following:

rootCmd.AddCommand(
    confixcmd.ConfigCommand(),
)

The ConfixCommand function builds the config root command and is defined in the confixCmd package (cosmossdk.io/tools/confix/cmd). An implementation example can be found in simapp.

The command will be available as simd config.

Using Confix Standalone

To use Confix standalone, without having to add it in your application, install it with the following command:

go install cosmossdk.io/tools/confix/cmd/confix@latest

Alternatively, for building from source, simply run make confix. The binary will be located in tools/confix.

Usage

Use standalone:

confix --help

Use in simd:

simd config fix --help

Get

Get a configuration value, e.g.:

simd config get app pruning # gets the value pruning from app.toml
simd config get client chain-id # gets the value chain-id from client.toml
confix get ~/.simapp/config/app.toml pruning # gets the value pruning from app.toml
confix get ~/.simapp/config/client.toml chain-id # gets the value chain-id from client.toml

Set

Set a configuration value, e.g.:

simd config set app pruning "enabled" # sets the value pruning from app.toml
simd config set client chain-id "foo-1" # sets the value chain-id from client.toml
confix set ~/.simapp/config/app.toml pruning "enabled" # sets the value pruning from app.toml
confix set ~/.simapp/config/client.toml chain-id "foo-1" # sets the value chain-id from client.toml

Migrate

Migrate a configuration file to a new version, e.g.:

simd config migrate v0.47 # migrates defaultHome/config/app.toml to the latest v0.47 config
confix migrate v0.47 ~/.simapp/config/app.toml # migrate ~/.simapp/config/app.toml to the latest v0.47 config

Diff

Get the diff between a given configuration file and the default configuration file, e.g.:

simd config diff v0.47 # gets the diff between defaultHome/config/app.toml and the latest v0.47 config
confix diff v0.47 ~/.simapp/config/app.toml # gets the diff between ~/.simapp/config/app.toml and the latest v0.47 config

View

View a configuration file, e.g:

simd config view client # views the current app client config
confix view ~/.simapp/config/client.toml # views the current app client conf

Maintainer

At each SDK modification of the default configuration, add the default SDK config under data/v0.XX-app.toml. This allows users to use the tool standalone.

Credits

This project is based on the CometBFT RFC 019 and their own implementation of confix.

Documentation

Overview

Package confix applies changes to a Cosmos SDK TOML configuration file, to update configurations created with an older version of Cosmos SDK to a compatible format for a newer version.

Index

Constants

View Source
const (
	AppConfig    = "app.toml"
	ClientConfig = "client.toml"
	CMTConfig    = "config.toml"
)

Variables

View Source
var Migrations = MigrationMap{
	"v0.45": NoPlan,
	"v0.46": PlanBuilder,
	"v0.47": PlanBuilder,
	"v0.50": PlanBuilder,
}

Functions

func CheckValid

func CheckValid(fileName string, data []byte) error

CheckValid checks whether the specified config appears to be a valid Cosmos SDK config file. It tries to unmarshal the config into both the server and client config structs.

func LoadConfig

func LoadConfig(path string) (*tomledit.Document, error)

LoadConfig loads and parses the TOML document from path.

func LoadLocalConfig

func LoadLocalConfig(name string) (*tomledit.Document, error)

LoadConfig loads and parses the TOML document from confix data

func NoPlan

func NoPlan(_ *tomledit.Document, to string) transform.Plan

NoPlan returns a no-op plan.

func PlanBuilder

func PlanBuilder(from *tomledit.Document, to string) transform.Plan

PlanBuilder is a function that returns a transformation plan for a given diff between two files.

func PrintDiff

func PrintDiff(w io.Writer, diffs []Diff)

PrintDiff output prints one line per key that differs: -S name -- section exists in f1 but not f2 +S name -- section exists in f2 but not f1 -M name -- mapping exists in f1 but not f2 +M name -- mapping exists in f2 but not f1

func Upgrade

func Upgrade(ctx context.Context, plan transform.Plan, configPath, outputPath string, skipValidate bool) error

Upgrade reads the configuration file at configPath and applies any transformations necessary to Upgrade it to the current version. If this succeeds, the transformed output is written to outputPath. As a special case, if outputPath == "" the output is written to stdout.

It is safe if outputPath == inputPath. If a regular file outputPath already exists, it is overwritten. In case of error, the output is not written.

Upgrade is a convenience wrapper for calls to LoadConfig, ApplyFixes, and CheckValid. If the caller requires more control over the behavior of the Upgrade, call those functions directly.

func WithLogWriter

func WithLogWriter(ctx context.Context, w io.Writer) context.Context

WithLogWriter returns a child of ctx with a logger attached that sends output to w. This is a convenience wrapper for transform.WithLogWriter.

Types

type Diff

type Diff struct {
	Type    DiffType
	Deleted bool

	KV KV
}

func DiffKeys

func DiffKeys(lhs, rhs *tomledit.Document) []Diff

DiffKeys diffs the keyspaces of the TOML documents in files lhs and rhs. Comments, order, and values are ignored for comparison purposes.

func DiffValues

func DiffValues(lhs, rhs *tomledit.Document) []Diff

DiffKeys diffs the keyspaces with different values of the TOML documents in files lhs and rhs.

type DiffType

type DiffType string
const (
	Section DiffType = "S"
	Mapping DiffType = "M"
)

type KV

type KV struct {
	Key   string
	Value string
	Block []string // comment block
}

type MigrationMap

type MigrationMap map[string]func(from *tomledit.Document, to string) transform.Plan

MigrationMap defines a mapping from a version to a transformation plan.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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