Documentation
¶
Overview ¶
Package github is the mounts driver for GitHub repositories, read and written through GitHub's REST API. A mount's Source is "github://owner/repo".
A snapshot mount pins a commit. When the mount is made, the driver downloads the commit's tarball into a blob store and writes a manifest, so the mount serves the same bytes for its whole life, and after a restart, without asking GitHub again. A live mount reads a branch through the Contents API, and each Put or Delete is one commit on it.
The driver sends each request with the token source the registry hands it, which comes from the mount's connection. A private repo answers 404 to a request without a valid token, so the driver reports ErrNotFound for it, as GitHub intends.
Index ¶
- Constants
- type Driver
- func (d *Driver) CanRead(ctx context.Context, baseURL, source string, ts oauth2.TokenSource) (bool, error)
- func (d *Driver) Delete(ctx context.Context, m mounts.Mount, ts oauth2.TokenSource, ...) (*mounts.WriteResult, error)
- func (d *Driver) HostPath(m mounts.Mount, p string) (string, error)
- func (d *Driver) Kind() mounts.Kind
- func (d *Driver) Modes() []mounts.Mode
- func (d *Driver) Open(ctx context.Context, m mounts.Mount, ts oauth2.TokenSource) (fs.FS, error)
- func (d *Driver) Prepare(ctx context.Context, m mounts.Mount, ts oauth2.TokenSource) (mounts.Mount, error)
- func (d *Driver) Put(ctx context.Context, m mounts.Mount, ts oauth2.TokenSource, ...) (*mounts.WriteResult, error)
- func (d *Driver) Resolve(ctx context.Context, source, ref string, ts oauth2.TokenSource) (string, error)
- func (d *Driver) Stat(ctx context.Context, m mounts.Mount, ts oauth2.TokenSource, p string) (mounts.FileVersion, error)
- type Option
Constants ¶
const DefaultBaseURL = "https://api.github.com"
DefaultBaseURL is GitHub's API root. GitHub Enterprise and tests set another with WithBaseURL.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
Driver serves mounts.KindGitHub mounts. It implements mounts.Preparer, mounts.Writer and mounts.Localizer. Share one Driver per process, since it caches manifests and builds each snapshot's folder view once.
func New ¶
New returns a GitHub driver keeping snapshots in store. A nil store serves live mounts only, and Prepare refuses a snapshot with ErrInvalidArgument.
func (*Driver) CanRead ¶
func (d *Driver) CanRead(ctx context.Context, baseURL, source string, ts oauth2.TokenSource) (bool, error)
CanRead reports whether ts can read the repo at source. It fits connections.ReadCheck, so an app passes it to connections.WithReadCheck.
baseURL is the connection's API root, empty for github.com. A connection to another host than this driver serves gets false with no request, since its token means nothing here. A 404 is a definite no, and it is also how GitHub answers a private repo the token can't see. Any other failure, a rejected token included, is an error, since it says nothing about access.
func (*Driver) Delete ¶
func (d *Driver) Delete(ctx context.Context, m mounts.Mount, ts oauth2.TokenSource, req mounts.DeleteRequest) (*mounts.WriteResult, error)
Delete removes req.Path as one commit on the mount's branch. IfMatch must be the file's current version or AnyVersion; a stale one returns ErrConflict, and an empty one ErrInvalidArgument.
func (*Driver) HostPath ¶
HostPath returns where p of a snapshot mount is on disk, in the folder WithViews set. The first call for a mount builds its view there, as hard links to the blob store (copies where the filesystem refuses links), so a restart that lost the folder rebuilds it from the manifest without asking GitHub. A live mount, or a driver without WithViews or a linking blob store, returns ErrNotLocal.
func (*Driver) Open ¶
Open returns the mount's files: a snapshot's from its manifest and the blob store, or a live mount's from the Contents API at its branch. A live mount's fs.FS keeps ctx and ts for the requests it makes later.
func (*Driver) Prepare ¶
func (d *Driver) Prepare(ctx context.Context, m mounts.Mount, ts oauth2.TokenSource) (mounts.Mount, error)
Prepare finishes a new mount after Resolve. For a snapshot it downloads m.Version's tarball into the blob store and sets m.Manifest. For a live mount it sets m.Ref to the default branch when it is empty, so later writes name the branch. A live mount's Ref must be a branch, since GitHub commits a write onto a branch.
func (*Driver) Put ¶
func (d *Driver) Put(ctx context.Context, m mounts.Mount, ts oauth2.TokenSource, req mounts.PutRequest) (*mounts.WriteResult, error)
Put writes req.Data to req.Path as one commit on the mount's branch. An empty IfMatch sends no sha, so GitHub refuses to replace an existing file and Put returns ErrConflict. A stale IfMatch returns ErrConflict too. The result names the new commit and the file's new blob sha.
func (*Driver) Resolve ¶
func (d *Driver) Resolve(ctx context.Context, source, ref string, ts oauth2.TokenSource) (string, error)
Resolve checks the repo and returns the commit ref points at. An empty ref means the repo's default branch. A missing repo or ref returns ErrNotFound, and so does a private repo the token can't read.
func (*Driver) Stat ¶
func (d *Driver) Stat(ctx context.Context, m mounts.Mount, ts oauth2.TokenSource, p string) (mounts.FileVersion, error)
Stat returns the file's git blob sha, the version a Put or Delete passes as IfMatch. A folder returns ErrInvalidArgument, and a missing file ErrNotFound. A snapshot mount returns ErrReadOnly, since its files have no versions to write against.
type Option ¶
type Option func(*Driver)
Option configures a Driver.
func WithBaseURL ¶
WithBaseURL points the driver at another API root, such as a GitHub Enterprise host ("https://ghe.example.com/api/v3") or a test's fake.
func WithHTTPClient ¶
WithHTTPClient sets the client for every request. The default is http.DefaultClient.
func WithLimits ¶
WithLimits caps a snapshot's size and file count. A zero field keeps mounts.DefaultLimits' value. Past either, Prepare returns ErrTooLarge and stores no manifest.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package githubtest is a fake GitHub for tests of code that reads and writes repos: the mounts GitHub driver, the storage example app, and consumers' own tests.
|
Package githubtest is a fake GitHub for tests of code that reads and writes repos: the mounts GitHub driver, the storage example app, and consumers' own tests. |