routing

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TargetToService = map[string]string{
	"dynamodb":                          "dynamodb",
	"dax":                               "dynamodb",
	"amazonsqs":                         "sqs",
	"amazonses":                         "ses",
	"amazonsns":                         "sns",
	"awskms":                            "kms",
	"amazonkinesis":                     "kinesis",
	"tagging":                           "tagging",
	"logs":                              "logs",
	"awslambda":                         "lambda",
	"awscognitoidentityproviderservice": "cognito-idp",
	"secretsmanager":                    "secretsmanager",
}

targetToService maps the lowercased X-Amz-Target service prefix to the canonical CloudMock service name. This handles services whose target prefix doesn't match their SigV4 signing name (e.g. Cognito uses "AWSCognitoIdentityProviderService" in X-Amz-Target but "cognito-idp" in the credential scope). TargetToService maps the lowercased X-Amz-Target service prefix to the canonical CloudMock service name.

Functions

func DetectAPIVersion

func DetectAPIVersion(r *http.Request, provider Provider) string

DetectAPIVersion extracts the provider-specific API version.

func DetectAction

func DetectAction(r *http.Request) string

DetectAction determines the AWS API action from the request. It checks X-Amz-Target (part after the dot) first, then the ?Action= query parameter. Returns empty string if not detected.

func DetectService

func DetectService(r *http.Request) string

DetectService determines the AWS service name from the request. It checks the Authorization header credential scope first (Credential=AKID/date/region/SERVICE/aws4_request), then falls back to X-Amz-Target (stripping the version suffix, e.g. "DynamoDB_20120810" → "dynamodb"), then checks for presigned URL query parameters (X-Amz-Credential). Returns lowercase service name, or empty string if not detected.

Types

type LazyService

type LazyService struct {
	// contains filtered or unexported fields
}

LazyService is a lightweight placeholder that satisfies service.Service for services registered via RegisterLazy that have not yet been initialized. It must never be used to handle real requests; Lookup will always return the real service after the first call.

func (*LazyService) Actions

func (l *LazyService) Actions() []service.Action

func (*LazyService) HandleRequest

func (l *LazyService) HandleRequest(_ *service.RequestContext) (*service.Response, error)

func (*LazyService) HealthCheck

func (l *LazyService) HealthCheck() error

func (*LazyService) Name

func (l *LazyService) Name() string

type Provider

type Provider string

Provider identifies the cloud provider protocol that owns a request.

const (
	ProviderAWS   Provider = "aws"
	ProviderAzure Provider = "azure"
	ProviderGCP   Provider = "gcp"
)

func DetectProvider

func DetectProvider(r *http.Request) Provider

DetectProvider identifies the cloud provider for r.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry holds the set of registered AWS service mocks.

func NewRegistry

func NewRegistry() *Registry

NewRegistry constructs an empty Registry.

func (*Registry) All

func (reg *Registry) All() []service.Service

All returns all services, forcing initialization of any lazy services. This is used by snapshot export/import which needs the real service instances.

func (*Registry) List

func (reg *Registry) List() []service.Service

List returns lightweight representations of all known services — both already-initialized and pending-lazy — in unspecified order. Lazy services are represented by a LazyService placeholder so that they are visible without forcing initialization.

func (*Registry) Lookup

func (reg *Registry) Lookup(name string) (service.Service, error)

Lookup returns the service registered under name, or an error if none exists. If the service has a pending lazy factory it is initialized on first call and the result is cached for all subsequent calls.

func (*Registry) LookupTarget

func (reg *Registry) LookupTarget(target RouteTarget) (service.Service, error)

LookupTarget resolves a provider-aware route target. AWS targets without an explicit API version fall back to the legacy Lookup path for backward compatibility with existing CloudMock service registration.

func (*Registry) LookupVersioned

func (reg *Registry) LookupVersioned(key ServiceKey) (service.Service, error)

LookupVersioned returns the service registered under key. If key omits APIVersion and a default version is configured for that provider/service, the default version is used.

func (*Registry) Register

func (reg *Registry) Register(svc service.Service)

Register adds svc to the registry, keyed by svc.Name(). If a service with the same name is already registered it is replaced. Registering an eager service also removes any pending lazy factory for that name.

func (*Registry) RegisterLazy

func (reg *Registry) RegisterLazy(name string, factory ServiceFactory)

RegisterLazy records a factory for name. The factory is called at most once, the first time Lookup is called for that name. Registering a lazy factory overwrites any existing factory for the same name, but does not affect an already-initialized eager service.

func (*Registry) RegisterLazyVersioned

func (reg *Registry) RegisterLazyVersioned(key ServiceKey, factory ServiceFactory)

RegisterLazyVersioned records a versioned service factory. The factory is called at most once, on the first LookupVersioned for that exact key.

func (*Registry) RegisterVersioned

func (reg *Registry) RegisterVersioned(key ServiceKey, svc service.Service)

RegisterVersioned adds svc under a provider/service/API-version key. It allows two implementations for the same logical service to coexist when cloud providers expose parallel API versions.

func (*Registry) SetDefaultVersion

func (reg *Registry) SetDefaultVersion(provider Provider, serviceName, apiVersion string)

SetDefaultVersion declares the API version used when a request omits an explicit version for a provider/service pair.

type RouteTarget

type RouteTarget struct {
	Provider   Provider
	Service    string
	Action     string
	APIVersion string
}

RouteTarget is the provider-aware routing identity for an incoming request. The legacy AWS router only needed Service and Action; Azure and future providers also need an API version because resource-provider versions can coexist for the same logical service.

func DetectTarget

func DetectTarget(r *http.Request) RouteTarget

DetectTarget returns the provider, service, action, and API version for r.

type ServiceFactory

type ServiceFactory func() service.Service

ServiceFactory is a function that constructs and returns a Service. It is called at most once per service name when using RegisterLazy.

type ServiceKey

type ServiceKey struct {
	Provider   Provider
	Service    string
	APIVersion string
}

ServiceKey identifies a registered service implementation.

Jump to

Keyboard shortcuts

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