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
- Variables
- func ShownFromFile(declared []config.Credential) []*gitdv1.Connection
- type AppToCreate
- type FileApps
- type GitHub
- type Kind
- type LoginToFinish
- type Record
- type Store
- func (store *Store) Add(record Record, secret []byte) (Record, error)
- func (store *Store) AddApp(ctx context.Context, host string, appID int64, privateKey []byte, ...) (Record, error)
- func (store *Store) BeginApp(host, organization, name, redirectURL string) (AppToCreate, error)
- func (store *Store) CompleteApp(ctx context.Context, code, state string) (Record, string, error)
- func (store *Store) Credentials() []credentials.Credential
- func (store *Store) FinishLogin(ctx context.Context, loginID string) (Record, string, error)
- func (store *Store) Get(id string) (Record, []byte, error)
- func (store *Store) List() []Record
- func (store *Store) Remove(id string) error
- func (store *Store) Replace(record Record, secret []byte) error
- func (store *Store) StartLogin(ctx context.Context, host string) (LoginToFinish, error)
- func (store *Store) UseGitHub(github GitHub)
Constants ¶
const FilePrefix = "file-"
FilePrefix starts the IDs of the connections the configuration file declares.
Variables ¶
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.
var ErrNotFound = errors.New("no connection has that ID")
ErrNotFound is a connection no ID names.
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 ¶
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.
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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) List ¶
List is every connection kept, oldest first, their secrets as kept, never opened.
func (*Store) Replace ¶
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 ¶
StartLogin asks GitHub for a code a person enters to sign in through gitd's public App.