Documentation
¶
Overview ¶
Package cloudcontrol provides an in-memory implementation of the AWS CloudControl API service.
Index ¶
- Variables
- 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(_ *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) Snapshot(ctx context.Context) []byte
- type InMemoryBackend
- func (b *InMemoryBackend) AddProgressEvent(event *ProgressEvent)
- func (b *InMemoryBackend) CancelResourceRequest(requestToken string) (*ProgressEvent, error)
- func (b *InMemoryBackend) CreateResource(typeName, desiredState, clientToken string) (*ProgressEvent, error)
- func (b *InMemoryBackend) DeleteResource(typeName, identifier string) (*ProgressEvent, error)
- func (b *InMemoryBackend) GetResource(typeName, identifier string) (*Resource, error)
- func (b *InMemoryBackend) GetResourceRequestStatus(requestToken string) (*ProgressEvent, error)
- func (b *InMemoryBackend) ListAllResources() []*Resource
- func (b *InMemoryBackend) ListResourceRequests(filter *ResourceRequestFilter, maxResults int, nextToken string) ([]*ProgressEvent, string, error)
- func (b *InMemoryBackend) ListResources(typeName string, maxResults int, nextToken string) ([]*Resource, string)
- func (b *InMemoryBackend) Region() string
- func (b *InMemoryBackend) Reset()
- func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
- func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
- func (b *InMemoryBackend) UpdateResource(typeName, identifier, patchDocument string) (*ProgressEvent, error)
- type ProgressEvent
- type Provider
- type Resource
- type ResourceRequestFilter
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is returned when a requested resource does not exist. ErrNotFound = awserr.New("ResourceNotFoundException", awserr.ErrNotFound) // ErrAlreadyExists is returned when a resource with the same identifier already exists. ErrAlreadyExists = awserr.New("AlreadyExistsException", awserr.ErrConflict) // ErrValidation is returned when a required field is missing or has an invalid value. // CloudControl's error model has no ValidationException shape at all: every // operation instead declares InvalidRequestException ("invalid input from the // user has generated a generic exception") as its generic input-validation error. // See the Errors section of e.g. the CreateResource API reference. ErrValidation = awserr.New("InvalidRequestException", awserr.ErrInvalidParameter) // ErrRequestTokenNotFound is returned when a RequestToken does not correspond to // any tracked resource operation request. GetResourceRequestStatus declares // RequestTokenNotFoundException as its ONLY error, and CancelResourceRequest // declares it alongside ConcurrentModificationException; real AWS never returns // ResourceNotFoundException for an unrecognized RequestToken. ErrRequestTokenNotFound = awserr.New("RequestTokenNotFoundException", awserr.ErrNotFound) // ErrConcurrentModification is returned by CancelResourceRequest when the target // request is not in a cancellable (PENDING/IN_PROGRESS) state. Confirmed against // the CancelResourceRequest API reference's Errors section: // ConcurrentModificationException, HTTP 500 -- "The resource is currently being // modified by another operation". ErrConcurrentModification = awserr.New("ConcurrentModificationException", awserr.ErrConflict) )
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct {
Backend *InMemoryBackend
// contains filtered or unexported fields
}
Handler is the Echo HTTP handler for CloudControl API operations.
func NewHandler ¶
func NewHandler(backend *InMemoryBackend) *Handler
NewHandler creates a new CloudControl handler backed by backend. backend must not be nil.
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 extracts the CloudControl action from the X-Amz-Target header.
func (*Handler) ExtractResource ¶
ExtractResource extracts the resource type name from the request body for metrics/logging. Returns "cloudcontrol" as a stable low-cardinality label when a TypeName is absent.
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 CloudControl requests.
func (*Handler) MatchPriority ¶
MatchPriority returns the routing priority.
func (*Handler) Reset ¶
func (h *Handler) Reset()
Reset clears all backend state. Useful for test isolation.
func (*Handler) RouteMatcher ¶
RouteMatcher returns a function that matches CloudControl 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 never picked CloudControl up at all. This delegation (matching the codecommit/cleanrooms pattern) is what wires CloudControl into persistence for the first time.
type InMemoryBackend ¶
type InMemoryBackend struct {
// contains filtered or unexported fields
}
InMemoryBackend is a thread-safe in-memory store for CloudControl resources.
func NewInMemoryBackend ¶
func NewInMemoryBackend(accountID, region string) *InMemoryBackend
NewInMemoryBackend creates a new backend for the given account and region.
func (*InMemoryBackend) AddProgressEvent ¶
func (b *InMemoryBackend) AddProgressEvent(event *ProgressEvent)
AddProgressEvent inserts a ProgressEvent directly into the requests map. This is intended for use in tests to set up specific request states that cannot be reached through the normal API (e.g. IN_PROGRESS).
func (*InMemoryBackend) CancelResourceRequest ¶
func (b *InMemoryBackend) CancelResourceRequest(requestToken string) (*ProgressEvent, error)
CancelResourceRequest cancels the request identified by requestToken. An unrecognized requestToken returns ErrRequestTokenNotFound (RequestTokenNotFoundException). Cancelling an already-terminal request (SUCCESS, FAILED, CANCEL_COMPLETE, CANCEL_IN_PROGRESS) returns ErrConcurrentModification (ConcurrentModificationException), matching the real AWS API reference for this operation -- not a validation error.
func (*InMemoryBackend) CreateResource ¶
func (b *InMemoryBackend) CreateResource(typeName, desiredState, clientToken string) (*ProgressEvent, error)
CreateResource creates a new resource of the given type with the given desired state JSON. An optional clientToken may be supplied for idempotency: if the same token is supplied again the original ProgressEvent is returned without creating a duplicate resource.
func (*InMemoryBackend) DeleteResource ¶
func (b *InMemoryBackend) DeleteResource(typeName, identifier string) (*ProgressEvent, error)
DeleteResource removes the resource identified by typeName and identifier.
func (*InMemoryBackend) GetResource ¶
func (b *InMemoryBackend) GetResource(typeName, identifier string) (*Resource, error)
GetResource returns a copy of the resource identified by typeName and identifier.
func (*InMemoryBackend) GetResourceRequestStatus ¶
func (b *InMemoryBackend) GetResourceRequestStatus(requestToken string) (*ProgressEvent, error)
GetResourceRequestStatus returns a copy of the ProgressEvent for the given request token. Events are retained in the map until Reset() is called. An unrecognized requestToken returns ErrRequestTokenNotFound (RequestTokenNotFoundException), the only error this operation declares -- not ErrNotFound (ResourceNotFoundException), which describes a missing *resource*, not a missing *request token*.
func (*InMemoryBackend) ListAllResources ¶
func (b *InMemoryBackend) ListAllResources() []*Resource
ListAllResources returns all resources regardless of type, sorted by TypeName then Identifier. This is used by the dashboard only and is not a CloudControl API operation.
func (*InMemoryBackend) ListResourceRequests ¶
func (b *InMemoryBackend) ListResourceRequests( filter *ResourceRequestFilter, maxResults int, nextToken string, ) ([]*ProgressEvent, string, error)
ListResourceRequests returns all tracked resource requests, optionally filtered by operation type, operation status, and/or resource type name. Results are sorted by EventTime descending (most recent first) for deterministic output. Returns ErrValidation if the filter contains unknown operation or status strings.
func (*InMemoryBackend) ListResources ¶
func (b *InMemoryBackend) ListResources(typeName string, maxResults int, nextToken string) ([]*Resource, string)
ListResources returns a paginated list of resources of the given type, sorted by Identifier.
func (*InMemoryBackend) Region ¶
func (b *InMemoryBackend) Region() string
Region returns the region for this backend instance.
func (*InMemoryBackend) Reset ¶
func (b *InMemoryBackend) Reset()
Reset clears all state from the backend, returning it to a clean initial state.
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) Snapshot ¶
func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
Snapshot serializes the backend state to JSON. It implements persistence.Persistable.
func (*InMemoryBackend) UpdateResource ¶
func (b *InMemoryBackend) UpdateResource(typeName, identifier, patchDocument string) (*ProgressEvent, error)
UpdateResource applies a JSON RFC 6902 patch document to the resource.
type ProgressEvent ¶
type ProgressEvent struct {
EventTime unixEpochTime `json:"EventTime"`
TypeName string `json:"TypeName"`
Identifier string `json:"Identifier,omitempty"`
RequestToken string `json:"RequestToken"`
Operation string `json:"Operation"`
OperationStatus string `json:"OperationStatus"`
StatusMessage string `json:"StatusMessage,omitempty"`
// ResourceModel is a JSON string containing the resource model -- each
// resource property and its current value -- per the real ProgressEvent
// shape. Populated on SUCCESS so callers can read the resource straight
// off the ProgressEvent without a follow-up GetResource call, matching
// real AWS CLI/SDK/IaC-tool usage of this field.
ResourceModel string `json:"ResourceModel,omitempty"`
}
ProgressEvent represents the status of a CloudControl resource operation.
type Provider ¶
type Provider struct{}
Provider implements service.Provider for the CloudControl API service.
func (*Provider) Init ¶
func (p *Provider) Init(ctx *service.AppContext) (service.Registerable, error)
Init initializes the CloudControl API service.
type Resource ¶
type Resource struct {
TypeName string
Identifier string
Properties string // JSON string of current properties
}
Resource represents an in-memory CloudControl managed resource.
type ResourceRequestFilter ¶
type ResourceRequestFilter struct {
TypeName string
Operations []string
OperationStatuses []string
}
ResourceRequestFilter holds optional filter criteria for ListResourceRequests.