config

package
v0.1.16 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package config resolves the credentials and endpoint used by pmock-cli.

Precedence (highest first):

flags (handled by the caller)
PMOCK_ACCESS_KEY / PMOCK_SECRET_KEY / PMOCK_BASE_URL / PMOCK_TIMEOUT
~/.pmock-cli/config.json
built-in defaults

The file is created with 0600 and its directory with 0700 because it holds a long-lived team secret.

Index

Constants

View Source
const (
	// DefaultBaseURL is the host prefix; every spec path starts with /open/api.
	DefaultBaseURL = "https://user.pmock.com/api"
	// DefaultTimeout is the per-request budget.
	DefaultTimeout = 30 * time.Second

	EnvAccessKey = "PMOCK_ACCESS_KEY"
	EnvSecretKey = "PMOCK_SECRET_KEY"
	EnvBaseURL   = "PMOCK_BASE_URL"
	EnvTimeout   = "PMOCK_TIMEOUT"
	// EnvConfigFile overrides the config path (tests, CI, multiple profiles).
	EnvConfigFile = "PMOCK_CLI_CONFIG"
)

Variables

This section is empty.

Functions

func Dir

func Dir() string

Dir returns the config directory.

func EnvOverrides

func EnvOverrides() []string

EnvOverrides lists the environment variables currently taking precedence.

func FileExists

func FileExists() bool

FileExists reports whether the config file exists.

func MaskAccessKey

func MaskAccessKey(v string) string

MaskAccessKey keeps the key recognizable without disclosing it.

func MaskSecret

func MaskSecret(v string) string

MaskSecret never reveals the secret.

func Path

func Path() string

Path returns the config file path.

func Save

func Save(cfg *Config) error

Save writes the configuration atomically with 0600 permissions. Empty endpoints are written as empty so a future default change is not pinned.

Types

type Config

type Config struct {
	AccessKey      string `json:"accessKey,omitempty"`
	SecretKey      string `json:"secretKey,omitempty"`
	BaseURL        string `json:"baseUrl,omitempty"`
	TimeoutSeconds int    `json:"timeoutSeconds,omitempty"`

	// Timeout is derived, never serialized.
	Timeout time.Duration `json:"-"`
}

Config is the persisted and effective CLI configuration.

func Load

func Load() (*Config, error)

Load returns a usable configuration or an actionable error.

func LoadFile

func LoadFile() (*Config, error)

LoadFile reads only the config file, ignoring environment overrides. It is used by `config init` so a CI-injected credential does not get copied into the user's file.

func LoadForDisplay

func LoadForDisplay() (*Config, error)

LoadForDisplay reads the file and applies environment overrides, tolerating a missing token (so `config show` works before setup).

func (*Config) Validate

func (c *Config) Validate() error

Validate checks that request signing is possible.

Jump to

Keyboard shortcuts

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