{"modulePath":"github.com/giantswarm/devctl/v8","version":"v8.176.1","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package githubapp\n\nPackage githubapp creates the GitHub Apps that giantswarm/github declares, through GitHub's manifest flow, and keeps their installations as declared.\n\nIt 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.\n\n## Constants\n\n```go\nconst (\n\t// DeclarationsOwner is the organisation whose repository declares its\n\t// Apps, and which owns every App declared there.\n\tDeclarationsOwner = \"giantswarm\"\n\t// DeclarationsRepo is the repository of DeclarationsOwner that declares\n\t// the Apps, one directory apps/\u003cname\u003e each.\n\tDeclarationsRepo = \"github\"\n\n\t// ManifestFile is an App's manifest in its directory: the document\n\t// GitHub's manifest flow takes.\n\tManifestFile = \"manifest.json\"\n\t// InstallationFile is an App's installation in its directory:\n\t// {\"repositories\": \"all\" | [\"\u003cname\u003e\", …]}.\n\tInstallationFile = \"installation.json\"\n)\n```\n\n```go\nconst (\n\tFieldAppID          = \"app-id\"\n\tFieldClientID       = \"client-id\"\n\tFieldSlug           = \"slug\"\n\tFieldClientSecret   = \"client-secret\"\n\tFieldPrivateKey     = \"private-key\"\n\tFieldWebhookSecret  = \"webhook-secret\"\n\tFieldInstallationID = \"installation-id\"\n)\n```\nThe fields of an App's 1Password item: the configuration as text, the credentials concealed.\n\n## Functions\n\n```go\nfunc IsRefused(err error) bool\n```\nIsRefused reports whether err is a refusal.\n\n```go\nfunc ParseInstallation(raw []byte) ([]string, error)\n```\nParseInstallation reads an installation file: the repositories by name, sorted and each once, nil for \"all\".\n\n```go\nfunc Slug(name string) string\n```\nSlug 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.\n\n## Types\n\n```go\ntype Created struct {\n\tSlug     string\n\tAppID    int64\n\tClientID string\n\tURL      string\n\t// Item is the 1Password item, \u003cvault\u003e/\u003ctitle\u003e, and Fields the labels\n\t// written into it.\n\tItem   string\n\tFields []string\n\t// Installation is the App's installation, nil until it exists.\n\tInstallation *Installed\n}\n```\nCreated is what Create made: the App, its item and its installation.\n\n```go\nfunc (c *Created) Text() string\n```\nText is the result for the person's terminal: ids and labels, no value.\n\n```go\ntype Credentials struct {\n\tID            int64   `json:\"id\"`\n\tSlug          string  `json:\"slug\"`\n\tName          string  `json:\"name\"`\n\tClientID      string  `json:\"client_id\"`\n\tClientSecret  string  `json:\"client_secret\"`\n\tWebhookSecret *string `json:\"webhook_secret\"`\n\tPEM           string  `json:\"pem\"`\n\tHTMLURL       string  `json:\"html_url\"`\n}\n```\nCredentials are what GitHub's manifest conversion answers: the App and its credentials, which stay in this process until the vault holds them.\n\n```go\ntype Declaration struct {\n\t// Name is the App's name, its directory under apps/.\n\tName string\n\t// Org is the organisation that owns the App and its installation.\n\tOrg string\n\t// Manifest is the manifest document as declared, a JSON object.\n\tManifest map[string]any\n\t// Repositories are the installation's repositories by name, sorted;\n\t// nil is all of the organisation's.\n\tRepositories []string\n\t// Source is where the manifest was read:\n\t// giantswarm/github@\u003ccommit\u003e:apps/\u003cname\u003e/manifest.json.\n\tSource string\n}\n```\nDeclaration is an App as giantswarm/github declares it on its default branch: the manifest and the installation.\n\n```go\nfunc ReadDeclaration(ctx context.Context, gh *github.Client, name string) (Declaration, error)\n```\nReadDeclaration 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.\n\n```go\nfunc (d Declaration) All() bool\n```\nAll reports whether the installation is declared on all repositories.\n\n```go\nfunc (d Declaration) Selection() string\n```\nSelection is the declared installation in words.\n\n```go\ntype Env struct {\n\t// GitHub is the client with the person's token: the declaration, the\n\t// ids the installation page preselects, and the changes of an\n\t// installation's repositories.\n\tGitHub *github.Client\n\t// HTTP sends the conversion and the requests made as the App; nil is\n\t// http.DefaultClient.\n\tHTTP *http.Client\n\t// API and Web are GitHub's API and web site, with a trailing slash;\n\t// empty is https://api.github.com/ and https://github.com/.\n\tAPI, Web string\n\tVault    Vault\n\t// Open opens a URL in the person's browser.\n\tOpen func(url string) error\n\t// Progress is told each step, for the person.\n\tProgress io.Writer\n\t// Timeout bounds the wait for each of the person's clicks.\n\tTimeout time.Duration\n\t// Poll is how often an installation is read while waiting; 0 is 3s.\n\tPoll time.Duration\n}\n```\nEnv is what the commands act with: the person's GitHub token, browser and 1Password vault.\n\n```go\nfunc (e *Env) Create(ctx context.Context, name string) (*Created, error)\n```\nCreate 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.\n\nRefused 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.\n\n```go\nfunc (e *Env) Install(ctx context.Context, name string) (*Installed, error)\n```\nInstall 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.\n\n```go\ntype Field struct {\n\tLabel string\n\tValue string\n\t// Secret makes the field concealed; any other is a text field.\n\tSecret bool\n}\n```\nField is one field of a vault item.\n\n```go\ntype Installed struct {\n\tApp   string\n\tAppID int64\n\tID    int64\n\tOrg   string\n\t// Selection is GitHub's repository selection: all or selected.\n\tSelection string\n\t// Repositories are the selected ones' names.\n\tRepositories []string\n\tAdded        []string\n\tRemoved      []string\n\t// Recorded is set when the item's installation-id was written.\n\tRecorded string\n}\n```\nInstalled is an App's installation as Install, or Create, left it.\n\n```go\nfunc (i *Installed) Text() string\n```\nText is the installation for the person's terminal.\n\n```go\ntype Item struct {\n\tID string\n\t// VaultID is the id of the vault that holds the item.\n\tVaultID string\n\tTitle   string\n\t// Text are the item's text fields by label. A concealed field is not\n\t// among them: Reveal reads one.\n\tText map[string]string\n}\n```\nItem is a vault item as Find reads it: its id and its text fields.\n\n```go\ntype OnePassword struct {\n\t// Vault is the vault's name or id.\n\tVault string\n\t// Bin is the op executable; empty is op on $PATH.\n\tBin string\n}\n```\nOnePassword 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.\n\n```go\nfunc (o *OnePassword) Create(ctx context.Context, title, notes string, fields []Field) error\n```\nCreate 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.\n\n```go\nfunc (o *OnePassword) Find(ctx context.Context, title string) (*Item, error)\n```\nFind lists the vault's items, metadata only, and reads the one titled title: nil when there is none, an error when there are several.\n\n```go\nfunc (o *OnePassword) Name() string\n```\nName is the vault's name.\n\n```go\nfunc (o *OnePassword) Reveal(ctx context.Context, item *Item, label string) (string, error)\n```\nReveal reads the field with op read, by the vault's and the item's ids.\n\n```go\nfunc (o *OnePassword) SetText(ctx context.Context, item *Item, label, value string) error\n```\nSetText sets a text field with op's assignment, which carries no secret.\n\n```go\ntype RefusedError struct {\n\t// contains filtered or unexported fields\n}\n```\nRefusedError is a refusal: the command did not act on what it names, and the message says why and what to do instead.\n\n```go\nfunc (e *RefusedError) Error() string\n```\n\n```go\ntype Vault interface {\n\t// Name is the vault's name, for the person's words.\n\tName() string\n\t// Find reads the item titled title; nil when the vault holds none.\n\tFind(ctx context.Context, title string) (*Item, error)\n\t// Create creates the item titled title with fields, in one write.\n\t// notes is the item's note, which says where it came from.\n\tCreate(ctx context.Context, title, notes string, fields []Field) error\n\t// SetText sets the text field label of item to value, adding it when\n\t// the item lacks it.\n\tSetText(ctx context.Context, item *Item, label, value string) error\n\t// Reveal reads the concealed field label of item.\n\tReveal(ctx context.Context, item *Item, label string) (string, error)\n}\n```\nVault is the 1Password vault an App's item lives in, acting through the person's own signed-in session.\n\n","path":"github.com/giantswarm/devctl/v8/pkg/githubapp","name":"githubapp","synopsis":"Package githubapp creates the GitHub Apps that giantswarm/github declares, through GitHub's manifest flow, and keeps their installations as declared.","isRedistributable":true}
