Help us shape the future of Go! Take the 2026 Go Developer Survey

setup

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package setup is the first run every surface shares: where the configuration file goes, Jira's address and token checked against Jira before they are kept, the OS keychain offered for the token, a messaging webhook, and the file written. The command line's `config init` asks its questions at a prompt; the terminal and the web ask the same ones in a form.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrExists reports a file setup would have written over: it holds
	// credentials that are not recoverable once overwritten.
	ErrExists = errors.New("configuration file already exists")
	// ErrNoKeychain reports the token asked to be kept in a keychain where
	// none is wired, or under a dry run.
	ErrNoKeychain = errors.New("there is no keychain here to keep the token in")
	// ErrNoHome reports a file asked for in a home directory where none is
	// known.
	ErrNoHome = errors.New("there is no home directory here to keep the file in")
	// ErrNoToken reports a token asked to be kept in the keychain that is
	// empty: storing it would replace whatever the keychain kept before.
	ErrNoToken = errors.New("there is no token to keep in the keychain")
)

Errors a setup reports. Callers tell them apart with errors.Is.

Functions

func Beneath

func Beneath(layers config.Files) (config.Config, config.Revision, error)

Beneath is the configuration a new file starts from — the home file's, when it lies over one, or the defaults — at the revision of the pair, which the save must still find them at.

func Check

func Check(ctx context.Context, doer jira.Doer, settings config.Jira) (string, error)

Check asks Jira over doer who the token in settings authenticates as, and names them.

func Create

func Create(path string, layers config.Files, cfg config.Config, over config.Revision) error

Create writes cfg to path as Save does, but only as a new file: anything already there, a link included, is refused with ErrExists and nothing is written, so a file made between RefuseExisting and the write is never replaced and a link is never followed.

func Identify

func Identify(user jira.User) string

Identify names a user, falling back to the login when an instance is configured to withhold display names.

func Keep

func Keep(
	ctx context.Context, store func(ctx context.Context, service, secret string) error, settings config.Jira,
) (config.Jira, error)

Keep moves the token in settings into the OS keychain through store, under the item for its address and under ctx, so the file reads it from there rather than holding the secret. An empty token is refused with ErrNoToken before store is asked: kept, it would replace whatever the keychain held for the address.

func Keepable

func Keepable(err error) bool

Keepable reports whether a check that failed with err may be kept anyway: a Jira that is unreachable or refuses the token now may answer later, but an address that is not one never will, and one carrying a username and password must never reach the file.

func NotIgnored

func NotIgnored(ctx context.Context, path string) bool

NotIgnored reports a file inside a repository that git does not ignore, which, holding credentials, could be committed. Outside a repository there is nothing to commit it to.

func RefuseExisting

func RefuseExisting(path string) error

RefuseExisting refuses anything already at path: a file, or a link, even one to nothing, which a write would follow to wherever it points.

Types

type Answers

type Answers struct {
	Jira    config.Jira
	Webhook config.Secret
}

Answers are what setup asks: Jira's address and token, and a Slack incoming webhook. A blank address or webhook skips that question.

func (Answers) Over

func (a Answers) Over(cfg config.Config) config.Config

Over is cfg with the answers in place of its own, and as it was where a question was left blank, so a blank answer over a home file keeps the home file's.

type Destination

type Destination struct {
	Place    Place
	Path     string
	Keychain bool
}

Destination is a place a file may go, the file it would be, and whether the keychain can keep the token for that file: wherever one is wired, since any file may read the item kept for its Jira address.

type Guide

type Guide struct {
	Where       Where
	Doer        jira.Doer
	StoreSecret func(ctx context.Context, service, secret string) error
}

Guide is setup as a form asks for it, all answers at once: where it runs, the transport Jira is checked over, and the OS keychain, keeping a secret under the item named, under the context it is asked under, nil where none is wired.

func (Guide) Check

func (g Guide) Check(ctx context.Context, settings config.Jira) (string, error)

Check asks Jira who the token in settings authenticates as.

func (Guide) Offer

func (g Guide) Offer() Offer

Offer is where the file may go here, and whether the keychain can keep the token for each.

func (Guide) Write

func (g Guide) Write(ctx context.Context, request Request) (Written, error)

Write writes the file request asks for, unless one is already there: the answers over the home file it lies over, the token in the keychain item for its address when asked. It checks nothing; a form checks the token first and says how that went. Everything that can refuse the write does before the keychain is touched, and the file is made before the keychain keeps the token, so a write that fails leaves the keychain as it was. The keychain keeps the token under ctx.

type Offer

type Offer struct {
	Places []Destination
}

Offer is what a form offers: where the file may go, the repository first.

type Place

type Place string

Place is where setup writes the file.

const (
	// Repository is the repository's root, so every subdirectory sees it, or
	// the working directory outside a repository.
	Repository Place = "repository"
	// Home is the home directory, where every directory sees it.
	Home Place = "home"
)

The places a file may go.

type Request

type Request struct {
	Place    Place
	Answers  Answers
	Keychain bool
}

Request is a setup a form asks for: where, the answers, and whether the token goes to the keychain.

type Where

type Where struct {
	WorkDir string
	HomeDir string
}

Where is where setup runs: the working directory and the home directory.

func (Where) IsHomeFile added in v0.9.0

func (w Where) IsHomeFile(place Place) bool

IsHomeFile reports whether the file for place is the home directory's: the home place, or the repository's where the repository's root is the home directory.

func (Where) Layers

func (w Where) Layers(place Place) config.Files

Layers are the home file the file for place lies over, and that file; empty when it stands alone: written to the home directory, where the repository's root is the home directory, with no home directory known, or with no home file to lie over.

func (Where) Path

func (w Where) Path(place Place) string

Path is the file setup writes for place.

func (Where) Places

func (w Where) Places() []Place

Places are where the file may go here: the repository, and the home directory where one is known.

func (Where) RefuseLinked added in v0.9.0

func (w Where) RefuseLinked(place Place) error

RefuseLinked refuses the file for place when it is a link, to a file or to none yet, with config.ErrLinkedFile: replacing it would write wherever it points. Only the home file may be one, as a dotfiles checkout makes it.

func (Where) Save added in v0.9.0

func (w Where) Save(place Place, cfg config.Config, over config.Revision) error

Save writes cfg to the file for place, replacing whatever is there: over a home file, the layer that differs from it, while the pair is at the revision over, and otherwise a file of its own. A file other than the home file that is a link is refused, as RefuseLinked refuses it, and nothing is written.

type Written

type Written struct {
	Path       string
	Keychain   bool
	NotIgnored bool
}

Written is what a setup wrote: the file, whether the keychain keeps the token, and whether git would let the file be committed.

Jump to

Keyboard shortcuts

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