config

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AppName is the directory name used under the OS config dir.
	AppName = "gh-secrets-sync"
	// ConfigFileName is the name of the config file.
	ConfigFileName = "secrets.yaml"

	// EnvConfigFile is the environment variable that overrides the config file path.
	EnvConfigFile = "GH_SECRETS_SYNC_CONFIG_FILE"
)

Variables

This section is empty.

Functions

func DefaultConfigPath

func DefaultConfigPath() (string, error)

DefaultConfigPath returns the OS-appropriate path for the secrets.yaml config file, using os.UserConfigDir() for cross-platform compatibility.

It checks for the GH_SECRETS_SYNC_CONFIG_FILE environment variable first.

Linux/macOS: ~/.config/gh-secrets-sync/secrets.yaml Windows: %APPDATA%\gh-secrets-sync\secrets.yaml

func EnsureConfigExists

func EnsureConfigExists(path string) (created bool, err error)

EnsureConfigExists checks whether the config file at path exists and creates it (along with any missing parent directories) if it does not.

The directory is created with 0700 permissions and the file with 0600 permissions. It returns true when the file was newly created and false when it already existed.

Types

type Config

type Config struct {
	Secrets []Secret `yaml:"secrets"`
}

Config is the top-level structure of secrets.yaml.

func Load

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

Load reads and parses the YAML config file at path. It returns a descriptive error (including the file path) when the file cannot be read or contains invalid YAML.

func (*Config) AddSecret

func (cfg *Config) AddSecret(s Secret, force bool) error

AddSecret adds s to cfg. It returns an error if a secret with the same name already exists and force is false. When force is true the existing entry is overwritten in place (preserving its position in the slice).

func (*Config) DeleteSecret

func (cfg *Config) DeleteSecret(name string) error

DeleteSecret removes the secret with the given name from cfg. It returns an error if no secret with that name exists.

func (*Config) Save

func (cfg *Config) Save(path string) error

Save marshals cfg to YAML and writes it to path with 0600 permissions.

func (*Config) UpdateSecret

func (cfg *Config) UpdateSecret(name string, patch Secret) error

UpdateSecret updates an existing secret by name. Only non-zero fields in patch are applied: if patch.Value is non-empty it replaces the current value; if patch.Repositories is non-nil it replaces the current repo list, including with an explicit empty slice. Returns an error if no secret with the given name exists.

type Secret

type Secret struct {
	Name         string   `yaml:"name"`
	Value        string   `yaml:"value"`
	Repositories []string `yaml:"repositories"`
}

Secret represents a single secret entry in the config file.

Jump to

Keyboard shortcuts

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