config

package
v1.32.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: Apache-2.0 Imports: 13 Imported by: 4

Documentation

Overview

Package config provides configuration management for Privateer plugins.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoInstall added in v1.30.0

func AutoInstall() bool

AutoInstall reports whether runtime autoinstall is enabled (the "autoinstall" config key, also settable via the PVTR_AUTOINSTALL environment variable). When true, a harness preflight installs any config-requested plugins that are missing locally before the run, so a single `pvtr run` can install-and-run without a separate `pvtr install` step (e.g. in CI). It reads from the same viper state as NewConfig (e.g. after command.ReadConfig()).

func GetBinariesPath added in v1.23.0

func GetBinariesPath() string

GetBinariesPath returns the path to the directory where plugins are installed. It reads from the same viper state as NewConfig (e.g. after command.ReadConfig()).

func GetServicePlugin added in v1.23.0

func GetServicePlugin(serviceName string) string

GetServicePlugin returns the plugin name for the given service. It reads from the same viper state as NewConfig (e.g. after command.ReadConfig()).

func GetServiceVersion added in v1.30.0

func GetServiceVersion(serviceName string) string

GetServiceVersion returns the optional pinned plugin version for the given service. An empty string means "use the latest installed version". It reads from the same viper state as NewConfig (e.g. after command.ReadConfig()).

The value is normalized to the bare form the manifest and grc.store both use (a single leading "v" before a semver is stripped, so config's "v1.4.0" and "1.4.0" are equivalent). Without this, an exact-match lookup against a manifest keyed on bare versions would miss, and a hub release-list lookup would reject the "v"-prefixed string — surfacing a confusing "no version" error for what is just a formatting difference.

func GetServices added in v1.23.0

func GetServices() map[string]interface{}

GetServices returns the services map from config (service name -> service config). It reads from the same viper state as NewConfig (e.g. after command.ReadConfig()).

Types

type Config

type Config struct {
	ServiceName    string // Must be unique in the config file or logs will be overwritten
	LogLevel       string
	Logger         hclog.Logger
	Write          bool
	Output         string
	IncludePayload bool
	WriteDirectory string
	Invasive       bool
	Policy         Policy
	Vars           map[string]interface{}
	Error          error

	Benchmark            bool
	BenchmarkPayloadOnly bool
}

Config holds the configuration for a plugin execution.

func NewConfig

func NewConfig(requiredVars []string) Config

NewConfig creates a new Config instance from viper configuration.

func (*Config) GetBool

func (c *Config) GetBool(key string) bool

GetBool retrieves the value associated with the given key as a boolean. If the value is not of type boolean, it returns false.

Parameters:

  • key: The key name in the config vars.

Returns:

  • bool: The boolean value associated with the key, or false if the value is not a boolean.

func (*Config) GetBoolSlice

func (c *Config) GetBoolSlice(key string) []bool

GetBoolSlice retrieves a slice of boolean values from the configuration based on the provided key. If the key does not exist or the value is not of type []bool, it returns nil.

Parameters:

  • key: The key name in the config vars.

Returns:

  • []bool: A slice of boolean values if the key exists and the value is of type []bool.
  • nil: If the key does not exist or the value is not of type []bool.

func (*Config) GetInt

func (c *Config) GetInt(key string) int

GetInt retrieves the value associated with the given key as an integer. If the value is not of type int, it returns 0.

Parameters:

  • key: The key name in the config vars.

Returns:

  • int: The value associated with the key, or 0 if the value is not of type int.

func (*Config) GetIntSlice

func (c *Config) GetIntSlice(key string) []int

GetIntSlice retrieves the value associated with the given key as a slice of integers. If the value is not of type []int, it returns nil.

Parameters:

  • key: The key name in the config vars.

Returns:

  • []int: The value associated with the key as a slice of integers
  • nil: If the value is not of type []int or the key does not exist.

func (*Config) GetMap

func (c *Config) GetMap(key string) map[string]interface{}

GetMap retrieves a value from the configuration as a map[string]interface{}. It takes a key as a string and returns the corresponding value if it is of type map[string]interface{}. If the value is not of the expected type, it returns nil.

Parameters:

  • key: The key name in the config vars.

Returns:

  • map[string]interface{}: The value associated with the key if it is of the correct type
  • nil: If the value is not of type map[string]interface{} or the key does not exist.

func (*Config) GetString

func (c *Config) GetString(key string) string

GetString retrieves the value associated with the given key from the Config object. If the value is not of type string, it returns an empty string.

Parameters:

  • key: The key name in the config vars.

Returns:

  • string: The value associated with the key, or an empty string if the value is not of type string.

func (*Config) GetStringSlice

func (c *Config) GetStringSlice(key string) []string

GetStringSlice retrieves the value associated with the given key as a slice of strings. If the value is not of type []string, it returns nil.

Parameters:

  • key: The key name in the config vars.

Returns:

  • []string: The value associated with the key as a slice of strings
  • nil: If the value is not of type []string or the key does not exist.

func (*Config) GetVar

func (c *Config) GetVar(key string) (interface{}, string)

GetVar retrieves the value associated with the given key from the Config's Vars map. It returns the value as an interface{} and a string representing the type of the value. Useful for debugging in the event that a value is not being retrieved as expected.

Parameters:

  • key: The key name in the config vars.

Returns:

  • interface{}: The value associated with the key.
  • string: The type of the value associated with the key. If the key does not exist, it returns "missing".

func (*Config) SetupLogging

func (c *Config) SetupLogging(name string, jsonFormat bool)

SetupLogging configures logging for the plugin with the given name and format.

type Policy added in v1.0.0

type Policy struct {
	ControlCatalogs []string
	Applicability   []string
}

Policy defines the control catalogs and applicability settings for a plugin. TODO: We will want to replace this with a Gemara layer3 object now that those are ready.

Jump to

Keyboard shortcuts

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