factory

package
v1.135.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultBaseRepo added in v1.4.0

func DefaultBaseRepo(runner run.Runner, cfg func() (*config.Config, error)) func() (bbrepo.RepoRef, error)

func EnableRepoOverride added in v1.4.0

func EnableRepoOverride(cmd *cobra.Command, f *Factory)

EnableRepoOverride registers a persistent -R/--repo flag on cmd and wires a PersistentPreRunE that swaps f.BaseRepo with an override resolver when the flag (or BB_REPO env) is set. The expected format is [HOST/]PROJECT/REPO; bare PROJECT/REPO uses the single configured host.

Parsing/host-inference for the override is delegated to ResolveTarget so the rules stay in one place.

func ResolveHost added in v1.13.0

func ResolveHost(f *Factory, hostname string) (string, error)

ResolveHost returns the host the caller should target.

Rules:

  1. If hostname is non-empty, it wins — no config lookup is performed. Callers that already know which host they want (e.g. a --hostname flag, or an MCP tool's `hostname` arg) shouldn't pay for IO.
  2. Otherwise consult config: - exactly one host configured → use it - zero hosts → "not authenticated" error - multiple hosts → "specify hostname" error

This is the single host-inference rule shared by both surfaces: the CLI's ResolveTarget (when args contain a bare PROJECT/REPO) and the MCP handlers (which take hostname as a tool arg, never positional).

func ResolveTarget added in v1.12.0

func ResolveTarget(f *Factory, args []string, hostnameFlag string) (bbrepo.RepoRef, error)

ResolveTarget returns the repository the command should act on.

Resolution order:

  1. If hostnameFlag is set, it overrides whichever Host was resolved.
  2. If args contains exactly one element, it is parsed as [HOST/]PROJECT/REPO. (Implemented in a later cycle.)
  3. Otherwise f.BaseRepo() is consulted — which already honours -R/--repo, BB_REPO, pinned git config, and the origin remote.

This is the single resolver every command should use. It replaces:

  • factory.Factory.ResolveRef (REQUIRED positional arg, ignored BaseRepo)
  • pr.resolveRepoRef (PR-package local duplicate)
  • pr.resolvePRTarget (now layered on top of this)

Effect: -R works everywhere, not just `pr list`. Commands that today require PROJECT/REPO can accept zero args and fall back to BaseRepo.

func ResolveToken added in v1.108.0

func ResolveToken(hostCfg config.HostConfig, kr keyring.Keyring) string

ResolveToken returns the token to use for the given host. When the config-file token is non-empty it wins (preserving the pre-migrate shape and the in-memory --with-token override). Otherwise — the canonical post-`auth migrate` shape — fall back to the keyring under the user-slug key. An empty User slug means we can't form the keyring key, so we return empty cleanly (the caller surfaces a normal "not authenticated" error). Errors from the keyring (timeout, not-found) are deliberately swallowed so a stuck keyring daemon can't brick every command — the empty-token path produces the same 401 the user would see without keyring at all. See PRD #372 Bug B.

Types

type Factory

type Factory struct {
	IOStreams          *iostreams.IOStreams
	Config             func() (*config.Config, error)
	Backend            func(hostname string) (backend.Client, error)
	BackendWithOptions func(hostname string, opts backend.Options) (backend.Client, error)
	HTTPClient         func(hostname string) (HTTPClient, error)
	UserConfig         func() (*userconfig.Config, error)
	Aliases            func() (*aliases.Store, error)
	Profiles           func() (*profiles.Store, error)
	GitRunner          func() run.Runner
	Keyring            keyring.Keyring
	Browser            cmdutil.BrowserLauncher
	Editor             cmdutil.EditorLauncher
	BaseURL            func(hostname string) string
	BaseRepo           func() (bbrepo.RepoRef, error)
	Now                func() time.Time
	// ServerPATURLProber resolves the PAT management URL for Bitbucket Server/DC
	// by probing which URL format the instance accepts. Injected here so tests
	// can stub it without real network calls. nil → default HEAD probe.
	ServerPATURLProber func(hostname, username string, skipTLS bool) string
	// TLSProber runs a handshake-only TLS dial against the host so
	// `auth login` can detect a self-signed/corporate CA before
	// pasting the PAT. Injected here for test substitution; nil → use
	// internal/tlsprobe.Probe directly.
	TLSProber func(ctx context.Context, host string, opts tlsprobe.Options) (*tlsprobe.Result, error)
	// ConfigDir is the root config directory (e.g. ~/.config/bitbottle).
	// Used by extension commands to locate the extensions subdirectory.
	ConfigDir func() string
	// SkipTLSOverride forces InsecureSkipVerify=true on the HTTP
	// transport for the current invocation, regardless of the per-host
	// SkipTLSVerify config. Set by the persistent root flag -k /
	// --skip-tls-verify so users can recover from a self-signed CA
	// failure without editing hosts.yml — the recovery path that the
	// `network.tls_unknown_authority` error hint promises.
	SkipTLSOverride bool
	// DebugHTTP enables verbose HTTP request/response logging to
	// IOStreams.ErrOut. Set by the persistent root flag --debug so users
	// can diagnose transport-level failures (timeouts, auth errors, etc.).
	DebugHTTP bool
}

func New

func New() *Factory

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

Directories

Path Synopsis
Package factorytest builds a *factory.Factory for tests with sane, minimal defaults.
Package factorytest builds a *factory.Factory for tests with sane, minimal defaults.

Jump to

Keyboard shortcuts

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