Documentation
¶
Overview ¶
Package appconfigdata provides an in-memory stub for the AWS AppConfigData service, which is used to retrieve deployed configuration data for applications at runtime.
Index ¶
- Constants
- Variables
- type ConfigVersion
- type ConfigurationProfile
- type Handler
- func (h *Handler) ChaosOperations() []string
- func (h *Handler) ChaosRegions() []string
- func (h *Handler) ChaosServiceName() string
- func (h *Handler) ExtractOperation(c *echo.Context) string
- func (h *Handler) ExtractResource(c *echo.Context) string
- func (h *Handler) GetSupportedOperations() []string
- func (h *Handler) Handler() echo.HandlerFunc
- func (h *Handler) MatchPriority() int
- func (h *Handler) Name() string
- func (h *Handler) Restore(ctx context.Context, data []byte) error
- func (h *Handler) RouteMatcher() service.Matcher
- func (h *Handler) Snapshot(ctx context.Context) []byte
- func (h *Handler) StartWorker(ctx context.Context) error
- type InMemoryBackend
- func (b *InMemoryBackend) DeleteProfile(app, env, profile string) bool
- func (b *InMemoryBackend) EndSession(token string) bool
- func (b *InMemoryBackend) GetLatestConfiguration(token string) ([]byte, string, string, string, string, error)
- func (b *InMemoryBackend) GetStats() ServiceStats
- func (b *InMemoryBackend) ListProfiles() []ConfigurationProfile
- func (b *InMemoryBackend) ListSessions() []Session
- func (b *InMemoryBackend) ListSessionsSafe() []SafeSession
- func (b *InMemoryBackend) LookupSession(token string) *Session
- func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
- func (b *InMemoryBackend) SetConfiguration(app, env, profile, content, contentType string) error
- func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
- func (b *InMemoryBackend) StartSession(app, env, profile string, pollIntervalInSeconds int) (string, error)
- func (b *InMemoryBackend) SweepExpiredSessions(ctx context.Context, ttl time.Duration)
- type Janitor
- type Provider
- type SafeSession
- type ServiceStats
- type Session
- type StorageBackend
Constants ¶
const ( // DefaultJanitorInterval is how often the janitor sweeps expired sessions. DefaultJanitorInterval = time.Hour )
const ( // DefaultSessionTTL is how long a session may be idle before the janitor evicts it. // AWS tokens expire after ~24 h; we use 1 h idle TTL with absolute 24 h cap. DefaultSessionTTL = 1 * time.Hour )
Variables ¶
var ( // ErrSessionNotFound is returned when the requested session token does not exist in the map. ErrSessionNotFound = errors.New("bad request: invalid configuration token") // ErrTokenCorrupted is returned when the token format or HMAC is invalid. ErrTokenCorrupted = errors.New("bad request: configuration token is corrupted") // ErrTokenExpired is returned when the session token has passed its expiry time. // AWS returns BadRequestException (400) for expired tokens, not 401. ErrTokenExpired = errors.New("bad request: configuration token has expired") // ErrProfileNotFound is returned when no configuration has been stored for a profile. ErrProfileNotFound = errors.New("resource not found: configuration profile not found") // ErrResourceRemoved is returned when a session's app/env/profile was deleted after the session started. ErrResourceRemoved = errors.New("resource not found: application, environment, or profile no longer exists") // ErrContentTooLarge is returned when configuration content exceeds the size limit. ErrContentTooLarge = errors.New("bad request: content exceeds maximum size of 1 MiB") // ErrInvalidPollInterval is returned when RequiredMinimumPollIntervalInSeconds is out of range. ErrInvalidPollInterval = errors.New( "bad request: RequiredMinimumPollIntervalInSeconds must be 0 or between 15 and 86400", ) // ErrPollTooFrequent is returned when a client polls faster than its declared minimum interval. ErrPollTooFrequent = errors.New( "bad request: polling too frequently — wait for the interval in Next-Poll-Interval-In-Seconds", ) // ErrContentTypeMismatch is returned when content is declared as JSON but is not valid JSON. ErrContentTypeMismatch = errors.New("bad request: content is not valid for the declared content type") // ErrNoActiveDeployment is returned when StartConfigurationSession is called for a profile // that has no active deployment (no configuration has been published yet). ErrNoActiveDeployment = errors.New( "resource not found: no active deployment found for the given application, environment, and configuration profile", ) // ErrIdentifierTooLong is returned when an identifier exceeds the maximum allowed length. ErrIdentifierTooLong = errors.New("bad request: identifier exceeds maximum length of 128 characters") )
Functions ¶
This section is empty.
Types ¶
type ConfigVersion ¶
type ConfigVersion struct {
UpdatedAt time.Time `json:"updatedAt"`
Content string `json:"content"`
ContentType string `json:"contentType"`
ContentHash string `json:"contentHash"`
VersionLabel string `json:"versionLabel"`
DeploymentID string `json:"deploymentId"`
VersionNumber int `json:"versionNumber"`
}
ConfigVersion records a historical snapshot of configuration content.
type ConfigurationProfile ¶
type ConfigurationProfile struct {
UpdatedAt time.Time `json:"updatedAt"`
ApplicationIdentifier string `json:"applicationIdentifier"`
EnvironmentIdentifier string `json:"environmentIdentifier"`
ConfigurationProfileIdentifier string `json:"configurationProfileIdentifier"`
Content string `json:"content"`
ContentType string `json:"contentType"`
ContentHash string `json:"contentHash"`
VersionLabel string `json:"versionLabel"`
DeploymentID string `json:"deploymentId"`
History []ConfigVersion `json:"history"`
VersionNumber int `json:"versionNumber"`
}
ConfigurationProfile stores configuration content for an application/environment/profile combination.
type Handler ¶
type Handler struct {
Backend *InMemoryBackend
}
Handler is the Echo HTTP handler for AppConfigData operations.
func NewHandler ¶
func NewHandler(backend *InMemoryBackend) *Handler
NewHandler creates a new AppConfigData Handler.
func (*Handler) ChaosOperations ¶
ChaosOperations returns all operations that can be fault-injected.
func (*Handler) ChaosRegions ¶
ChaosRegions returns all regions this handler instance handles.
func (*Handler) ChaosServiceName ¶
ChaosServiceName returns the lowercase AWS service name for fault rule matching.
func (*Handler) ExtractOperation ¶
ExtractOperation returns the operation name based on the request path.
func (*Handler) ExtractResource ¶
ExtractResource returns a stable, non-sensitive resource label for telemetry. For GetLatestConfiguration, it resolves the session to return app/env/profile; for other operations it returns a fixed label to avoid high-cardinality metrics.
func (*Handler) GetSupportedOperations ¶
GetSupportedOperations returns the list of supported operations.
func (*Handler) Handler ¶
func (h *Handler) Handler() echo.HandlerFunc
Handler returns the Echo handler function for AppConfigData operations.
func (*Handler) MatchPriority ¶
MatchPriority returns the routing priority.
func (*Handler) RouteMatcher ¶
RouteMatcher returns a function matching AppConfigData requests.
func (*Handler) Snapshot ¶
Snapshot implements persistence.Persistable by delegating to the backend. Handler previously had no Snapshot/Restore of its own -- and neither did InMemoryBackend -- so cli.go's generic setupPersistence (which type-asserts the registered service.Registerable, i.e. the Handler, for a Snapshot/Restore pair) never picked AppConfigData up at all: dead wiring, with no persistence underneath it either. This delegation (matching the cleanrooms/appconfig/codecommit pattern) is what wires AppConfigData into persistence for the first time.
type InMemoryBackend ¶
type InMemoryBackend struct {
// contains filtered or unexported fields
}
InMemoryBackend implements StorageBackend for AppConfigData.
func NewInMemoryBackend ¶
func NewInMemoryBackend() *InMemoryBackend
NewInMemoryBackend creates a new InMemoryBackend with a freshly generated signing key.
func (*InMemoryBackend) DeleteProfile ¶
func (b *InMemoryBackend) DeleteProfile(app, env, profile string) bool
DeleteProfile removes a configuration profile and its associated sessions.
func (*InMemoryBackend) EndSession ¶
func (b *InMemoryBackend) EndSession(token string) bool
EndSession terminates the session with the given token. Returns false if not found.
func (*InMemoryBackend) GetLatestConfiguration ¶
func (b *InMemoryBackend) GetLatestConfiguration( token string, ) ([]byte, string, string, string, string, error)
GetLatestConfiguration retrieves configuration data for the given token and returns a new token. The token is rotated on every successful call; the old token enters a short grace window so that clients can safely retry after a transient failure without losing their session.
Returned values: content, contentType, nextToken, contentHash, versionLabel, error.
func (*InMemoryBackend) GetStats ¶
func (b *InMemoryBackend) GetStats() ServiceStats
GetStats returns aggregate service statistics.
func (*InMemoryBackend) ListProfiles ¶
func (b *InMemoryBackend) ListProfiles() []ConfigurationProfile
ListProfiles returns all stored configuration profiles.
func (*InMemoryBackend) ListSessions ¶
func (b *InMemoryBackend) ListSessions() []Session
ListSessions returns all active sessions.
func (*InMemoryBackend) ListSessionsSafe ¶
func (b *InMemoryBackend) ListSessionsSafe() []SafeSession
ListSessionsSafe returns all active sessions with tokens truncated for safe display. Use this for admin list endpoints; never return full tokens in list responses.
func (*InMemoryBackend) LookupSession ¶
func (b *InMemoryBackend) LookupSession(token string) *Session
LookupSession returns the session for the given token, or nil if not found. This is a read-only lookup; it does not rotate the token.
func (*InMemoryBackend) Restore ¶
func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
Restore deserializes backend state from a snapshot. It implements persistence.Persistable.
func (*InMemoryBackend) SetConfiguration ¶
func (b *InMemoryBackend) SetConfiguration(app, env, profile, content, contentType string) error
SetConfiguration stores or updates configuration content for a profile. Returns ErrContentTooLarge if content exceeds maxContentBytes. Returns ErrContentTypeMismatch if contentType indicates JSON but content is not valid JSON.
func (*InMemoryBackend) Snapshot ¶
func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
Snapshot serializes the backend state to JSON. It implements persistence.Persistable.
func (*InMemoryBackend) StartSession ¶
func (b *InMemoryBackend) StartSession( app, env, profile string, pollIntervalInSeconds int, ) (string, error)
StartSession creates a new retrieval session and returns the initial token. pollIntervalInSeconds must be 0 (use default) or between minPollIntervalSeconds and maxPollIntervalSeconds (inclusive). Returns ErrNoActiveDeployment when no configuration has been published for the profile.
func (*InMemoryBackend) SweepExpiredSessions ¶
func (b *InMemoryBackend) SweepExpiredSessions(ctx context.Context, ttl time.Duration)
SweepExpiredSessions removes sessions that have been idle longer than ttl OR that have exceeded the absolute session lifetime (sessionAbsoluteMaxTTL from CreatedAt). Expired grace tokens are also purged in the same pass.
type Janitor ¶
type Janitor struct {
Backend *InMemoryBackend
Interval time.Duration
SessionTTL time.Duration
}
Janitor is the AppConfig Data background worker that prunes expired retrieval sessions.
func NewJanitor ¶
func NewJanitor(backend *InMemoryBackend) *Janitor
NewJanitor creates a new AppConfig Data Janitor with default settings.
type Provider ¶
type Provider struct{}
Provider implements service.Provider for the AppConfigData service.
func (*Provider) Init ¶
func (p *Provider) Init(_ *service.AppContext) (service.Registerable, error)
Init initialises the AppConfigData backend and handler.
type SafeSession ¶
type SafeSession struct {
CreatedAt time.Time `json:"createdAt"`
LastAccessedAt time.Time `json:"lastAccessedAt"`
LastPollAt time.Time `json:"lastPollAt"`
ExpiresAt time.Time `json:"expiresAt"`
TokenPrefix string `json:"tokenPrefix"` // first8…last4, e.g. "abcd1234...ef12"
TokenFamilyID string `json:"tokenFamilyId"`
ApplicationIdentifier string `json:"applicationIdentifier"`
EnvironmentIdentifier string `json:"environmentIdentifier"`
ConfigurationProfileIdentifier string `json:"configurationProfileIdentifier"`
PollIntervalInSeconds int `json:"pollIntervalInSeconds"`
PollCount int `json:"pollCount"`
}
SafeSession mirrors Session but truncates the token for safe display in admin UIs. The full token is never returned in list responses; only via authenticated audit endpoints.
type ServiceStats ¶
type ServiceStats struct {
LastSweepAt time.Time `json:"lastSweepAt"`
SessionTTL string `json:"sessionTtl"`
JanitorPeriod string `json:"janitorPeriod"`
SessionCount int `json:"sessionCount"`
ProfileCount int `json:"profileCount"`
TotalPollCount int64 `json:"totalPollCount"`
TotalPollFailures int64 `json:"totalPollFailures"`
ConfigurationChangeCount int64 `json:"configurationChangeCount"`
}
ServiceStats holds aggregate metrics for the AppConfigData service.
type Session ¶
type Session struct {
CreatedAt time.Time `json:"createdAt"`
LastAccessedAt time.Time `json:"lastAccessedAt"`
LastPollAt time.Time `json:"lastPollAt"`
ExpiresAt time.Time `json:"expiresAt"`
Token string `json:"token"`
TokenFamilyID string `json:"tokenFamilyId"`
PreviousContentHash string `json:"previousContentHash"`
ApplicationIdentifier string `json:"applicationIdentifier"`
EnvironmentIdentifier string `json:"environmentIdentifier"`
ConfigurationProfileIdentifier string `json:"configurationProfileIdentifier"`
PollIntervalInSeconds int `json:"pollIntervalInSeconds"`
PollCount int `json:"pollCount"`
}
Session represents an active configuration retrieval session.
type StorageBackend ¶
type StorageBackend interface {
// Snapshot and Restore implement persistence.Persistable. Handler
// delegates to them (see persistence.go) so cli.go's generic
// setupPersistence picks AppConfigData up.
Snapshot(ctx context.Context) []byte
Restore(ctx context.Context, data []byte) error
// SetConfiguration stores or updates configuration content for a profile.
SetConfiguration(app, env, profile, content, contentType string) error
// StartSession creates a new retrieval session and returns the initial token.
StartSession(app, env, profile string, pollIntervalInSeconds int) (string, error)
// GetLatestConfiguration retrieves configuration for the token.
// Returns content, contentType, nextToken, contentHash, versionLabel.
GetLatestConfiguration(
token string,
) (content []byte, contentType string, nextToken string, contentHash string, versionLabel string, err error)
// LookupSession returns the session for the given token, or nil if not found.
LookupSession(token string) *Session
// ListProfiles returns all stored configuration profiles.
ListProfiles() []ConfigurationProfile
// ListSessions returns all active sessions (includes full tokens — use only internally).
ListSessions() []Session
// ListSessionsSafe returns all active sessions with tokens truncated for safe display.
ListSessionsSafe() []SafeSession
// EndSession terminates the session with the given token. Returns false if not found.
EndSession(token string) bool
// DeleteProfile removes a configuration profile and its associated sessions.
DeleteProfile(app, env, profile string) bool
// GetStats returns aggregate service statistics.
GetStats() ServiceStats
// SweepExpiredSessions removes sessions idle longer than ttl or past absolute expiry.
SweepExpiredSessions(ctx context.Context, ttl time.Duration)
}
StorageBackend defines the operations supported by the AppConfigData in-memory backend.