Documentation
¶
Index ¶
- Constants
- Variables
- type ConfigProvider
- type Database
- type Endpoint
- type Engine
- type Handler
- func (h *Handler) ExtractOperation(*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) Shutdown(context.Context)
- func (h *Handler) Snapshot(ctx context.Context) []byte
- type InMemoryBackend
- func (b *InMemoryBackend) Close()
- func (b *InMemoryBackend) Databases(id string) ([]string, error)
- func (b *InMemoryBackend) Delete(id string) error
- func (b *InMemoryBackend) DropDatabase(id, name string) error
- func (b *InMemoryBackend) Endpoint(id string) (Endpoint, bool)
- func (b *InMemoryBackend) Ensure(id string, spec Spec) (Endpoint, error)
- func (b *InMemoryBackend) EnsureDatabase(id, name, collation string) error
- func (b *InMemoryBackend) Reset()
- func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
- func (b *InMemoryBackend) SetLauncher(l Launcher, startup time.Duration)
- func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
- type LaunchSpec
- type Launcher
- type Provider
- type Settings
- type Spec
Constants ¶
const ( // EngineAuto launches SQL Server containers when a container runtime is reachable. EngineAuto = "auto" // EngineNone never starts containers: servers are state-only. EngineNone = "none" // DefaultImage is the SQL Server image servers run. DefaultImage = "mcr.microsoft.com/mssql/server:2022-CU26-ubuntu-22.04" // DefaultStartupTimeout bounds how long a server container may take to accept connections. DefaultStartupTimeout = 5 * time.Minute )
Variables ¶
var ( // ErrNotFound is returned for an unknown server. ErrNotFound = errors.New("azuresql: server not found") // ErrInvalid is returned for a malformed request. ErrInvalid = errors.New("azuresql: invalid request") // runs state-only. ErrRuntimeUnavailable = errors.New("azuresql: container runtime unavailable") // ErrNilAppContext is returned when Init is called with a nil AppContext. ErrNilAppContext = errors.New("azuresql: nil app context") )
Functions ¶
This section is empty.
Types ¶
type ConfigProvider ¶
type ConfigProvider interface {
GetAzureSQLSettings() Settings
}
ConfigProvider extracts the Azure SQL settings from the AppContext config.
type Endpoint ¶
Endpoint is where a server's TDS port listens. Port is 0 when the server is state-only.
type Engine ¶
type Engine interface {
// Endpoint is the host and published TDS port clients connect to.
Endpoint() (string, int)
// SetLogin creates the server-admin login, or resets its password, with sysadmin rights.
SetLogin(ctx context.Context, login, password string) error
CreateDatabase(ctx context.Context, name, collation string) error
DropDatabase(ctx context.Context, name string) error
ListDatabases(ctx context.Context) ([]string, error)
Close(ctx context.Context)
}
Engine is one running SQL Server. Methods are safe for sequential use per server.
type Handler ¶
type Handler struct {
Backend *InMemoryBackend
// contains filtered or unexported fields
}
Handler owns the SQL servers. Azure SQL has no HTTP data plane: ARM manages servers and clients speak TDS to each server's own port, so the handler never matches a request.
func (*Handler) ExtractOperation ¶
ExtractOperation is unused: requests never reach the shared router.
func (*Handler) ExtractResource ¶
ExtractResource is unused: requests never reach the shared router.
func (*Handler) GetSupportedOperations ¶
GetSupportedOperations lists the operations ARM's Microsoft.Sql provider drives.
func (*Handler) Handler ¶
func (h *Handler) Handler() echo.HandlerFunc
Handler returns a 404 handler.
func (*Handler) MatchPriority ¶
MatchPriority is irrelevant because RouteMatcher never matches.
func (*Handler) RouteMatcher ¶
RouteMatcher never matches.
type InMemoryBackend ¶
type InMemoryBackend struct {
// contains filtered or unexported fields
}
InMemoryBackend runs one SQL Server container per logical server, or tracks the server state-only when no container runtime is reachable. mu guards the map; life serialises lifecycle calls so a slow container start does not block reads.
func NewInMemoryBackend ¶
func NewInMemoryBackend() *InMemoryBackend
NewInMemoryBackend creates an empty backend with no launcher: servers are state-only.
func (*InMemoryBackend) Databases ¶
func (b *InMemoryBackend) Databases(id string) ([]string, error)
Databases lists the user databases the engine holds, or the tracked ones when the server is state-only.
func (*InMemoryBackend) Delete ¶
func (b *InMemoryBackend) Delete(id string) error
Delete stops the server and releases its port; a missing server is ErrNotFound.
func (*InMemoryBackend) DropDatabase ¶
func (b *InMemoryBackend) DropDatabase(id, name string) error
DropDatabase drops the database from the engine; a missing database is not an error.
func (*InMemoryBackend) Endpoint ¶
func (b *InMemoryBackend) Endpoint(id string) (Endpoint, bool)
Endpoint reports where the server's TDS port listens; ok is false for an unknown server.
func (*InMemoryBackend) Ensure ¶
func (b *InMemoryBackend) Ensure(id string, spec Spec) (Endpoint, error)
Ensure creates the server's engine, or applies a changed admin login or password to an existing one.
func (*InMemoryBackend) EnsureDatabase ¶
func (b *InMemoryBackend) EnsureDatabase(id, name, collation string) error
EnsureDatabase creates the database in the engine; an existing database is left as it is.
func (*InMemoryBackend) Restore ¶
func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
Restore loads a snapshot, starting every server again on a fresh port.
func (*InMemoryBackend) SetLauncher ¶
func (b *InMemoryBackend) SetLauncher(l Launcher, startup time.Duration)
SetLauncher makes new servers start engines through l.
type LaunchSpec ¶
LaunchSpec describes the engine of one logical server.
type Launcher ¶
type Launcher interface {
Launch(ctx context.Context, spec LaunchSpec) (Engine, error)
}
Launcher starts engines.
type Provider ¶
type Provider struct{}
Provider implements service.Provider for Azure SQL Database.
func (*Provider) Init ¶
func (p *Provider) Init(ctx *service.AppContext) (service.Registerable, error)
Init builds the backend and handler.
type Settings ¶
type Settings struct {
Engine string `` //nolint:lll // config struct tags are intentionally verbose
/* 272-byte string literal not displayed */
Image string `` //nolint:lll // config struct tags are intentionally verbose
/* 224-byte string literal not displayed */
StartupTimeout time.Duration `` //nolint:lll // config struct tags are intentionally verbose
/* 243-byte string literal not displayed */
}
Settings is the Kong-embedded configuration of the Azure SQL Database emulator.
func DefaultSettings ¶
func DefaultSettings() Settings
DefaultSettings returns the settings used when no ConfigProvider exists.
type Spec ¶
type Spec struct {
AdminLogin string `json:"adminLogin"`
AdminPassword string `json:"adminPassword"`
}
Spec is the part of a logical server's ARM configuration the engine acts on. An empty AdminLogin (Entra-only server) creates no SQL login; an empty AdminPassword on an existing server keeps the current one.