hiera

package
v0.6.8 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package hiera contains the Lookup functions to use when using Hiera as a library.

Index

Examples

Constants

View Source
const (
	// YAML render output in YAML
	YAML = RenderName(`yaml`)
	// JSON render output in JSON
	JSON = RenderName(`json`)
	// Binary render output as binary data
	Binary = RenderName(`binary`)
	// Text render output as plain text
	Text = RenderName(`s`)
)

Variables

This section is empty.

Functions

func DoWithParent

func DoWithParent(parent context.Context, tp hiera.LookupKey, options interface{}, consumer func(api.Session))

DoWithParent initializes a lookup context with global options and a top-level lookup key function and then calls the given consumer function with that context.

func Lookup

func Lookup(ic api.Invocation, name string, defaultValue dgo.Value, options interface{}) dgo.Value

Lookup performs a lookup using the given parameters.

ic - The lookup invocation

name - The name to lookup

defaultValue - Optional value to use as default when no value is found

options - Optional map with merge strategy and options

Example (MapProvider)
package main

import (
	"context"
	"fmt"

	"github.com/lyraproj/dgo/dgo"
	"github.com/lyraproj/dgo/vf"

	sdk "github.com/lyraproj/hierasdk/hiera"
	"github.com/yanndegat/hiera/api"
	"github.com/yanndegat/hiera/hiera"
)

func main() {
	sampleData := map[string]string{
		`a`: `value of a`,
		`b`: `value of b`}

	tp := func(ic sdk.ProviderContext, key string) dgo.Value {
		if v, ok := sampleData[key]; ok {
			return vf.String(v)
		}
		return nil
	}

	hiera.DoWithParent(context.Background(), tp, nil, func(hs api.Session) {
		fmt.Println(hiera.Lookup(hs.Invocation(nil, nil), `a`, nil, nil))
		fmt.Println(hiera.Lookup(hs.Invocation(nil, nil), `b`, nil, nil))
	})

}
Output:

value of a
value of b

func Lookup2

func Lookup2(
	ic api.Invocation,
	names []string,
	valueType dgo.Type,
	defaultValue dgo.Value,
	override dgo.Map,
	defaultValuesHash dgo.Map,
	options dgo.Map,
	defaultFunc dgo.Producer) dgo.Value

Lookup2 performs a lookup using the given parameters.

ic - The lookup invocation

names[] - The name or names to lookup

valueType - Optional expected type of the found value

defaultValue - Optional value to use as default when no value is found

override - Optional map to use as override. Values found here are returned immediately (no merge)

defaultValuesHash - Optional map to use as the last resort (but before defaultValue)

options - Optional map with merge strategy and options

defaultFunc - Optional function to produce a default value

func LookupAll

func LookupAll(
	ic api.Invocation,
	names []string,
	valueType dgo.StructMapType,
	override dgo.Map,
	defaultValuesHash dgo.Map,
	options dgo.Map) dgo.Value

LookupAll performs a lookup using the given parameters for all of the names passed in.

ic - The lookup invocation

names[] - The name or names to lookup

valueType - Optional expected type of the found value

override - Optional map to use as override. Values found here are returned immediately (no merge)

defaultValuesHash - Optional map to use as the last resort

options - Optional map with merge strategy and options

func LookupAndRender

func LookupAndRender(c api.Session, opts *CommandOptions, args []string, out io.Writer) bool

LookupAndRender performs a lookup using the given command options and arguments and renders the result on the given io.Writer in accordance with the `RenderAs` option.

func Render

func Render(s api.Session, renderAs RenderName, value dgo.Value, out io.Writer)

Render renders a value on a writer using a specified RenderName

func TryWithParent

func TryWithParent(parent context.Context, tp hiera.LookupKey, options interface{}, consumer func(api.Session) error) error

TryWithParent initializes a lookup context with global options and a top-level lookup key function and then calls the given consumer function with that context. If the given function panics, the panic will be recovered and returned as an error.

Types

type CommandOptions

type CommandOptions struct {
	// Type is a  Type string such as "string" or "[]int" used for assertion of the
	// found value.
	Type string

	// Merge is the name of a merge strategy
	Merge string

	// Default is a pointer to the string representation of a default value or nil if no default value exists
	Default *string

	// FactPaths are an optional paths to a files containing extra variables to add to the lookup scope
	// and as a copy under the lookup scope "facts" key.
	FactPaths []string

	// VarPaths are an optional paths to a files containing extra variables to add to the lookup scope
	VarPaths []string

	// Variables are an optional paths to a files containing extra variables to add to the lookup scope
	Variables []string

	// RenderAs is the name of the desired rendering
	RenderAs string

	// ExplainData should be set to true to explain the progress of a lookup
	ExplainData bool

	// ExplainOptions should be set to true to explain how lookup options were found for the lookup
	ExplainOptions bool

	LookupAll bool
}

A CommandOptions contains the options given by to the CLI lookup command or a REST invocation.

type RenderName

type RenderName string

RenderName is the name of the option value that describes how to render output

Jump to

Keyboard shortcuts

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