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 ¶
const ( // RotationManual means a person replaces the credential, for example // before it expires. RotationManual = "manual" // RotationAutomatic means the host replaces the credential on a // schedule, which usually needs more permission at the service. RotationAutomatic = "automatic" )
Rotation mode keys a host may act on. A provider may describe others; a host that does not know a mode does not offer it.
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"`
// Setup is what a person does, in order, to create the credential at
// the service before entering it.
Setup []SetupStep `json:"setup,omitempty"`
// Rotation lists the ways the credential can be replaced over its life,
// with what each needs. Empty means the method does not describe
// rotation; a person replaces the credential by reconnecting.
Rotation []RotationMode `json:"rotation,omitempty"`
}
AuthMethod is one way to connect to a provider.
func (AuthMethod) RotationMode ¶ added in v0.4.0
func (a AuthMethod) RotationMode(key string) (RotationMode, bool)
RotationMode returns the method's rotation mode with key.
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 connectforge 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
// ExpiresAt is when the credential stops working, if the provider
// reports it; nil when it does not expire or the provider does not say.
ExpiresAt *time.Time
}
Result is what validation discovered.
type RotationMode ¶ added in v0.4.0
type RotationMode struct {
Key string `json:"key"`
Label string `json:"label"`
Description string `json:"description,omitempty"`
// Scopes are the permissions the credential needs in this mode in
// addition to the method's.
Scopes []Scope `json:"scopes,omitempty"`
// Risks say what those extra permissions also allow, so a person can
// weigh the mode before choosing it.
Risks []string `json:"risks,omitempty"`
// ExpiryDays is the lifetime to give the credential when creating it,
// for services that support one; 0 means no expiry.
ExpiryDays int `json:"expiryDays,omitempty"`
// Recommended marks the mode to offer first. At most one mode is.
Recommended bool `json:"recommended,omitempty"`
}
RotationMode is one way a credential is replaced over its life.
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 SetupStep ¶ added in v0.4.0
type SetupStep struct {
Title string `json:"title"`
// Detail explains the step in plain text.
Detail string `json:"detail,omitempty"`
// URL opens the page at the service where the step is done.
URL string `json:"url,omitempty"`
// Rotation limits the step to these rotation mode keys; empty means
// every mode.
Rotation []string `json:"rotation,omitempty"`
}
SetupStep is one step of creating a credential at the service.
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 connectforge'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. |