Documentation
¶
Overview ¶
Package provider defines what a provider adapter implements: a declarative Manifest, validation with account discovery, and authentication of outgoing requests. It also holds the Registry a host fills at startup.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrBadMaterial = errors.New("provider: not credential material")
ErrBadMaterial is returned for plaintext that is not encoded material.
var ErrUnknownProvider = errors.New("provider: unknown provider")
ErrUnknownProvider is returned for a provider key that is not registered.
Functions ¶
func Classify ¶
Classify returns nil for a 2xx response and a *StatusError otherwise: 401 is an invalid credential, 403 an insufficient scope, 429 rate limiting, 5xx transient, and any other status an invalid credential.
func EncodeMaterial ¶
EncodeMaterial returns the plaintext to seal. The caller seals it and clears it.
Types ¶
type AuthMethod ¶
type AuthMethod struct {
// Key identifies the method, for example "api_token".
Key string `json:"key"`
Fields []Field `json:"fields"`
Scopes []Scope `json:"scopes,omitempty"`
// AccountSelection says how the account is chosen: "discovered" from the
// credential, or "chosen" by the person from a list.
AccountSelection string `json:"accountSelection,omitempty"`
HelpURL string `json:"helpUrl,omitempty"`
}
AuthMethod is one way to connect to a provider.
type Field ¶
type Field struct {
Name string `json:"name"`
Label string `json:"label"`
Secret bool `json:"secret"`
Required bool `json:"required"`
Help string `json:"help,omitempty"`
}
Field is an input a method needs.
type Manifest ¶
type Manifest struct {
// Key identifies the provider, for example "cloudflare".
Key string `json:"key"`
DisplayName string `json:"displayName"`
// BaseURLs are the only origins a request for this provider may reach.
BaseURLs []string `json:"baseUrls"`
AuthMethods []AuthMethod `json:"authMethods"`
HelpURL string `json:"helpUrl,omitempty"`
}
Manifest describes a provider so a user interface can render a connection form and an agent can read what a connection needs. It contains no code.
type Material ¶
type Material struct {
// Kind names the structure, for example "api_token".
Kind string
// Fields holds the credential's values by field name.
Fields map[string]cf.Secret
// ExpiresAt is when an access token expires, if it does.
ExpiresAt *time.Time
}
Material is a credential's plaintext, as a provider adapter sees it. It exists only between unsealing and use; every value is a cf.Secret.
func DecodeMaterial ¶
DecodeMaterial parses unsealed plaintext and clears it.
type Provider ¶
type Provider interface {
// Manifest describes the provider. It is data and never changes.
Manifest() Manifest
// Validate checks the credential with the provider, using hc, which the
// caller has restricted to the manifest's hosts, and returns the account
// it belongs to. A rejection wraps a connectionforge provider error.
Validate(ctx context.Context, hc *http.Client, m Material) (Result, error)
// Authenticate adds the credential to an outgoing request. The request
// is the caller's copy.
Authenticate(r *http.Request, m Material) error
}
Provider is an adapter for one external service.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds the providers a host supports. It is safe for concurrent use.
type Result ¶
type Result struct {
AccountID string
AccountLabel string
// Scopes are the permissions the provider reports for the credential,
// if it reports them.
Scopes []string
}
Result is what validation discovered.
type Scope ¶
type Scope struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Required bool `json:"required,omitempty"`
}
Scope is a permission a method asks for or expects.
type StatusError ¶
StatusError is a provider's refusal, classified. It carries the status and the provider's request ID, never a body.
func (*StatusError) Error ¶
func (e *StatusError) Error() string
func (*StatusError) Unwrap ¶
func (e *StatusError) Unwrap() error
Unwrap returns the class, so errors.Is works with connectionforge's errors.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package apikey is a provider for services that issue a static API key or token, driven by configuration: where the token goes in a request, which endpoint verifies it, and where the account is in the response.
|
Package apikey is a provider for services that issue a static API key or token, driven by configuration: where the token goes in a request, which endpoint verifies it, and where the account is in the response. |