connections

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 25 Imported by: 0 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 connections keeps the credentials a platform gives gitd through the API: one file per connection under the state directory, readable by gitd's user only, its secret sealed when gitd has a secrets key. What is kept is applied at once: the credentials gitd reads and publishes with are asked for each time.

Index

Constants

View Source
const FilePrefix = "file-"

FilePrefix starts the IDs of the connections the configuration file declares.

Variables

View Source
var (
	ErrInvalid  = errors.New("invalid connection")
	ErrFromFile = errors.New("this connection is the configuration file's: change it there")
)

Errors a connection is refused with.

View Source
var ErrNotFound = errors.New("no connection has that ID")

ErrNotFound is a connection no ID names.

View Source
var ErrUnavailable = errors.New("not available")

ErrUnavailable is a way of connecting this gitd does not offer, saying why.

Functions

func ShownFromFile

func ShownFromFile(declared []config.Credential) []*gitdv1.Connection

ShownFromFile are the connections the configuration file declares, as the API shows them: named `file-1`, `file-2`… in the file's order, never their secrets.

Types

type AppToCreate

type AppToCreate struct {
	FormAction string
	Manifest   string
	State      string
}

AppToCreate is what a browser posts to GitHub to create an App: where, the manifest, and the state that ties GitHub's answer to it.

type FileApps

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

FileApps are the GitHub Apps the configuration file declares, as credentials: each App's key read from its file each time it signs, so replacing the file rotates the key. A key that cannot be read now stops the start.

func NewFileApps

func NewFileApps(declared []config.Credential, github GitHub) (*FileApps, error)

NewFileApps reads the Apps among declared, reaching GitHub as github says.

func (*FileApps) Credentials

func (apps *FileApps) Credentials() []credentials.Credential

Credentials are the Apps' credentials, which make a token for each operation.

type GitHub

type GitHub struct {
	UserAgent     string
	Hosts         repo.Hosts
	APIBase       string
	WebBase       string
	LoginClientID string
	LoginAppSlug  string
}

GitHub is how gitd reaches GitHub: as which User-Agent, and on which port of each host that is not reached on the usual one. APIBase and WebBase, when set, are where its API and its pages are reached instead of their usual addresses, for every host: a proxy, or a test. LoginClientID and LoginAppSlug are gitd's public App, which people sign in through; without a client ID, signing in is not offered.

func (GitHub) API

func (github GitHub) API(host string) *githubapp.API

API is GitHub's API for a host.

type Kind

type Kind string

Kind is what a connection is.

const (
	// Token is a token for the repositories under a prefix, on any host.
	Token Kind = "token"
	// GitHubApp is a GitHub App: its private key makes installation tokens.
	GitHubApp Kind = "github_app"
	// GitHubLogin is a person signed in through gitd's public App: a renewal token.
	GitHubLogin Kind = "github_login"
)

type LoginToFinish

type LoginToFinish struct {
	UserCode        string
	VerificationURL string
	LoginID         string
	ExpiresIn       time.Duration
}

LoginToFinish is what a person enters, where, and the name to finish the sign-in by.

type Record

type Record struct {
	ID        string    `json:"id"`
	Kind      Kind      `json:"kind"`
	URLPrefix string    `json:"url_prefix"`
	Host      string    `json:"host,omitempty"`
	User      string    `json:"user,omitempty"`
	ActsAs    string    `json:"acts_as,omitempty"`
	AppID     int64     `json:"app_id,omitempty"`
	ManageURL string    `json:"manage_url,omitempty"`
	Expires   time.Time `json:"expires,omitzero"`
	Created   time.Time `json:"created"`
	Lasting   bool      `json:"lasting,omitempty"`
	Secret    string    `json:"secret"`
}

Record is one connection as it is kept. Secret is the token, the private key or the renewal token, as the Box keeps it; the rest is never secret. Lasting says a sign-in's token does not expire, as with an App that does not expire its users' tokens: Secret is then that token, not a renewal token.

func NewToken

func NewToken(prefix, token, user string) (Record, error)

NewToken is a token for the repositories under prefix, checked: a prefix that names its host, so the token never goes to another, and a token and user of one line each.

func (Record) Shown

func (record Record) Shown() *gitdv1.Connection

Shown is a connection as the API shows it: everything but its secret.

type Store

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

Store is the connections kept in a directory, and their secrets opened, in memory.

func Open

func Open(directory string, box *secrets.Box) (*Store, error)

Open reads the connections kept in directory, making it if it is not there. A secret that cannot be opened — sealed with another key, or with none given — stops the start, rather than leaving its repositories to fail one by one.

func (*Store) Add

func (store *Store) Add(record Record, secret []byte) (Record, error)

Add keeps a new connection with its secret, giving it an ID and the time now, and returns it as kept.

func (*Store) AddApp

func (store *Store) AddApp(ctx context.Context, host string, appID int64, privateKey []byte, prefix string) (Record, error)

AddApp keeps a GitHub App a platform already has, once GitHub has said the key is that App's: what the App acts as and where it is managed come from GitHub, not from the caller. prefix is what it opens; empty is every repository on the host.

func (*Store) BeginApp

func (store *Store) BeginApp(host, organization, name, redirectURL string) (AppToCreate, error)

BeginApp starts creating the organisation's own App named name — or the person's, when organization is empty — which GitHub sends back to redirectURL with a code and the state.

func (*Store) CompleteApp

func (store *Store) CompleteApp(ctx context.Context, code, state string) (Record, string, error)

CompleteApp finishes creating an App: the state must be one BeginApp gave and not yet used, and the code GitHub sent back is exchanged for the App's ID and private key, which are kept. It answers the connection and where the App is installed.

func (*Store) Credentials

func (store *Store) Credentials() []credentials.Credential

Credentials are what the connections kept open repositories with, as gitd asks for them at every operation: so a connection added or removed applies at once. A GitHub App makes a token for each repository and purpose.

func (*Store) FinishLogin

func (store *Store) FinishLogin(ctx context.Context, loginID string) (Record, string, error)

FinishLogin waits until the person has entered the code, then keeps their sign-in: the renewal token, sealed, and the token it renews, in memory only. It answers the connection and where gitd's App is installed on repositories, if it is not yet.

func (*Store) Get

func (store *Store) Get(id string) (Record, []byte, error)

Get is one connection and its secret, opened.

func (*Store) List

func (store *Store) List() []Record

List is every connection kept, oldest first, their secrets as kept, never opened.

func (*Store) Remove

func (store *Store) Remove(id string) error

Remove forgets a connection and deletes its file.

func (*Store) Replace

func (store *Store) Replace(record Record, secret []byte) error

Replace keeps a connection again with a new secret or new details, under its ID: a sign-in's renewal token is replaced each time it is used.

func (*Store) StartLogin

func (store *Store) StartLogin(ctx context.Context, host string) (LoginToFinish, error)

StartLogin asks GitHub for a code a person enters to sign in through gitd's public App.

func (*Store) UseGitHub

func (store *Store) UseGitHub(github GitHub)

UseGitHub says how the GitHub Apps of the connections reach GitHub's API.

Jump to

Keyboard shortcuts

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