Documentation ¶
Overview ¶
Package client implements a Perkeep client.
Index ¶
- Variables
- func AddFlags()
- func ExplicitServer() string
- type ByCountAndBytes
- type Client
- func (c *Client) BlobRoot() (string, error)
- func (c *Client) Close() error
- func (c *Client) Describe(ctx context.Context, req *search.DescribeRequest) (*search.DescribeResponse, error)
- func (c *Client) DialFunc() func(network, addr string) (net.Conn, error)
- func (c *Client) DialTLSFunc() func(network, addr string) (net.Conn, error)
- func (c *Client) DiscoveryDoc(ctx context.Context) (io.Reader, error)
- func (c *Client) EnumerateBlobs(ctx context.Context, dest chan<- blob.SizedRef, after string, limit int) error
- func (c *Client) EnumerateBlobsOpts(ctx context.Context, ch chan<- blob.SizedRef, opts EnumerateOpts) error
- func (c *Client) Fetch(ctx context.Context, b blob.Ref) (io.ReadCloser, uint32, error)
- func (c *Client) FetchSchemaBlob(ctx context.Context, b blob.Ref) (*schema.Blob, error)
- func (c *Client) FileHasContents(ctx context.Context, f, wholeRef blob.Ref) bool
- func (c *Client) GetClaims(ctx context.Context, req *search.ClaimsRequest) (*search.ClaimsResponse, error)
- func (c *Client) GetJSON(ctx context.Context, url string, data interface{}) error
- func (c *Client) GetPermanodesWithAttr(ctx context.Context, req *search.WithAttrRequest) (*search.WithAttrResponse, error)
- func (c *Client) GetRecentPermanodes(ctx context.Context, req *search.RecentRequest) (*search.RecentResponse, error)
- func (c *Client) HTTPClient() *http.Client
- func (c *Client) HTTPStats() *httputil.StatsTransport
- func (c *Client) HTTPVersion(ctx context.Context) (string, error)
- func (c *Client) HasLegacySHA1() (bool, error)
- func (c *Client) HelpRoot() (string, error)
- func (c *Client) IsIgnoredFile(fullpath string) bool
- func (c *Client) NewPathClient(path string) (*Client, error)
- func (c *Client) Post(ctx context.Context, url string, bodyType string, body io.Reader) error
- func (c *Client) Query(ctx context.Context, req *search.SearchQuery) (*search.SearchResult, error)
- func (c *Client) QueryRaw(ctx context.Context, req *search.SearchQuery) ([]byte, error)
- func (c *Client) ReceiveBlob(ctx context.Context, br blob.Ref, source io.Reader) (blob.SizedRef, error)
- func (c *Client) RemoveBlob(ctx context.Context, b blob.Ref) error
- func (c *Client) RemoveBlobs(ctx context.Context, blobs []blob.Ref) error
- func (c *Client) SearchExistingFileSchema(ctx context.Context, wholeRef ...blob.Ref) (blob.Ref, error)
- func (c *Client) SearchRoot() (string, error)
- func (c *Client) SecretRingFile() string
- func (c *Client) ServerKeyID() (string, error)
- func (c *Client) ServerPublicKeyBlobRef() (blob.Ref, error)
- func (c *Client) SetHTTPClient(client *http.Client)
- func (c *Client) SetHaveCache(cache HaveCache)
- func (c *Client) SetupAuth() error
- func (c *Client) SetupAuthFromString(a string) error
- func (c *Client) ShareRoot() (string, error)
- func (c *Client) Sign(ctx context.Context, server string, r io.Reader) (signed []byte, err error)
- func (c *Client) SignHandler() (string, error)
- func (c *Client) Signer() (*schema.Signer, error)
- func (c *Client) SignerPublicKeyBlobref() blob.Ref
- func (c *Client) SimpleEnumerateBlobs(ctx context.Context, ch chan<- blob.SizedRef) error
- func (c *Client) StatBlobs(ctx context.Context, blobs []blob.Ref, fn func(blob.SizedRef) error) error
- func (c *Client) Stats() Stats
- func (c *Client) StorageGeneration() (string, error)
- func (c *Client) SyncHandlers() ([]*SyncInfo, error)
- func (c *Client) UpdateShareChain(b blob.Ref, r io.Reader) error
- func (c *Client) Upload(ctx context.Context, h *UploadHandle) (*PutResult, error)
- func (c *Client) UploadAndSignBlob(ctx context.Context, b schema.AnyBlob) (*PutResult, error)
- func (c *Client) UploadBlob(ctx context.Context, b schema.AnyBlob) (*PutResult, error)
- func (c *Client) UploadFile(ctx context.Context, filename string, contents io.Reader, ...) (blob.Ref, error)
- func (c *Client) UploadNewPermanode(ctx context.Context) (*PutResult, error)
- func (c *Client) UploadPlannedPermanode(ctx context.Context, key string, sigTime time.Time) (*PutResult, error)
- func (c *Client) UploadPublicKey(ctx context.Context) error
- type ClientOption
- func OptionAuthMode(m auth.AuthMode) ClientOption
- func OptionInsecure(v bool) ClientOption
- func OptionNoExternalConfig() ClientOption
- func OptionServer(server string) ClientOption
- func OptionTransportConfig(tc *TransportConfig) ClientOption
- func OptionTrustedCert(cert string) ClientOption
- func OptionUseStorageClient(s blobserver.Storage) ClientOption
- type EnumerateOpts
- type FileUploadOptions
- type HaveCache
- type PutResult
- type ResponseFormatError
- type Stats
- type SyncInfo
- type TransportConfig
- type UploadHandle
Constants ¶
This section is empty.
Variables ¶
var ErrNoHelpRoot = errors.New("client: server does not have a help handler")
ErrNoHelpRoot is returned by HelpRoot if the server doesn't have a help handler.
var ErrNoSearchRoot = errors.New("client: server doesn't support search")
ErrNoSearchRoot is returned by SearchRoot if the server doesn't support search.
ErrNoShareRoot is returned by ShareRoot if the server doesn't have a share handler.
var ErrNoSigning = fmt.Errorf("client: server doesn't support signing")
ErrNoSigning is returned by ServerKeyID if the server doesn't support signing.
var ErrNoStorageGeneration = errors.New("client: server doesn't report a storage generation")
ErrNoStorageGeneration is returned by StorageGeneration if the server doesn't report a storage generation value.
var ErrNoSync = errors.New("client: server has no sync handlers")
ErrNoSync is returned by SyncHandlers if the server does not advertise syncs.
var ErrNotSharing = errors.New("client can not deal with shared blobs. Create it with NewFromShareRoot")
ErrNotSharing is returned when a client that was not created with NewFromShareRoot tries to access shared blobs.
Functions ¶
func ExplicitServer ¶
func ExplicitServer() string
ExplicitServer returns the Perkeep server given in the "server" flag, if any.
Use AddFlags to register the flag before any flag.Parse call.
Types ¶
type ByCountAndBytes ¶
func (*ByCountAndBytes) String ¶
func (bb *ByCountAndBytes) String() string
type Client ¶
type Client struct { // Verbose controls how much logging from the client is printed. The caller // should set it only before using the client, and treat it as read-only after // that. Verbose bool // Logger is the logger used by the client. It defaults to a standard // logger to os.Stderr if the client is initialized by one of the package's // functions. Like Verbose, it should be set only before using the client, and // not be modified afterwards. Logger *log.Logger // contains filtered or unexported fields }
A Client provides access to a Perkeep server.
After use, a Client should be closed via its Close method to release idle HTTP connections or other resourcedds.
func New ¶
func New(opts ...ClientOption) (*Client, error)
New returns a new Perkeep Client.
By default, with no options, it uses the client as configured in the environment or default configuration files.
func NewFromShareRoot ¶
func NewFromShareRoot(ctx context.Context, shareBlobURL string, opts ...ClientOption) (c *Client, target blob.Ref, err error)
NewFromShareRoot uses shareBlobURL to set up and return a client that will be used to fetch shared blobs.
func NewOrFail ¶
func NewOrFail(opts ...ClientOption) *Client
NewOrFail is like New, but calls log.Fatal instead of returning an error.
func (*Client) BlobRoot ¶
BlobRoot returns the server's blobroot URL prefix. If the client was constructed with an explicit path, that path is used. Otherwise the server's default advertised blobRoot is used.
func (*Client) Describe ¶
func (c *Client) Describe(ctx context.Context, req *search.DescribeRequest) (*search.DescribeResponse, error)
func (*Client) DialTLSFunc ¶
DialTLSFunc returns the adequate dial function, when using SSL, depending on whether we're using insecure TLS (certificate verification is disabled), or we have some trusted certs, or we're on android. If the client's config has some trusted certs, the server's certificate will be checked against those in the config after the TLS handshake.
func (*Client) DiscoveryDoc ¶
DiscoveryDoc returns the server's JSON discovery document. This method exists purely for the "camtool discovery" command. Clients shouldn't have to parse this themselves.
func (*Client) EnumerateBlobs ¶
func (*Client) EnumerateBlobsOpts ¶
func (c *Client) EnumerateBlobsOpts(ctx context.Context, ch chan<- blob.SizedRef, opts EnumerateOpts) error
EnumerateBlobsOpts sends blobs to the provided channel, as directed by opts. The channel will be closed, regardless of whether an error is returned.
func (*Client) FetchSchemaBlob ¶
func (*Client) FileHasContents ¶
FileHasContents returns true iff f refers to a "file" or "bytes" schema blob, the server is configured with a "download helper", and the server responds that all chunks of 'f' are available and match the digest of wholeRef.
func (*Client) GetClaims ¶
func (c *Client) GetClaims(ctx context.Context, req *search.ClaimsRequest) (*search.ClaimsResponse, error)
func (*Client) GetJSON ¶
GetJSON sends a GET request to url, and unmarshals the returned JSON response into data. The URL's host must match the client's configured server.
func (*Client) GetPermanodesWithAttr ¶
func (c *Client) GetPermanodesWithAttr(ctx context.Context, req *search.WithAttrRequest) (*search.WithAttrResponse, error)
GetPermanodesWithAttr searches for permanodes that match the given search request. The Fuzzy option in the request must not be set, and the Attribute option must be set. Only indexed attributes may be queried.
func (*Client) GetRecentPermanodes ¶
func (c *Client) GetRecentPermanodes(ctx context.Context, req *search.RecentRequest) (*search.RecentResponse, error)
GetRecentPermanodes implements search.GetRecentPermanoder against a remote server over HTTP.
func (*Client) HTTPClient ¶
HTTPClient returns the Client's underlying http.Client.
func (*Client) HTTPStats ¶
func (c *Client) HTTPStats() *httputil.StatsTransport
HTTPStats returns the client's underlying httputil.StatsTransport, if in use. If another transport is being used, nil is returned.
func (*Client) HTTPVersion ¶
HTTPVersion reports the HTTP version in use, such as "HTTP/1.1" or "HTTP/2.0".
func (*Client) HasLegacySHA1 ¶
HasLegacySHA1 reports whether the server has SHA-1 blobs indexed.
func (*Client) HelpRoot ¶
HelpRoot returns the server's help handler. If the server isn't running a help handler, the error will be ErrNoHelpRoot.
func (*Client) IsIgnoredFile ¶
IsIgnoredFile returns whether the file at fullpath should be ignored by pk-put. The fullpath is checked against the ignoredFiles list, trying the following rules in this order: 1) star-suffix style matching (.e.g *.jpg). 2) Shell pattern match as done by http://golang.org/pkg/path/filepath/#Match 3) If the pattern is an absolute path to a directory, fullpath matches if it is that directory or a child of it. 4) If the pattern is a relative path, fullpath matches if it has pattern as a path component (i.e the pattern is a part of fullpath that fits exactly between two path separators).
func (*Client) NewPathClient ¶
NewPathClient returns a new client accessing a subpath of c.
func (*Client) Post ¶
Post is like http://golang.org/pkg/net/http/#Client.Post but with implementation details like gated requests. The URL's host must match the client's configured server.
func (*Client) Query ¶
func (c *Client) Query(ctx context.Context, req *search.SearchQuery) (*search.SearchResult, error)
func (*Client) QueryRaw ¶
QueryRaw sends req and returns the body of the response, which should be the unparsed JSON of a search.SearchResult.
func (*Client) ReceiveBlob ¶
func (*Client) RemoveBlob ¶
RemoveBlob removes the provided blob. An error is returned if the server failed to remove the blob. Removing a non-existent blob isn't an error.
func (*Client) RemoveBlobs ¶
RemoveBlobs removes the list of blobs. An error is returned if the server failed to remove a blob. Removing a non-existent blob isn't an error.
func (*Client) SearchExistingFileSchema ¶
func (c *Client) SearchExistingFileSchema(ctx context.Context, wholeRef ...blob.Ref) (blob.Ref, error)
SearchExistingFileSchema does a search query looking for an existing file with entire contents of wholeRef, then does a HEAD request to verify the file still exists on the server. If so, it returns that file schema's blobref.
If multiple wholeRef values are provided, any may match. This is used for searching for the file by multiple wholeRef hashes (e.g. SHA-224 and SHA-1).
It returns (zero, nil) if not found. A non-nil error is only returned if there were problems searching.
func (*Client) SearchRoot ¶
SearchRoot returns the server's search handler. If the server isn't running an index and search handler, the error will be ErrNoSearchRoot.
func (*Client) SecretRingFile ¶
SecretRingFile returns the filename to the user's GPG secret ring. The value comes from either the --secret-keyring flag, the CAMLI_SECRET_RING environment variable, the client config file's "identitySecretRing" value, or the operating system default location.
func (*Client) ServerKeyID ¶
ServerKeyID returns the server's GPG public key ID, in its long (16 capital hex digits) format. If the server isn't running a sign handler, the error will be ErrNoSigning.
func (*Client) ServerPublicKeyBlobRef ¶
ServerPublicKeyBlobRef returns the server's public key blobRef If the server isn't running a sign handler, the error will be ErrNoSigning.
func (*Client) SetHTTPClient ¶
SetHTTPClient sets the Perkeep client's HTTP client. If nil, the default HTTP client is used.
func (*Client) SetHaveCache ¶
func (*Client) SetupAuth ¶
SetupAuth sets the client's authMode. It tries from the environment first if we're on android or in dev mode, and then from the client configuration.
func (*Client) SetupAuthFromString ¶
SetupAuthFromString configures the clients authentication mode from an explicit auth string.
func (*Client) ShareRoot ¶
ShareRoot returns the server's share handler prefix URL. If the server isn't running a share handler, the error will be ErrNoShareRoot.
func (*Client) Sign ¶
Sign sends a request to the sign handler on server to sign the contents of r, and return them signed. It uses the same implementation details, such as gated requests, as Post.
func (*Client) SignHandler ¶
SignHandler returns the server's sign handler. If the server isn't running a sign handler, the error will be ErrNoSigning.
func (*Client) Signer ¶
Signer returns the client's Signer, if any. The Signer signs JSON mutation claims.
func (*Client) SignerPublicKeyBlobref ¶
SignerPublicKeyBlobref returns the blobref of signer's public key. The blobref may not be valid (zero blob.Ref) if e.g the configuration is invalid or incomplete.
func (*Client) SimpleEnumerateBlobs ¶
SimpleEnumerateBlobs sends all blobs to the provided channel. The channel will be closed, regardless of whether an error is returned.
func (*Client) StorageGeneration ¶
StorageGeneration returns the server's unique ID for its storage generation, reset whenever storage is reset, moved, or partially lost.
This is a value that can be used in client cache keys to add certainty that they're talking to the same instance as previously.
If the server doesn't return such a value, the error will be ErrNoStorageGeneration.
func (*Client) SyncHandlers ¶
SyncHandlers returns the server's sync handlers "from" and "to" prefix URLs. If the server isn't running any sync handler, the error will be ErrNoSync.
func (*Client) UpdateShareChain ¶
UpdateShareChain reads the schema of b from r, and instructs the client that all blob refs found in this schema should use b as a preceding chain link, in all subsequent shared blobs fetches. If the client was not created with NewFromShareRoot, ErrNotSharing is returned.
func (*Client) Upload ¶
Upload uploads a blob, as described by the provided UploadHandle parameters.
func (*Client) UploadAndSignBlob ¶
func (*Client) UploadBlob ¶
func (*Client) UploadFile ¶
func (c *Client) UploadFile(ctx context.Context, filename string, contents io.Reader, opts *FileUploadOptions) (blob.Ref, error)
UploadFile uploads the contents of the file, as well as a file blob with filename for these contents. If the contents or the file blob are found on the server, they're not uploaded.
Note: this method is still a work in progress, and might change to accommodate the needs of pk-put file.
func (*Client) UploadNewPermanode ¶
func (*Client) UploadPlannedPermanode ¶
func (*Client) UploadPublicKey ¶
UploadPublicKey uploads the public key (if one is defined), so subsequent (likely synchronous) indexing of uploaded signed blobs will have access to the public key to verify it. In the normal case, the stat cache prevents this from doing anything anyway.
type ClientOption ¶
type ClientOption interface {
// contains filtered or unexported methods
}
func OptionAuthMode ¶
func OptionAuthMode(m auth.AuthMode) ClientOption
OptionAuthMode returns a Client constructor option that sets the client's authentication mode.
func OptionInsecure ¶
func OptionInsecure(v bool) ClientOption
OptionInsecure returns a ClientOption that controls whether HTTP requests are allowed to be insecure (over HTTP or HTTPS without TLS certificate checking). Use of this is strongly discouraged except for local testing.
func OptionNoExternalConfig ¶
func OptionNoExternalConfig() ClientOption
OptionNoExternalConfig returns a Client constructor option that prevents any on-disk config files or environment variables from influencing the client. It may still use the disk for caches.
func OptionServer ¶
func OptionServer(server string) ClientOption
OptionServer returns a Client constructor option that forces use of the provided server.
The provided server is either "host:port" (assumed http, not https) or a URL prefix, with or without a path, or a server alias from the client configuration file. A server alias should not be confused with a hostname, therefore it cannot contain any colon or period.
func OptionTransportConfig ¶
func OptionTransportConfig(tc *TransportConfig) ClientOption
OptionTransportConfig returns a ClientOption that makes the client use the provided transport configuration options.
func OptionTrustedCert ¶
func OptionTrustedCert(cert string) ClientOption
OptionTrustedCert returns a ClientOption that makes the client trust the provide self-signed cert signature. The value should be the 20 byte hex prefix of the SHA-256 of the cert, as printed by the perkeepd server on start-up.
If cert is empty, the option has no effect.
func OptionUseStorageClient ¶
func OptionUseStorageClient(s blobserver.Storage) ClientOption
OptionUseStorageClient returns a Client constructor option that forces use of the provided blob storage target.
This exists mainly so all the convenience methods on Client (e.g. the Upload variants) are available against storage directly.
Use of OptionUseStorageClient is mutually exclusively with all other options, although it does imply OptionNoExternalConfig(true).
type EnumerateOpts ¶
type EnumerateOpts struct { After string // last blobref seen; start with ones greater than this MaxWait time.Duration // how long to poll for (second granularity), waiting for any blob, or 0 for no limit Limit int // if non-zero, the max blobs to return }
EnumerateOpts are the options to Client.EnumerateBlobsOpts.
type FileUploadOptions ¶
type FileUploadOptions struct { // FileInfo optionally specifies the FileInfo to populate the schema of the file blob. FileInfo os.FileInfo // WholeRef optionally specifies the digest of the uploaded file contents, which // allows UploadFile to skip computing the digest (needed to check if the contents // are already on the server). WholeRef blob.Ref }
FileUploadOptions is optionally provided to UploadFile.
type HaveCache ¶
type HaveCache interface { StatBlobCache(br blob.Ref) (size uint32, ok bool) NoteBlobExists(br blob.Ref, size uint32) }
A HaveCache caches whether a remote blobserver has a blob.
type PutResult ¶
type PutResult struct { BlobRef blob.Ref Size uint32 Skipped bool // already present on blobserver }
func (*PutResult) SizedBlobRef ¶
type ResponseFormatError ¶
type ResponseFormatError error
type Stats ¶
type Stats struct { // The number of uploads that were requested, but perhaps // not actually performed if the server already had the items. UploadRequests ByCountAndBytes // The uploads which were actually sent to the blobserver // due to the server not having the blobs Uploads ByCountAndBytes }
type SyncInfo ¶
type SyncInfo struct { From string To string ToIndex bool // whether this sync is from a blob storage to an index }
SyncInfo holds the data that were acquired with a discovery and that are relevant to a syncHandler.
type TransportConfig ¶
type TransportConfig struct { // Proxy optionally specifies the Proxy for the transport. Useful with // pk-put for debugging even localhost requests. Proxy func(*http.Request) (*url.URL, error) Verbose bool // Verbose enables verbose logging of HTTP requests. }
TransportConfig contains options for how HTTP requests are made.
type UploadHandle ¶
type UploadHandle struct { // BlobRef is the required blobref of the blob to upload. BlobRef blob.Ref // Contents is the blob data. Contents io.Reader // Size optionally specifies the size of Contents. // If <= 0, the Contents are slurped into memory to count the size. Size uint32 // Vivify optionally instructs the server to create a // permanode for this blob. If used, the blob should be a // "file" schema blob. This is typically used by // lesser-trusted clients (such a mobile phones) which don't // have rights to do signing directly. Vivify bool // SkipStat indicates whether the stat check (checking whether // the server already has the blob) will be skipped and the // blob should be uploaded immediately. This is useful for // small blobs that the server is unlikely to already have // (e.g. new claims). SkipStat bool }
UploadHandle contains the parameters is a request to upload a blob.
func NewUploadHandleFromString ¶
func NewUploadHandleFromString(data string) *UploadHandle
NewUploadHandleFromString returns an upload handle