valuemodifier

package module
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: Apache-2.0 Imports: 5 Imported by: 2

README

CircleCI

valuemodifier

Package valuemodifier provides an interface to modify values of arbitrary structures in custom ways. Currently JSON and YAML formats are supported.

usage

This is an working example of how to use this package. For more examples check the go tests.

package main

import (
	"fmt"

	"github.com/giantswarm/valuemodifier"
	encodemodifier "github.com/giantswarm/valuemodifier/base64/encode"
	encryptmodifier "github.com/giantswarm/valuemodifier/gpg/encrypt"
)

func main() {
	var err error

	var encodeModifier valuemodifier.ValueModifier
	{
		modifierConfig := encodemodifier.DefaultConfig()
		encodeModifier, err = encodemodifier.New(modifierConfig)
		if err != nil {
			// error handling
		}
	}

	var encryptModifier valuemodifier.ValueModifier
	{
		modifierConfig := encryptmodifier.DefaultConfig()
		modifierConfig.Pass = "somesecretpassphrase"
		encryptModifier, err = encryptmodifier.New(modifierConfig)
		if err != nil {
			// error handling
		}
	}

	var newTraverser *valuemodifier.Service
	{
		config := valuemodifier.DefaultConfig()
		config.ValueModifiers = []valuemodifier.ValueModifier{encryptModifier, encodeModifier}
		newTraverser, err = valuemodifier.New(config)
		if err != nil {
			// error handling
		}
	}

	decrypted, err := newTraverser.TraverseJSON([]byte(`{"key":"val"}`))
	if err != nil {
		// error handling
	}

	// Variable decrypted holds the string "val" in GPG encrypted and base64 encoded
	// form.
	//
	//     {
	//       "key": "LS0tLS1CRUdJTiBQR1AgU0lHTkFUVVJFLS0tLS0KCnd4NEVCd01JdWk3S1BHcmRWK0JnU0U1RFJMVVY1L3l0UXp2dWwwUHhXS2JTNEFIa3Znc2ZreFJSZFZuUzdLVG4KTVkvZnJ1RXlCZURwNEp2aC90cmdBZUp6dDZGWjRQTGhZQ2JneXVCdTRKVGsrcWVzNm96dCtvUVJCRDcvTXNpSQpBZUxEeWk5bjRWYUdBQT09Cj14YTQ5Ci0tLS0tRU5EIFBHUCBTSUdOQVRVUkUtLS0tLQ=="
	//     }
	//
	fmt.Printf("%s\n", decrypted)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsExecutionFailed

func IsExecutionFailed(err error) bool

IsExecutionFailed asserts executionFailedError.

func IsFieldNotFound

func IsFieldNotFound(err error) bool

IsFieldNotFound asserts fieldNotFoundError.

func IsInvalidConfig

func IsInvalidConfig(err error) bool

IsInvalidConfig asserts invalidConfigError.

Types

type Config

type Config struct {
	// Dependencies.
	ValueModifiers []ValueModifier

	// Settings.
	IgnoreFields []string
	SelectFields []string
}

Config represents the configuration used to create a new value modifier traverser.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig provides a default configuration to create a new value modifier traverser by best effort.

type Service

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

Service implements the traversing value modifier.

func New

func New(config Config) (*Service, error)

New creates a new configured value modifier traverser.

func (*Service) Traverse

func (s *Service) Traverse(input []byte) ([]byte, error)

type ValueModifier

type ValueModifier interface {
	Modify(value []byte) ([]byte, error)
}

ValueModifier implements some modification mechanism for values being provided. This can e.g. be an implementation to encrypt a given value using GPG encryption standards or encode a given value using base64 encoding standard.

Directories

Path Synopsis
base64
gpg
vault

Jump to

Keyboard shortcuts

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