client

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2022 License: BSD-3-Clause Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// OperationGet is a PKSLookup operation value to perform a "get" operation.
	OperationGet = "get"
	// OperationIndex is a PKSLookup operation value to perform a "index" operation.
	OperationIndex = "index"
	// OperationVIndex is a PKSLookup operation value to perform a "vindex" operation.
	OperationVIndex = "vindex"
)
View Source
const OptionMachineReadable = "mr"

OptionMachineReadable is a PKSLookup options value to return machine readable output.

Variables

View Source
var ErrInvalidKeyText = errors.New("invalid key text")

ErrInvalidKeyText is returned when the key text is invalid.

View Source
var ErrInvalidOperation = errors.New("invalid operation")

ErrInvalidOperation is returned when the operation is invalid.

View Source
var ErrInvalidSearch = errors.New("invalid search")

ErrInvalidSearch is returned when the search value is invalid.

View Source
var ErrTLSRequired = errors.New("TLS required when auth token provided")

ErrTLSRequired is returned when an auth token is supplied with a non-TLS BaseURL.

Functions

This section is empty.

Types

type Client

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

Client describes the client details.

func NewClient

func NewClient(opts ...Option) (*Client, error)

NewClient returns a Client to interact with an HKP key server according to opts.

By default, the Sylabs Key Service is used. To override this behaviour, use OptBaseURL. If the key server requires authentication, consider using OptBearerToken.

If a bearer token is specified with a non-localhost base URL that does not utilize Transport Layer Security (TLS), an error wrapping ErrTLSRequired is returned.

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

Do sends an HTTP request and returns an HTTP response.

func (*Client) GetKey

func (c *Client) GetKey(ctx context.Context, search []byte) (keyText string, err error)

GetKey retrieves an ASCII armored keyring matching search from the Key Service. A 32-bit key ID, 64-bit key ID, 128-bit version 3 fingerprint, or 160-bit version 4 fingerprint can be specified in search. The context controls the lifetime of the request.

If an non-200 HTTP status code is received, an error wrapping an HTTPError is returned.

func (*Client) GetVersion

func (c *Client) GetVersion(ctx context.Context) (string, error)

GetVersion gets version information from the Key Service. The context controls the lifetime of the request.

If an non-200 HTTP status code is received, an error wrapping an HTTPError is returned.

func (*Client) NewRequest

func (c *Client) NewRequest(ctx context.Context, method string, ref *url.URL, body io.Reader) (*http.Request, error)

NewRequest returns a new Request given a method, ref, and optional body.

The context controls the entire lifetime of a request and its response: obtaining a connection, sending the request, and reading the response headers and body.

func (*Client) PKSAdd

func (c *Client) PKSAdd(ctx context.Context, keyText string) error

PKSAdd submits an ASCII armored keyring to the Key Service, as specified in section 4 of the OpenPGP HTTP Keyserver Protocol (HKP) specification. The context controls the lifetime of the request.

If an non-200 HTTP status code is received, an error wrapping an HTTPError is returned.

func (*Client) PKSAddWithResponse added in v0.8.0

func (c *Client) PKSAddWithResponse(ctx context.Context, keyText string) (string, error)

PKSAdd submits an ASCII armored keyring to the Key Service, as specified in section 4 of the OpenPGP HTTP Keyserver Protocol (HKP) specification and returns the server response upon successful submission. The context controls the lifetime of the request.

If an non-200 HTTP status code is received, an error wrapping an HTTPError is returned.

func (*Client) PKSLookup

func (c *Client) PKSLookup(ctx context.Context, pd *PageDetails, search, operation string, fingerprint, exact bool, options []string) (response string, err error)

PKSLookup requests data from the Key Service, as specified in section 3 of the OpenPGP HTTP Keyserver Protocol (HKP) specification. The context controls the lifetime of the request.

If an non-200 HTTP status code is received, an error wrapping an HTTPError is returned.

type HTTPError

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

HTTPError represents an error returned from an HTTP server.

func (*HTTPError) Code

func (e *HTTPError) Code() int

Code returns the HTTP status code associated with e.

func (*HTTPError) Error

func (e *HTTPError) Error() string

Error returns a human-readable representation of e.

func (*HTTPError) Is

func (e *HTTPError) Is(target error) bool

Is compares e against target. If target is a HTTPError with the same code as e, true is returned.

func (*HTTPError) Unwrap

func (e *HTTPError) Unwrap() error

Unwrap returns the error wrapped by e.

type Option

type Option func(co *clientOptions) error

Option are used to populate co.

func OptBaseURL

func OptBaseURL(url string) Option

OptBaseURL sets the base URL of the key server to url. The supported URL schemes are "http", "https", "hkp", and "hkps".

func OptBearerToken

func OptBearerToken(token string) Option

OptBearerToken sets the bearer token to include in the "Authorization" header of each request.

func OptHTTPClient

func OptHTTPClient(c *http.Client) Option

OptHTTPClient sets the client to use to make HTTP requests.

func OptUserAgent

func OptUserAgent(agent string) Option

OptUserAgent sets the HTTP user agent to include in the "User-Agent" header of each request.

type PageDetails

type PageDetails struct {
	// Maximum number of results per page (server may ignore or return fewer).
	Size int
	// Token for next page (advanced with each request, empty for last page).
	Token string
}

PageDetails includes pagination details.

Jump to

Keyboard shortcuts

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