pcurl

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderRules

func RenderRules(c *Config) string

RenderRules returns the markdown rules text including the profile list.

Types

type AddOptions

type AddOptions struct {
	Name  string
	Test  bool
	Force bool
	Raw   bool
}

AddOptions controls pcurl add behavior.

type Config

type Config struct {
	Profiles map[string]*Profile `toml:"Profiles"`
}

Config represents the top-level profiles.toml structure.

func (*Config) FindProfile

func (c *Config) FindProfile(name string) *Profile

func (*Config) FindProfileByHost

func (c *Config) FindProfileByHost(host string) string

FindProfileByHost returns the profile name whose MatchHosts contains host.

type ConfigManager

type ConfigManager struct {
	// contains filtered or unexported fields
}

ConfigManager owns config file path and load/save operations.

func NewConfigManager

func NewConfigManager() *ConfigManager

func NewConfigManagerWithDir

func NewConfigManagerWithDir(dir string) *ConfigManager

NewConfigManagerWithDir creates a ConfigManager with a custom directory (for tests).

func (*ConfigManager) Dir

func (cm *ConfigManager) Dir() string

func (*ConfigManager) EnsureDir

func (cm *ConfigManager) EnsureDir() error

EnsureDir creates the config directory with 0700 permissions.

func (*ConfigManager) Load

func (cm *ConfigManager) Load() (*Config, error)

Load reads and parses profiles.toml. Returns empty config if file does not exist.

func (*ConfigManager) Path

func (cm *ConfigManager) Path() string

func (*ConfigManager) Save

func (cm *ConfigManager) Save(c *Config) error

Save writes config to profiles.toml with 0600 permissions.

type Executer

type Executer struct {
	CM      *ConfigManager
	Keyring keyring.Keyring
}

Executer holds shared dependencies and provides all pcurl commands.

func (*Executer) Add

func (e *Executer) Add(args []string, opts AddOptions, w io.Writer, in io.Reader, interactive bool) error

Add parses a curl command, classifies headers, prompts for storage, saves secrets, writes profile, and updates agent rules.

func (*Executer) Delete

func (e *Executer) Delete(name string, w io.Writer) error

Delete removes a profile from config and its keychain entries.

func (*Executer) Edit

func (e *Executer) Edit() error

Edit opens profiles.toml in $EDITOR.

func (*Executer) Exec

func (e *Executer) Exec(args []string, stderr io.Writer) (int, error)

Exec resolves a profile's headers, then executes curl. Looks for @profile in args. If not found, checks MatchHosts and warns.

func (*Executer) Install

func (e *Executer) Install() error

Install creates config directory and writes agent rules.

func (*Executer) List

func (e *Executer) List(w io.Writer) error

List prints all profiles to w.

func (*Executer) Show

func (e *Executer) Show(name string, w io.Writer) error

Show prints profile details with masked secret values.

func (*Executer) Uninstall

func (e *Executer) Uninstall(purge bool) error

Uninstall removes agent rules. Config kept unless purge.

type HeaderSource

type HeaderSource int

HeaderSource describes where a header value comes from.

const (
	SourcePlaintext HeaderSource = iota
	SourceKeychain
	SourceEnv
)

type Output

type Output struct {
	// contains filtered or unexported fields
}

Output collects lines and prints them all at once.

func (*Output) Addf

func (o *Output) Addf(format string, args ...any)

func (*Output) Empty

func (o *Output) Empty()

func (*Output) Print

func (o *Output) Print(w io.Writer)

func (*Output) String

func (o *Output) String() string

type ParsedSource

type ParsedSource struct {
	Name   string
	Source HeaderSource
	Ref    string
}

ParsedSource is the result of parsing a single header line from TOML.

func ParseHeaderSource

func ParseHeaderSource(raw string) ParsedSource

ParseHeaderSource splits "Authorization: keychain:gh/auth" into components.

type Profile

type Profile struct {
	Description string   `toml:"Description,omitempty"`
	MatchHosts  []string `toml:"MatchHosts"`
	Headers     []string `toml:"Headers"`
}

Profile represents a single named credential profile.

type Prompter

type Prompter struct {
	Out         io.Writer
	Interactive bool
	// contains filtered or unexported fields
}

Prompter handles all interactive prompts. When Interactive is true, uses huh TUI (arrow keys, space to toggle). Otherwise falls back to plain text input (for tests, pipes, non-TTY).

func NewPrompter

func NewPrompter(in io.Reader, out io.Writer, interactive bool) *Prompter

NewPrompter creates a Prompter with shared scanner.

func (*Prompter) ConfirmHostConflict added in v0.0.3

func (p *Prompter) ConfirmHostConflict(newName, existingName, host string) (bool, error)

ConfirmHostConflict asks whether to create a new profile when the host is already covered by a differently-named profile.

func (*Prompter) ConfirmUpdate

func (p *Prompter) ConfirmUpdate(profileName string) (bool, error)

ConfirmUpdate asks "Profile X already exists. Update? Y/n".

func (*Prompter) CookieStorage

func (p *Prompter) CookieStorage() (StorageChoice, error)

CookieStorage asks where to store selected cookies.

func (*Prompter) PickCookies

func (p *Prompter) PickCookies(cookies []curlparse.Cookie) error

PickCookies shows cookies and lets the user toggle selection.

func (*Prompter) PickHeaders

func (p *Prompter) PickHeaders(headers []curlparse.Header) error

PickHeaders shows non-secret headers and lets the user toggle selection.

func (*Prompter) Storage

func (p *Prompter) Storage(headerName, maskedValue string) (StorageChoice, error)

Storage asks where to store a secret header.

type ResolvedHeader

type ResolvedHeader struct {
	Name   string
	Value  string
	Secret bool
}

ResolvedHeader is a header ready to be passed to curl.

type RulesTarget

type RulesTarget struct {
	Name string
	Path string
}

RulesTarget describes a supported agent rules file location.

func DetectTargets

func DetectTargets() []RulesTarget

DetectTargets returns all agent rule targets found on the system.

type StorageChoice

type StorageChoice int

StorageChoice is where to store a secret value.

const (
	StoreKeychain StorageChoice = iota
	StoreConfig
	StoreSkip
)

Jump to

Keyboard shortcuts

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