config

package
v0.0.1-0...-ff937d3 Latest Latest
Warning

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

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

Documentation

Overview

Copyright © 2022 Roberto Hidalgo <joao@un.rob.mx> SPDX-License-Identifier: Apache-2.0

Copyright © 2022 Roberto Hidalgo <joao@un.rob.mx> SPDX-License-Identifier: Apache-2.0

Copyright © 2022 Roberto Hidalgo <joao@un.rob.mx> SPDX-License-Identifier: Apache-2.0

Copyright © 2022 Roberto Hidalgo <joao@un.rob.mx> SPDX-License-Identifier: Apache-2.0

Copyright © 2022 Roberto Hidalgo <joao@un.rob.mx> SPDX-License-Identifier: Apache-2.0

Copyright © 2022 Roberto Hidalgo <joao@un.rob.mx> SPDX-License-Identifier: Apache-2.0

Copyright © 2022 Roberto Hidalgo <joao@un.rob.mx> SPDX-License-Identifier: Apache-2.0

Index

Constants

View Source
const YAMLTypeMetaConfig string = "!!joao"
View Source
const YAMLTypeSecret string = "!!secret"

Variables

This section is empty.

Functions

func AutocompleteKeys

func AutocompleteKeys(cmd *command.Command, currentValue, config string) ([]string, cobra.ShellCompDirective, error)

func AutocompleteKeysAndParents

func AutocompleteKeysAndParents(cmd *command.Command, currentValue string, config string) (values []string, flag cobra.ShellCompDirective, err error)

func KeysFromYAML

func KeysFromYAML(data []byte) ([]string, error)

func VaultAndNameFrom

func VaultAndNameFrom(path string, buf []byte) (name string, vault string, err error)

VaultAndNameFrom path/buffer reads a path (unless a buffer is provided) and gets the 1Password item name and vault name: first, it looks at the embedded `_config: !!joao` YAML item. if it still needs a vault or name, it looks for the repo config, erroring if none found otherwise, it'll fill in missing values from the found repo config

Types

type Config

type Config struct {
	Vault string
	Name  string
	Tree  *Entry
}

func FromFile

func FromFile(path string) (*Config, error)

FromFile reads a path and returns a config.

func FromOP

func FromOP(item *op.Item) (*Config, error)

FromOP reads a config from an op item and returns a config.

func FromYAML

func FromYAML(data []byte) (*Config, error)

FromYAML reads yaml bytes and returns a config.

func Load

func Load(ref string, preferRemote bool) (*Config, error)

func (*Config) AsFile

func (cfg *Config) AsFile(path string, modes ...OutputMode) error

func (*Config) AsJSON

func (cfg *Config) AsJSON(redacted bool, item bool) ([]byte, error)

AsJSON returns the config enconded as JSON, optionally encoding as a 1Password item.

func (*Config) AsYAML

func (cfg *Config) AsYAML(modes ...OutputMode) ([]byte, error)

AsYAML returns the config encoded as YAML.

func (*Config) Delete

func (cfg *Config) Delete(path []string) error

Delete a value at path.

func (*Config) DiffRemote

func (cfg *Config) DiffRemote(path string, redacted, asFetch bool, stdout, stderr io.Writer) error

func (*Config) MarshalYAML

func (cfg *Config) MarshalYAML() (any, error)

MarshalYAML implements `yaml.Marshal“.

func (*Config) Merge

func (cfg *Config) Merge(other *Config) error

func (*Config) OPURL

func (cfg *Config) OPURL() string

func (*Config) Set

func (cfg *Config) Set(path []string, data []byte, isSecret, parseEntry bool) error

Set a new value, optionally parsing the supplied bytes as a secret or a JSON-encoded value.

func (*Config) ToMap

func (cfg *Config) ToMap(modes ...OutputMode) map[string]any

ToMap turns a config into a dictionary of strings to values.

func (*Config) ToOP

func (cfg *Config) ToOP() *op.Item

ToOp turns a config into an 1Password Item.

type Entry

type Entry struct {
	Value       string
	Kind        yaml.Kind
	Tag         string
	Path        []string
	Content     []*Entry
	Style       yaml.Style
	FootComment string
	LineComment string
	HeadComment string
	Line        int
	Column      int
	// The ShortTag
	Type string
}

Entry is a configuration entry. Basically a copy of a yaml.Node with extra methods.

func NewEntry

func NewEntry(name string, kind yaml.Kind) *Entry

func (*Entry) AsMap

func (e *Entry) AsMap() any

func (*Entry) ChildNamed

func (e *Entry) ChildNamed(name string) *Entry

func (*Entry) Contents

func (e *Entry) Contents() []*Entry

func (*Entry) FromOP

func (e *Entry) FromOP(fields []*op.ItemField) error

func (*Entry) IsScalar

func (e *Entry) IsScalar() bool

func (*Entry) IsSecret

func (e *Entry) IsSecret() bool

func (*Entry) MarshalYAML

func (e *Entry) MarshalYAML() (*yaml.Node, error)

func (*Entry) Merge

func (e *Entry) Merge(other *Entry) error

func (*Entry) Name

func (e *Entry) Name() string

func (*Entry) SetPath

func (e *Entry) SetPath(parent []string, current string)

func (*Entry) String

func (e *Entry) String() string

func (*Entry) ToOP

func (e *Entry) ToOP() []*op.ItemField

func (*Entry) TypeStr

func (e *Entry) TypeStr() string

func (*Entry) UnmarshalYAML

func (e *Entry) UnmarshalYAML(node *yaml.Node) error

type OutputMode

type OutputMode uint8
const (
	// OutputModeRoundTrip outputs the input as-is.
	OutputModeRoundTrip OutputMode = iota
	// OutputModeRedacted prints empty secret values.
	OutputModeRedacted
	// OutputModeNoComments does not output comments.
	OutputModeNoComments OutputMode = 2
	// OutputModeSorted outputs map keys in alphabetical order.
	OutputModeSorted OutputMode = 4
	// OutputModeNoConfig does not output the _config key if any.
	OutputModeNoConfig OutputMode = 8
	// OutputModeStandardYAML formats strings and arrays uniformly.
	OutputModeStandardYAML OutputMode = 16
)

Jump to

Keyboard shortcuts

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