Documentation
¶
Overview ¶
Package azureappconfig emulates Azure App Configuration: key-values with labels, ETags and sync tokens, revisions and point-in-time reads, locks, snapshots and feature flags behind the HMAC-SHA256 authenticated data plane, sharing its stores and access keys with the ARM plane. See PARITY.md.
Index ¶
- Constants
- Variables
- func SignRequest(r *http.Request, signed []string, secret string) (string, error)
- func ValidStoreName(name string) bool
- type AccessKey
- type ConfigProvider
- type Filter
- type Handler
- 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) Reset()
- func (h *Handler) Restore(ctx context.Context, data []byte) error
- func (h *Handler) RouteMatcher() service.Matcher
- func (h *Handler) Shutdown(ctx context.Context)
- func (h *Handler) Snapshot(ctx context.Context) []byte
- func (h *Handler) StartWorker(ctx context.Context) error
- type InMemoryBackend
- func (b *InMemoryBackend) AccessKeys(name string) ([]AccessKey, error)
- func (b *InMemoryBackend) AllKeyValues(storeName string) ([]KeyValue, error)
- func (b *InMemoryBackend) CreateSnapshot(storeName, name string, spec SnapshotSpec) (Snapshot, error)
- func (b *InMemoryBackend) DeleteKeyValue(storeName, key, label string, p Precondition) (KeyValue, error)
- func (b *InMemoryBackend) DeleteStore(name string) error
- func (b *InMemoryBackend) EnsureStore(name string) error
- func (b *InMemoryBackend) GetKeyValue(storeName, key, label string, at time.Time) (KeyValue, error)
- func (b *InMemoryBackend) GetSnapshot(storeName, name string) (Snapshot, error)
- func (b *InMemoryBackend) HasStore(name string) bool
- func (b *InMemoryBackend) KeyOwner(id string) (string, AccessKey, bool)
- func (b *InMemoryBackend) ListKeyNames(storeName, name string, at time.Time) ([]string, error)
- func (b *InMemoryBackend) ListKeyValues(storeName string, sel Selector, at time.Time) ([]KeyValue, error)
- func (b *InMemoryBackend) ListLabelNames(storeName, name string, at time.Time) ([]string, error)
- func (b *InMemoryBackend) ListRevisions(storeName string, sel Selector, at time.Time) ([]KeyValue, error)
- func (b *InMemoryBackend) ListSnapshots(storeName, nameFilter string, statuses []string) ([]Snapshot, error)
- func (b *InMemoryBackend) PutStore(name string) (StoreInfo, error)
- func (b *InMemoryBackend) RegenerateKey(name, keyID string) (AccessKey, error)
- func (b *InMemoryBackend) Reset()
- func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
- func (b *InMemoryBackend) SetKeyValue(storeName, key, label string, in KVInput, p Precondition) (KeyValue, error)
- func (b *InMemoryBackend) SetLock(storeName, key, label string, locked bool, p Precondition) (KeyValue, error)
- func (b *InMemoryBackend) SetSnapshotStatus(storeName, name, status string, p Precondition) (Snapshot, error)
- func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
- func (b *InMemoryBackend) SnapshotKeyValues(storeName, name string, sel Selector) ([]KeyValue, error)
- func (b *InMemoryBackend) Store(name string) (StoreInfo, error)
- func (b *InMemoryBackend) StoreNames() []string
- func (b *InMemoryBackend) SyncToken(name string) string
- type KVInput
- type KeyValue
- type Precondition
- type Provider
- type Selector
- type Settings
- type Snapshot
- type SnapshotSpec
- type StoreInfo
Constants ¶
const ( ContentTypeFeatureFlag = "application/vnd.microsoft.appconfig.ff+json;charset=utf-8" ContentTypeKeyVaultRef = "application/vnd.microsoft.appconfig.keyvaultref+json;charset=utf-8" FeatureFlagPrefix = ".appconfig.featureflag/" )
Content types the service and its clients treat specially.
const DefaultPort = 10008
DefaultPort is the App Configuration HTTPS data-plane port.
const DefaultStoreName = "default"
DefaultStoreName is the store addressed when a request names none.
Variables ¶
var ( ErrStoreNotFound = errors.New("azureappconfig: configuration store not found") ErrKeyNotFound = errors.New("azureappconfig: key-value not found") ErrKeyIDNotFound = errors.New("azureappconfig: access key not found") ErrSnapshotNotFound = errors.New("azureappconfig: snapshot not found") ErrSnapshotExists = errors.New("azureappconfig: snapshot already exists") ErrSnapshotStatus = errors.New("azureappconfig: snapshot is not in a state that allows this change") ErrLocked = errors.New("azureappconfig: key-value is read-only") ErrPrecondition = errors.New("azureappconfig: precondition failed") ErrInvalidName = errors.New("azureappconfig: invalid store name") ErrInvalidArgument = errors.New("azureappconfig: invalid argument") ErrForbidden = errors.New("azureappconfig: the access key is read-only") ErrNilAppContext = errors.New("azureappconfig: nil app context") ErrTooLarge = errors.New("azureappconfig: request body too large") )
Backend errors.
Functions ¶
func SignRequest ¶
SignRequest computes the HMAC-SHA256 signature of the request for the given signed headers and base64 secret.
func ValidStoreName ¶
ValidStoreName reports whether name is a legal store name (5-50 letters, digits, hyphens).
Types ¶
type AccessKey ¶
type AccessKey struct {
LastModified time.Time `json:"lastModified"`
ID string `json:"id"`
Name string `json:"name"`
Secret string `json:"secret"`
ReadOnly bool `json:"readOnly,omitempty"`
}
AccessKey is one of a store's four HMAC credentials.
type ConfigProvider ¶
type ConfigProvider interface {
GetAzureAppConfigSettings() Settings
}
ConfigProvider extracts the App Configuration settings from the AppContext config.
type Handler ¶
type Handler struct {
Backend *InMemoryBackend
Settings Settings
Port int
// contains filtered or unexported fields
}
Handler owns the HTTPS listener.
func NewHandler ¶
func NewHandler(backend *InMemoryBackend, settings Settings) *Handler
NewHandler returns a Handler over backend.
func (*Handler) ExtractOperation ¶
ExtractOperation implements service.Service.
func (*Handler) ExtractResource ¶
ExtractResource implements service.Service.
func (*Handler) GetSupportedOperations ¶
GetSupportedOperations implements service.Service.
func (*Handler) Handler ¶
func (h *Handler) Handler() echo.HandlerFunc
Handler returns the echo handler of the HTTPS listener.
func (*Handler) MatchPriority ¶
MatchPriority implements service.Registerable.
func (*Handler) RouteMatcher ¶
RouteMatcher never matches: App Configuration listens on its own port.
type InMemoryBackend ¶
type InMemoryBackend struct {
// contains filtered or unexported fields
}
InMemoryBackend holds every configuration store; the ARM and data planes share it.
func NewInMemoryBackend ¶
func NewInMemoryBackend() *InMemoryBackend
NewInMemoryBackend returns an empty backend using the wall clock.
func (*InMemoryBackend) AccessKeys ¶
func (b *InMemoryBackend) AccessKeys(name string) ([]AccessKey, error)
AccessKeys returns the store's four credentials.
func (*InMemoryBackend) AllKeyValues ¶
func (b *InMemoryBackend) AllKeyValues(storeName string) ([]KeyValue, error)
AllKeyValues returns every current key-value of the store.
func (*InMemoryBackend) CreateSnapshot ¶
func (b *InMemoryBackend) CreateSnapshot(storeName, name string, spec SnapshotSpec) (Snapshot, error)
CreateSnapshot captures the key-values selected by the spec; the snapshot is ready immediately.
func (*InMemoryBackend) DeleteKeyValue ¶
func (b *InMemoryBackend) DeleteKeyValue(storeName, key, label string, p Precondition) (KeyValue, error)
DeleteKeyValue removes a key-value and returns its last state.
func (*InMemoryBackend) DeleteStore ¶
func (b *InMemoryBackend) DeleteStore(name string) error
DeleteStore removes a store with all its key-values and snapshots.
func (*InMemoryBackend) EnsureStore ¶
func (b *InMemoryBackend) EnsureStore(name string) error
EnsureStore creates the store when missing; it accepts any non-empty name.
func (*InMemoryBackend) GetKeyValue ¶
GetKeyValue returns the key-value; a non-zero at reads its state at that time.
func (*InMemoryBackend) GetSnapshot ¶
func (b *InMemoryBackend) GetSnapshot(storeName, name string) (Snapshot, error)
GetSnapshot returns a snapshot's metadata and items.
func (*InMemoryBackend) HasStore ¶
func (b *InMemoryBackend) HasStore(name string) bool
HasStore reports whether the store exists.
func (*InMemoryBackend) KeyOwner ¶
func (b *InMemoryBackend) KeyOwner(id string) (string, AccessKey, bool)
KeyOwner finds the credential with the given id across all stores.
func (*InMemoryBackend) ListKeyNames ¶
ListKeyNames returns the distinct keys matching the name filter.
func (*InMemoryBackend) ListKeyValues ¶
func (b *InMemoryBackend) ListKeyValues(storeName string, sel Selector, at time.Time) ([]KeyValue, error)
ListKeyValues returns the key-values matching sel, as of at when non-zero.
func (*InMemoryBackend) ListLabelNames ¶
ListLabelNames returns the distinct non-null labels matching the name filter.
func (*InMemoryBackend) ListRevisions ¶
func (b *InMemoryBackend) ListRevisions(storeName string, sel Selector, at time.Time) ([]KeyValue, error)
ListRevisions returns every recorded state of the key-values matching sel up to at (zero: all).
func (*InMemoryBackend) ListSnapshots ¶
func (b *InMemoryBackend) ListSnapshots(storeName, nameFilter string, statuses []string) ([]Snapshot, error)
ListSnapshots returns snapshots whose name matches the filter and whose status is in statuses.
func (*InMemoryBackend) PutStore ¶
func (b *InMemoryBackend) PutStore(name string) (StoreInfo, error)
PutStore creates a store, or returns the existing one unchanged.
func (*InMemoryBackend) RegenerateKey ¶
func (b *InMemoryBackend) RegenerateKey(name, keyID string) (AccessKey, error)
RegenerateKey replaces the secret (and id) of the credential with the given id.
func (*InMemoryBackend) Restore ¶
func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
Restore implements persistence.Persistable.
func (*InMemoryBackend) SetKeyValue ¶
func (b *InMemoryBackend) SetKeyValue(storeName, key, label string, in KVInput, p Precondition) (KeyValue, error)
SetKeyValue creates or replaces a key-value.
func (*InMemoryBackend) SetLock ¶
func (b *InMemoryBackend) SetLock(storeName, key, label string, locked bool, p Precondition) (KeyValue, error)
SetLock marks a key-value read-only or writable again.
func (*InMemoryBackend) SetSnapshotStatus ¶
func (b *InMemoryBackend) SetSnapshotStatus(storeName, name, status string, p Precondition) (Snapshot, error)
SetSnapshotStatus archives (ready -> archived) or recovers (archived -> ready) a snapshot.
func (*InMemoryBackend) Snapshot ¶
func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
Snapshot implements persistence.Persistable.
func (*InMemoryBackend) SnapshotKeyValues ¶
func (b *InMemoryBackend) SnapshotKeyValues(storeName, name string, sel Selector) ([]KeyValue, error)
SnapshotKeyValues returns the items of a snapshot matching sel.
func (*InMemoryBackend) Store ¶
func (b *InMemoryBackend) Store(name string) (StoreInfo, error)
Store returns the ARM-visible view of a store.
func (*InMemoryBackend) StoreNames ¶
func (b *InMemoryBackend) StoreNames() []string
StoreNames returns the store names sorted.
func (*InMemoryBackend) SyncToken ¶
func (b *InMemoryBackend) SyncToken(name string) string
SyncToken returns the store's current sync token.
type KeyValue ¶
type KeyValue struct {
LastModified time.Time `json:"lastModified"`
Value *string `json:"value,omitempty"`
ContentType *string `json:"contentType,omitempty"`
Tags map[string]string `json:"tags,omitempty"`
Key string `json:"key"`
Label string `json:"label,omitempty"`
ETag string `json:"etag"`
Locked bool `json:"locked,omitempty"`
}
KeyValue is one configuration setting. An empty Label is the null label.
type Precondition ¶
Precondition carries the If-Match / If-None-Match request headers (already unquoted).
type Provider ¶
type Provider struct{}
Provider implements service.Provider for Azure App Configuration.
func (*Provider) Init ¶
func (p *Provider) Init(ctx *service.AppContext) (service.Registerable, error)
Init builds the backend and handler; the port is bound by Handler.StartWorker.
type Selector ¶
type Selector struct {
// contains filtered or unexported fields
}
Selector is the parsed key/label/tags filter of a list request.
type Settings ¶
type Settings struct {
TLSCertFile string `` //nolint:lll // config struct tags are intentionally verbose
/* 245-byte string literal not displayed */
TLSKeyFile string `` //nolint:lll // config struct tags are intentionally verbose
/* 140-byte string literal not displayed */
Port int `` //nolint:lll // config struct tags are intentionally verbose
/* 261-byte string literal not displayed */
ValidateHMAC bool `` //nolint:lll // config struct tags are intentionally verbose
/* 261-byte string literal not displayed */
AutoCreate bool `` //nolint:lll // config struct tags are intentionally verbose
/* 260-byte string literal not displayed */
}
Settings is the Kong-embedded configuration of the App Configuration emulator.
func DefaultSettings ¶
func DefaultSettings() Settings
DefaultSettings returns the settings used when no ConfigProvider exists.
type Snapshot ¶
type Snapshot struct {
Created time.Time `json:"created"`
Expires *time.Time `json:"expires,omitempty"`
Tags map[string]string `json:"tags,omitempty"`
Name string `json:"name"`
Status string `json:"status"`
Composition string `json:"composition"`
ETag string `json:"etag"`
Filters []Filter `json:"filters"`
Items []KeyValue `json:"items"`
Retention int64 `json:"retention"`
Size int64 `json:"size"`
}
Snapshot is an immutable point-in-time set of key-values.