Documentation
¶
Overview ¶
Package credential defines the main SDKCredential interface used throughout the codebase, as well as a means to detect how a credential has changed.
Index ¶
- type AcceptedKey
- type AcceptedKeySet
- type AcceptedSet
- type AcceptedSetBuilder
- func (b *AcceptedSetBuilder) Build() (AcceptedSet, error)
- func (b *AcceptedSetBuilder) WithAnchor(p SDKKeyParams) *AcceptedSetBuilder
- func (b *AcceptedSetBuilder) WithEnvironmentID(id config.EnvironmentID) *AcceptedSetBuilder
- func (b *AcceptedSetBuilder) WithMobileKey(p MobileKeyParams) *AcceptedSetBuilder
- func (b *AcceptedSetBuilder) WithPrimaryMobileKey(p MobileKeyParams) *AcceptedSetBuilder
- func (b *AcceptedSetBuilder) WithSDKKey(p SDKKeyParams) *AcceptedSetBuilder
- type AnchorChange
- type MalformedCredentialSetError
- func NewAnchorNotInSetError() *MalformedCredentialSetError
- func NewEmptyCredentialError(kind, key string) *MalformedCredentialSetError
- func NewInvalidCredentialCharactersError(kind, key string) *MalformedCredentialSetError
- func NewPrimaryMobileKeyMissingError() *MalformedCredentialSetError
- func NewPrimaryMobileKeyNotInSetError() *MalformedCredentialSetError
- type MobileKeyParams
- type ReconcileResult
- type Rotator
- func (r *Rotator) AcceptedKeys() AcceptedKeySet
- func (r *Rotator) AllCredentials() []SDKCredential
- func (r *Rotator) AnchorKey() config.SDKKey
- func (r *Rotator) CommitAnchor(key config.SDKKey)
- func (r *Rotator) DeprecatedCredentials() []SDKCredential
- func (r *Rotator) EnvironmentID() config.EnvironmentID
- func (r *Rotator) Initialize(sdkKey config.SDKKey, mobileKey config.MobileKey, envID config.EnvironmentID)
- func (r *Rotator) IsAccepted(cred SDKCredential) bool
- func (r *Rotator) MobileKey() config.MobileKey
- func (r *Rotator) Reconcile(set AcceptedSet, now time.Time) ReconcileResult
- func (r *Rotator) RevertAnchorChange(change AnchorChange)
- func (r *Rotator) StepTime(now time.Time) (additions []SDKCredential, expirations []SDKCredential)
- type SDKCredential
- type SDKKeyParams
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AcceptedKey ¶
type AcceptedKey struct {
// Expiry is the key's expiry. A nil expiry means the key is permanent.
Expiry *time.Time
// Key is the non-secret wire identifier, a human-readable name. Nil when the source carried none
// (manual configuration, or an old-format payload predating concurrent keys).
Key *string
}
AcceptedKey is the metadata for one accepted credential: its optional expiry and its optional wire identifier. The credential value itself is the map key wherever AcceptedKey is stored.
type AcceptedKeySet ¶
type AcceptedKeySet struct {
Server map[config.SDKKey]AcceptedKey
Mobile map[config.MobileKey]AcceptedKey
Anchor config.SDKKey
PrimaryMobile config.MobileKey
}
AcceptedKeySet is a point-in-time snapshot of an environment's full accepted set, returned by Rotator.AcceptedKeys. Server and Mobile are keyed by credential value; Anchor and PrimaryMobile name the designated keys within them. Reads are taken under one lock, so the fields agree.
type AcceptedSet ¶
type AcceptedSet struct {
// contains filtered or unexported fields
}
AcceptedSet is the full set of credentials an environment accepts after a reconcile: every server-side SDK key and mobile key with an optional expiry, the environment ID, and two designations.
- The anchor is the one SDK key that owns the environment's upstream connection.
- The primary mobile key is the default used where one mobile key is required, such as event forwarding.
Construct an AcceptedSet with AcceptedSetBuilder. Structural validation of the wire payload happens upstream, in BuildAcceptedSet.
type AcceptedSetBuilder ¶
type AcceptedSetBuilder struct {
// contains filtered or unexported fields
}
AcceptedSetBuilder accumulates the credentials for an AcceptedSet. Build validates the accumulated set (see Build) before returning it.
func NewAcceptedSetBuilder ¶
func NewAcceptedSetBuilder() *AcceptedSetBuilder
NewAcceptedSetBuilder returns an empty AcceptedSetBuilder.
func (*AcceptedSetBuilder) Build ¶
func (b *AcceptedSetBuilder) Build() (AcceptedSet, error)
Build validates and returns the accumulated AcceptedSet. It returns a *MalformedCredentialSetError if no SDK key was added, or if no anchor was designated.
func (*AcceptedSetBuilder) WithAnchor ¶
func (b *AcceptedSetBuilder) WithAnchor(p SDKKeyParams) *AcceptedSetBuilder
WithAnchor adds p.Value and designates it as the anchor. The anchor is always permanent, so p.Expiry is ignored. It is a no-op if the value is undefined. Unlike WithSDKKey, it overwrites an existing entry for the value.
func (*AcceptedSetBuilder) WithEnvironmentID ¶
func (b *AcceptedSetBuilder) WithEnvironmentID(id config.EnvironmentID) *AcceptedSetBuilder
WithEnvironmentID sets the environment ID. It is a no-op if the ID is undefined.
func (*AcceptedSetBuilder) WithMobileKey ¶
func (b *AcceptedSetBuilder) WithMobileKey(p MobileKeyParams) *AcceptedSetBuilder
WithMobileKey adds a mobile key. It resolves a repeated value the same way WithSDKKey does, and it is a no-op for the value that is already the designated primary.
func (*AcceptedSetBuilder) WithPrimaryMobileKey ¶
func (b *AcceptedSetBuilder) WithPrimaryMobileKey(p MobileKeyParams) *AcceptedSetBuilder
WithPrimaryMobileKey adds p.Value and designates it as the primary mobile key. The primary is always permanent, so p.Expiry is ignored. It is a no-op if the value is undefined.
func (*AcceptedSetBuilder) WithSDKKey ¶
func (b *AcceptedSetBuilder) WithSDKKey(p SDKKeyParams) *AcceptedSetBuilder
WithSDKKey adds a server-side SDK key. It is a no-op if the value is undefined, or if the value is already the designated anchor. When the value is already present, the first wire name recorded for it wins, and the entry keeps the earlier of the two expiries. A value a payload lists twice must not outlive the soonest expiry that payload gives it.
type AnchorChange ¶
type AnchorChange struct {
PreviousAnchor config.SDKKey
PreviousAnchorName *string
NewAnchor config.SDKKey
NewAnchorPreviouslyAccepted bool
}
AnchorChange describes an SDK anchor transition produced by Reconcile.
NewAnchorPreviouslyAccepted is false when the new anchor is a brand-new key, so the re-anchor must register that key's credential mappings. It is true when the key was already accepted, so the mappings already exist and a client may too. See envContextImpl.reanchor.
PreviousAnchorName is the previous anchor's wire "key" identifier, captured before this reconcile. A rollback that re-admits the previous anchor restores the name from here. See RevertAnchorChange. It is nil when the key had no name.
type MalformedCredentialSetError ¶
type MalformedCredentialSetError struct {
// contains filtered or unexported fields
}
MalformedCredentialSetError is returned when a credential payload cannot produce a valid AcceptedSet. Each constructor below documents one cause.
Validation runs before Reconcile, so the environment keeps its previous accepted set.
A caller reading a one-way push stream with no NAK channel, such as RAC, must also decide whether to reconnect: without one the service assumes the payload was applied and sends nothing new. It is worth reconnecting only when the whole event was unusable. When the event carried other environments that applied, the refused one would be identical on a new connection, and the reconnect would interrupt the environments that are working.
func NewAnchorNotInSetError ¶
func NewAnchorNotInSetError() *MalformedCredentialSetError
NewAnchorNotInSetError reports a payload whose designated anchor (sdkKey.value) is defined but absent from sdkKeys[]. Credential values are secrets, so no message here includes one.
func NewEmptyCredentialError ¶
func NewEmptyCredentialError(kind, key string) *MalformedCredentialSetError
NewEmptyCredentialError reports a key-array entry whose value field is empty. kind is "sdkKeys" or "mobileKeys"; key is the entry's wire identifier, which old-format payloads leave empty.
func NewInvalidCredentialCharactersError ¶
func NewInvalidCredentialCharactersError(kind, key string) *MalformedCredentialSetError
NewInvalidCredentialCharactersError reports a key-array entry whose value cannot be sent as an HTTP header value. Relay presents a credential in an Authorization header, so such a value can never authenticate anything upstream. kind is "sdkKeys" or "mobileKeys"; key is the entry's wire identifier. No message here includes a credential value.
func NewPrimaryMobileKeyMissingError ¶
func NewPrimaryMobileKeyMissingError() *MalformedCredentialSetError
NewPrimaryMobileKeyMissingError reports a payload with a non-empty mobileKeys[] and no designated primary. Accepting it would clear the primary without a repoint, leaving event forwarding on the previous key.
func NewPrimaryMobileKeyNotInSetError ¶
func NewPrimaryMobileKeyNotInSetError() *MalformedCredentialSetError
NewPrimaryMobileKeyNotInSetError reports a payload whose designated primary mobile key (mobKey) is defined but absent from mobileKeys[].
func (*MalformedCredentialSetError) Error ¶
func (e *MalformedCredentialSetError) Error() string
type MobileKeyParams ¶
MobileKeyParams describes one accepted mobile key for the builder. See SDKKeyParams.
type ReconcileResult ¶
type ReconcileResult struct {
AnchorChange *AnchorChange
MobilePrimaryRepoint *config.MobileKey
}
ReconcileResult signals state changes the caller must apply itself, rather than through the StepTime-driven addCredential and removeCredential flow.
AnchorChange is non-nil when the SDK anchor changed. The caller drives the re-anchor sequence; see envContextImpl.reanchor.
MobilePrimaryRepoint is non-nil when the primary mobile key changed to a key already accepted. Such a key is not in additions, so addCredential does not repoint the event dispatcher for it and the caller must do so.
type Rotator ¶
type Rotator struct {
// contains filtered or unexported fields
}
func NewRotator ¶
NewRotator constructs a rotator with the provided logger. A new rotator contains no credentials and can optionally be initialized via Initialize.
func (*Rotator) AcceptedKeys ¶
func (r *Rotator) AcceptedKeys() AcceptedKeySet
AcceptedKeys returns a snapshot of the full accepted set. See AcceptedKeySet.
func (*Rotator) AllCredentials ¶
func (r *Rotator) AllCredentials() []SDKCredential
AllCredentials returns every accepted credential: SDK keys, mobile keys, and the environment ID.
func (*Rotator) AnchorKey ¶
AnchorKey returns the anchor SDK key, which owns the upstream connection.
func (*Rotator) CommitAnchor ¶
CommitAnchor moves the rotator's SDK anchor pointer to key. The caller invokes it once the new anchor's client is ready. Until then the anchor stays on the previous key, so GetClient() returns the still-serving old client. Initialize and CommitAnchor are the only paths that move the pointer.
func (*Rotator) DeprecatedCredentials ¶
func (r *Rotator) DeprecatedCredentials() []SDKCredential
DeprecatedCredentials returns every accepted SDK key, other than the anchor, that carries an expiry. It does not return mobile keys, which expire the same way.
func (*Rotator) EnvironmentID ¶
func (r *Rotator) EnvironmentID() config.EnvironmentID
EnvironmentID returns the environment ID.
func (*Rotator) Initialize ¶
func (r *Rotator) Initialize(sdkKey config.SDKKey, mobileKey config.MobileKey, envID config.EnvironmentID)
Initialize sets an environment's initial credentials: the anchor SDK key, the primary mobile key and the environment ID. It runs for every environment as it is constructed, seeded from that environment's configuration.
Each credential is stored only if it is defined, and manual configuration is the reason: an environment configured by hand can legitimately have no mobile key and no environment ID, so those two checks are load-bearing rather than defensive. An environment that came from the auto-configuration stream or an offline archive always has all three, because every LaunchDarkly environment has at least one global key of each kind.
It takes one credential of each kind rather than a set: an environment starts from a single configured SDK key, and any further accepted keys arrive later, through Reconcile. Manually configured environments are never reconciled, so for them this is the whole credential set.
func (*Rotator) IsAccepted ¶
func (r *Rotator) IsAccepted(cred SDKCredential) bool
IsAccepted reports whether cred is currently one of the environment's accepted credentials: an accepted SDK key, an accepted mobile key (including one carrying a future expiry, which still authenticates until the cleanup ticker drops it), or the environment ID. Any other credential type is never accepted.
This answers the same question as membership in AllCredentials, by direct map lookup, so callers on request paths do not allocate a credential slice per call.
func (*Rotator) Reconcile ¶
func (r *Rotator) Reconcile(set AcceptedSet, now time.Time) ReconcileResult
Reconcile updates the rotator to match set. It queues additions and expirations, which the next StepTime call drains. Keys newly present are accepted; keys no longer present are revoked. An undefined environment ID leaves the current one unchanged. Per-key expiry is stored on the accepted entry, and StepTime acts on it.
set is assumed well-formed: AcceptedSetBuilder.Build already guaranteed a designated anchor.
Reconcile does NOT flip the anchor pointer. The returned AnchorChange signals the change; the caller drives the re-anchor and then calls CommitAnchor. A brand-new anchor is also stripped from additions, because reanchor registers that key's mappings itself.
func (*Rotator) RevertAnchorChange ¶
func (r *Rotator) RevertAnchorChange(change AnchorChange)
RevertAnchorChange undoes the accepted-set effects of a failed re-anchor. CommitAnchor was never called, so the anchor pointer still names the previous anchor. This method realigns the accepted set.
If this reconcile revoked the previous anchor outright, RevertAnchorChange re-admits that key as a permanent key with no expiry. The re-admission discards the key's previous expiry, because that key is still the anchor and still serving. It keeps the key's name, so /status still names the key that is serving. A previous anchor that is only grace-demoted stays accepted and keeps its expiry. The new anchor is dropped only if that key was brand new.
func (*Rotator) StepTime ¶
func (r *Rotator) StepTime(now time.Time) (additions []SDKCredential, expirations []SDKCredential)
StepTime provides the current time to the Rotator, so it can compute the additions and expirations for the tracked credentials since the last call. It enforces per-key expiry for SDK and mobile keys, strictly after a key's expiry timestamp.
type SDKCredential ¶
type SDKCredential interface {
// GetAuthorizationHeaderValue returns the value that should be passed in an HTTP Authorization header
// when using this credential, or "" if the header is not used.
GetAuthorizationHeaderValue() string
// Defined returns true if the credential is present.
Defined() bool
// String returns the string form of the credential.
String() string
// Masked returns a masked form of the credential suitable for log messages.
Masked() string
}
SDKCredential is implemented by types that represent an SDK authorization credential (SDKKey, etc.).