githubapp

package
v8.177.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 27 Imported by: ? 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 githubapp creates the GitHub Apps that giantswarm/github declares, through GitHub's manifest flow, and keeps their installations as declared.

It runs as a person on their own laptop: GitHub's pages open in their browser, the reads go out with their GitHub token, and an App's credentials go into their 1Password vault in one write, from this process. No credential is printed, logged, written to a file or put on the clipboard.

Index

Constants

View Source
const (
	// DeclarationsOwner is the organisation whose repository declares its
	// Apps, and which owns every App declared there.
	DeclarationsOwner = "giantswarm"
	// DeclarationsRepo is the repository of DeclarationsOwner that declares
	// the Apps, one directory apps/<name> each.
	DeclarationsRepo = "github"

	// ManifestFile is an App's manifest in its directory: the document
	// GitHub's manifest flow takes.
	ManifestFile = "manifest.json"
	// InstallationFile is an App's installation in its directory:
	// {"repositories": "all" | ["<name>", …]}.
	InstallationFile = "installation.json"
)
View Source
const (
	FieldAppID          = "app-id"
	FieldClientID       = "client-id"
	FieldSlug           = "slug"
	FieldClientSecret   = "client-secret"
	FieldPrivateKey     = "private-key"
	FieldWebhookSecret  = "webhook-secret"
	FieldInstallationID = "installation-id"
)

The fields of an App's 1Password item: the configuration as text, the credentials concealed.

Variables

This section is empty.

Functions

func IsRefused

func IsRefused(err error) bool

IsRefused reports whether err is a refusal.

func ParseInstallation

func ParseInstallation(raw []byte) ([]string, error)

ParseInstallation reads an installation file: the repositories by name, sorted and each once, nil for "all".

func Slug

func Slug(name string) string

Slug is the slug GitHub gives an App's name: lower case, each run of characters other than letters and digits one hyphen, none at the ends.

Types

type Created

type Created struct {
	Slug     string
	AppID    int64
	ClientID string
	URL      string
	// Item is the 1Password item, <vault>/<title>, and Fields the labels
	// written into it.
	Item   string
	Fields []string
	// Installation is the App's installation, nil until it exists.
	Installation *Installed
}

Created is what Create made: the App, its item and its installation.

func (*Created) Text

func (c *Created) Text() string

Text is the result for the person's terminal: ids and labels, no value.

type Credentials

type Credentials struct {
	ID            int64   `json:"id"`
	Slug          string  `json:"slug"`
	Name          string  `json:"name"`
	ClientID      string  `json:"client_id"`
	ClientSecret  string  `json:"client_secret"`
	WebhookSecret *string `json:"webhook_secret"`
	PEM           string  `json:"pem"`
	HTMLURL       string  `json:"html_url"`
}

Credentials are what GitHub's manifest conversion answers: the App and its credentials, which stay in this process until the vault holds them.

type Declaration

type Declaration struct {
	// Name is the App's name, its directory under apps/.
	Name string
	// Org is the organisation that owns the App and its installation.
	Org string
	// Manifest is the manifest document as declared, a JSON object.
	Manifest map[string]any
	// Repositories are the installation's repositories by name, sorted;
	// nil is all of the organisation's.
	Repositories []string
	// Source is where the manifest was read:
	// giantswarm/github@<commit>:apps/<name>/manifest.json.
	Source string
}

Declaration is an App as giantswarm/github declares it on its default branch: the manifest and the installation.

func ReadDeclaration

func ReadDeclaration(ctx context.Context, gh *github.Client, name string) (Declaration, error)

ReadDeclaration reads the App name from giantswarm/github's default branch: its manifest and its installation file at the same commit. A manifest that is missing, no JSON object, or names another App is a refusal, as is a missing or malformed installation file: the App is not declared.

func (Declaration) All

func (d Declaration) All() bool

All reports whether the installation is declared on all repositories.

func (Declaration) Selection

func (d Declaration) Selection() string

Selection is the declared installation in words.

type Env

type Env struct {
	// GitHub is the client with the person's token: the declaration, the
	// ids the installation page preselects, and the changes of an
	// installation's repositories.
	GitHub *github.Client
	// HTTP sends the conversion and the requests made as the App; nil is
	// http.DefaultClient.
	HTTP *http.Client
	// API and Web are GitHub's API and web site, with a trailing slash;
	// empty is https://api.github.com/ and https://github.com/.
	API, Web string
	Vault    Vault
	// Open opens a URL in the person's browser.
	Open func(url string) error
	// Progress is told each step, for the person.
	Progress io.Writer
	// Timeout bounds the wait for each of the person's clicks.
	Timeout time.Duration
	// Poll is how often an installation is read while waiting; 0 is 3s.
	Poll time.Duration
}

Env is what the commands act with: the person's GitHub token, browser and 1Password vault.

func (*Env) Create

func (e *Env) Create(ctx context.Context, name string) (*Created, error)

Create creates the App name that giantswarm/github declares, through GitHub's manifest flow, writes its credentials into the vault item name in one write, and waits for its installation, which it records in the same item and makes match the declaration.

Refused before any click, nothing written: an App not declared on the default branch, one GitHub knows by its name already, a vault item of its name, a declared repository the organisation lacks. Refused after the Create click, nothing written: a redirect whose state is not this run's, and no redirect within the timeout. An Install click that does not come leaves the credentials in the item and answers how to finish.

func (*Env) Install

func (e *Env) Install(ctx context.Context, name string) (*Installed, error)

Install makes the installation of the App name match its declared installation.json: it opens the App's installation page while there is none, records the installation's id in the App's vault item, has the person switch between all and selected repositories on the installation's settings page (GitHub's API cannot), and adds and removes selected repositories through the API with the person's token.

type Field

type Field struct {
	Label string
	Value string
	// Secret makes the field concealed; any other is a text field.
	Secret bool
}

Field is one field of a vault item.

type Installed

type Installed struct {
	App   string
	AppID int64
	ID    int64
	Org   string
	// Selection is GitHub's repository selection: all or selected.
	Selection string
	// Repositories are the selected ones' names.
	Repositories []string
	Added        []string
	Removed      []string
	// Recorded is set when the item's installation-id was written.
	Recorded string
}

Installed is an App's installation as Install, or Create, left it.

func (*Installed) Text

func (i *Installed) Text() string

Text is the installation for the person's terminal.

type Item

type Item struct {
	ID string
	// VaultID is the id of the vault that holds the item.
	VaultID string
	Title   string
	// Text are the item's text fields by label. A concealed field is not
	// among them: Reveal reads one.
	Text map[string]string
}

Item is a vault item as Find reads it: its id and its text fields.

type OnePassword

type OnePassword struct {
	// Vault is the vault's name or id.
	Vault string
	// Bin is the op executable; empty is op on $PATH.
	Bin string
}

OnePassword is the Vault of the person's 1Password CLI, op, signed in: through the 1Password desktop app's integration or `op signin`, with $OP_ACCOUNT choosing among several accounts. A credential travels to op on its stdin, never on its command line, and back on its stdout, never into an error.

func (*OnePassword) Create

func (o *OnePassword) Create(ctx context.Context, title, notes string, fields []Field) error

Create creates the item as a Password item from JSON on op's stdin. A Password item's built-in password must hold a value: it holds the first secret field's, which is also the item's field under its own label.

func (*OnePassword) Find

func (o *OnePassword) Find(ctx context.Context, title string) (*Item, error)

Find lists the vault's items, metadata only, and reads the one titled title: nil when there is none, an error when there are several.

func (*OnePassword) Name

func (o *OnePassword) Name() string

Name is the vault's name.

func (*OnePassword) Reveal

func (o *OnePassword) Reveal(ctx context.Context, item *Item, label string) (string, error)

Reveal reads the field with op read, by the vault's and the item's ids.

func (*OnePassword) SetText

func (o *OnePassword) SetText(ctx context.Context, item *Item, label, value string) error

SetText sets a text field with op's assignment, which carries no secret.

type RefusedError

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

RefusedError is a refusal: the command did not act on what it names, and the message says why and what to do instead.

func (*RefusedError) Error

func (e *RefusedError) Error() string

type Vault

type Vault interface {
	// Name is the vault's name, for the person's words.
	Name() string
	// Find reads the item titled title; nil when the vault holds none.
	Find(ctx context.Context, title string) (*Item, error)
	// Create creates the item titled title with fields, in one write.
	// notes is the item's note, which says where it came from.
	Create(ctx context.Context, title, notes string, fields []Field) error
	// SetText sets the text field label of item to value, adding it when
	// the item lacks it.
	SetText(ctx context.Context, item *Item, label, value string) error
	// Reveal reads the concealed field label of item.
	Reveal(ctx context.Context, item *Item, label string) (string, error)
}

Vault is the 1Password vault an App's item lives in, acting through the person's own signed-in session.

Jump to

Keyboard shortcuts

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