envfactory

package
v8.23.1 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package envfactory contains types related to service-driven environment configuration, shared by the autoconfig and filedata packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildAcceptedSet added in v8.21.0

func BuildAcceptedSet(params EnvironmentParams) (credential.AcceptedSet, []string, error)

BuildAcceptedSet converts EnvironmentParams into the AcceptedSet that EnvContext.ReconcileCredentials needs. It is the single home for the anchor invariant, for both RAC and the offline archive.

Credential identity is the value (the secret), not the wire identifier, so a rename produces an unchanged AcceptedSet.

Expiry comes from the arrays. The legacy sdkKey.expiring wire slot is never consulted.

On a structurally malformed payload it returns a *credential.MalformedCredentialSetError and an empty set. The caller must keep the previous accepted state, and RAC handlers must also reconnect the stream with jitter.

It filters out keys scoped to a view and names them in the second return value, so callers can log what they dropped. An SDK presenting one gets a 401, because the key is absent from the lookup map.

func ToTime added in v8.8.0

func ToTime(millisecondTime ldtime.UnixMillisecondTime) time.Time

Types

type AcceptedMobileKey added in v8.21.0

type AcceptedMobileKey struct {
	Key      string
	Value    config.MobileKey
	Expiry   time.Time
	HasViews bool
}

AcceptedMobileKey is one entry in the accepted mobile key set for an environment. Expiry is zero if the key is permanent. HasViews is true if the mobile key is associated with a view.

type AcceptedSDKKey added in v8.21.0

type AcceptedSDKKey struct {
	Key      string
	Value    config.SDKKey
	Expiry   time.Time
	HasViews bool
}

AcceptedSDKKey is one entry in the accepted SDK key set for an environment. Expiry is zero if the key is permanent. HasViews is true if the SDK key is associated with a view.

type ConcurrentKeyRep added in v8.21.0

type ConcurrentKeyRep struct {
	Key      string `json:"key"`
	Value    string `json:"value"`
	Expiry   *int64 `json:"expiry,omitempty"` // Unix-ms; nil = permanent
	HasViews bool   `json:"hasViews"`
}

ConcurrentKeyRep is an entry in the sdkKeys or mobileKeys array on EnvironmentRep. It represents one accepted credential in an environment's concurrent key set. See EnvironmentRep for the wire vocabulary.

type EnvConfigFactory

type EnvConfigFactory struct {
	// DataStorePrefix is the configured data store prefix, which may contain a per-environment placeholder.
	DataStorePrefix string
	// DataStorePrefix is the configured data store table name, which may contain a per-environment placeholder.
	TableName     string
	AllowedOrigin ct.OptStringList
	AllowedHeader ct.OptStringList
	// Whether this factory is used for offline mode or not.
	Offline bool
}

EnvConfigFactory is an abstraction of the logic for generating environment configurations that are partly parameterized, instead of each environment being manually configured. This is used in both auto-configuration mode and offline mode.

func NewEnvConfigFactoryForAutoConfig

func NewEnvConfigFactoryForAutoConfig(c config.AutoConfigConfig) EnvConfigFactory

NewEnvConfigFactoryForAutoConfig creates an EnvConfigFactory based on the auto-configuration mode settings.

func NewEnvConfigFactoryForOfflineMode

func NewEnvConfigFactoryForOfflineMode(c config.OfflineModeConfig) EnvConfigFactory

NewEnvConfigFactoryForOfflineMode creates an EnvConfigFactory based on the offline mode settings.

func (EnvConfigFactory) MakeEnvironmentConfig

func (f EnvConfigFactory) MakeEnvironmentConfig(params EnvironmentParams) config.EnvConfig

MakeEnvironmentConfig creates an EnvConfig based on both the individual EnvironmentParams and the properties of the EnvConfigFactory.

type EnvironmentParams

type EnvironmentParams struct {
	// ID is the environment ID.
	EnvID config.EnvironmentID

	// Identifiers contains the project and environment names and keys.
	Identifiers relayenv.EnvIdentifiers

	// SDKKey is the environment's anchor SDK key (the wire's sdkKey.value).
	SDKKey config.SDKKey

	// MobileKey is the environment's mobile key.
	MobileKey config.MobileKey

	// AcceptedSDKKeys is the full accepted set of SDK keys, including the anchor. ToParams always
	// leaves it non-nil, synthesizing from the singular sdkKey field when the payload has no
	// sdkKeys array.
	AcceptedSDKKeys []AcceptedSDKKey

	// AcceptedMobileKeys is the full accepted set of mobile keys. ToParams always leaves it non-nil,
	// synthesizing from the singular mobKey field when the payload has no mobileKeys array.
	AcceptedMobileKeys []AcceptedMobileKey

	// TTL is the cache TTL for PHP clients.
	TTL time.Duration

	// SecureMode is true if secure mode is required for this environment.
	SecureMode bool
}

EnvironmentParams contains environment-specific information obtained from LaunchDarkly which will be used to configure a Relay environment in auto-configuration mode or offline mode.

This is a simplified representation that does not contain all of the properties used in the auto-configuration or offline mode protocols, but only the ones that the core Relay logic needs.

func (EnvironmentParams) WithFilter

type EnvironmentRep

type EnvironmentRep struct {
	EnvID      config.EnvironmentID `json:"envID"`
	EnvKey     string               `json:"envKey"`
	EnvName    string               `json:"envName"`
	MobKey     config.MobileKey     `json:"mobKey"`
	ProjKey    string               `json:"projKey"`
	ProjName   string               `json:"projName"`
	SDKKey     SDKKeyRep            `json:"sdkKey"`
	SDKKeys    []ConcurrentKeyRep   `json:"sdkKeys,omitempty"`
	MobileKeys []ConcurrentKeyRep   `json:"mobileKeys,omitempty"`
	DefaultTTL int                  `json:"defaultTtl"`
	SecureMode bool                 `json:"secureMode"`
	Version    int                  `json:"version"`
}

EnvironmentRep is the wire shape of an environment, shared by RAC and the offline archive.

Wire vocabulary: "key" is the non-secret human-readable identifier; "value" is the credential secret. Relay's own SDKKey, MobileKey, and SDKCredential types hold what the wire calls "value". Do not rename them.

sdkKey and mobKey are the singular default credentials. sdkKey is an object because it also carries the legacy sdkKey.expiring slot; mobKey is a plain string because mobile keys never had one. sdkKeys and mobileKeys are the authoritative full accepted set, with entries of the form { key, value, expiry?, hasViews? }.

This parse path never sets DisallowUnknownFields, so a relay predating concurrent keys ignores sdkKeys and mobileKeys and keeps using sdkKey and mobKey.

func (EnvironmentRep) Describe

func (r EnvironmentRep) Describe() string

func (EnvironmentRep) ID

func (r EnvironmentRep) ID() string

func (EnvironmentRep) ToParams

func (r EnvironmentRep) ToParams() EnvironmentParams

ToParams converts the JSON properties for an environment into our internal parameter type.

type ExpiringKeyRep

type ExpiringKeyRep struct {
	Value     config.SDKKey              `json:"value"`
	Timestamp ldtime.UnixMillisecondTime `json:"timestamp"`
}

ExpiringKeyRep describes an old key that will expire at the specified date/time.

type FilterParams

type FilterParams struct {
	ProjKey string
	ID      config.FilterID
	Key     config.FilterKey
}

type FilterRep

type FilterRep struct {
	ProjKey   string           `json:"projKey"`
	FilterKey config.FilterKey `json:"key"`
	Version   int              `json:"version"`
}

func (FilterRep) Describe

func (f FilterRep) Describe() string

func (FilterRep) ToParams

func (f FilterRep) ToParams(id config.FilterID) FilterParams

ToParams converts the JSON properties for a filter into our internal parameter type. It requires an explicit FilterID because there is no ID included within the JSON representation.

func (FilterRep) ToTestParams

func (f FilterRep) ToTestParams() FilterParams

ToTestParams is similar to ToParams, but intended as a convenience for tests. It assumes that a filter's ID can be computed by concatenating the project key with the filter key.

type SDKKeyRep

type SDKKeyRep struct {
	Value    config.SDKKey  `json:"value"`
	Expiring ExpiringKeyRep `json:"expiring"`
}

SDKKeyRep describes an SDK key optionally accompanied by an old expiring key.

Jump to

Keyboard shortcuts

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