Documentation
¶
Overview ¶
Package http provides a TenantLister that pulls tenant IDs from a control-plane API conforming to the go-bricks pre-defined contract.
Contract (responses use the standard go-bricks APIResponse envelope):
GET <base>/tenants?limit=<int>&cursor=<opaque>
200 OK
{
"data": { "tenants": [ {"id": "..."}, ... ], "next_cursor": "..." },
"meta": { "timestamp": "...", "traceId": "..." }
}
4xx/5xx
{ "error": { "code": "...", "message": "..." }, "meta": { ... } }
next_cursor empty/absent ends the iteration.
Index ¶
Constants ¶
const DefaultMaxResponseBytes int64 = 4194304 // 4 MiB
DefaultMaxResponseBytes caps a single page response when Options.MaxResponseBytes is unset. 4 MiB is far past any real page: a page carries at most PageLimit tenant IDs, and even 1000 UUIDs is ~40 KB. Spelled as a plain literal rather than 4 << 20 so the mutation gate cannot generate a bitwise-shift mutant on a line no test could distinguish.
const DefaultPageLimit = 100
DefaultPageLimit is the default page size requested from the control-plane.
const DefaultTimeout = 30 * time.Second
DefaultTimeout is applied to the underlying *http.Client when none is supplied.
Variables ¶
var ErrInsecureScheme = errors.New("migration/source/http: http:// scheme requires Options.AllowInsecureScheme=true (defense-in-depth: bearer token would be transmitted in clear text)")
ErrInsecureScheme is returned by New when the supplied base URL uses a plaintext scheme (`http://`) and Options.AllowInsecureScheme is false.
var ErrResponseTooLarge = errors.New("migration/source/http: control-plane response exceeded the configured maximum")
ErrResponseTooLarge is returned when one page response exceeds Options.MaxResponseBytes (DefaultMaxResponseBytes when unset).
var ErrUnsupportedScheme = errors.New("migration/source/http: unsupported URL scheme (expected http or https)")
ErrUnsupportedScheme is returned by New when the supplied base URL uses a scheme other than http or https.
Functions ¶
This section is empty.
Types ¶
type ContractError ¶
ContractError is returned when the control-plane responds with a non-2xx status. It exposes the envelope's error fields for diagnostics.
func (*ContractError) Error ¶
func (e *ContractError) Error() string
type Options ¶
type Options struct {
// BearerToken is sent in the Authorization header when non-empty.
BearerToken string
// Client overrides the default HTTP client. When nil, a client with a
// DefaultTimeout is used. A caller-supplied CheckRedirect is honored as-is
// and replaces the source's scheme/host redirect guard.
Client *stdhttp.Client
// PageLimit is sent as the ?limit= query parameter on each request.
// Servers may cap this. When 0 or negative, DefaultPageLimit is used.
PageLimit int
// AllowInsecureScheme opts in to accepting `http://` base URLs. By default
// New() rejects plaintext schemes so an operator-supplied bearer token is
// never transmitted in clear text. Set this to true only for LocalStack,
// dev loops, or internal-only tooling on private networks. It additionally
// permits redirects that downgrade to `http://`.
AllowInsecureScheme bool
// MaxResponseBytes caps how many bytes are read from a single page
// response before the read fails with ErrResponseTooLarge. When 0 or
// negative, DefaultMaxResponseBytes is used.
MaxResponseBytes int64
}
Options configures TenantSource.
type TenantSource ¶
type TenantSource struct {
// contains filtered or unexported fields
}
TenantSource implements migration.TenantLister against an HTTP control-plane API.
func New ¶
func New(baseURL string, opts Options) (*TenantSource, error)
New constructs a TenantSource. baseURL must be parseable; the /tenants path is appended automatically. Plaintext `http://` URLs are rejected unless opts.AllowInsecureScheme is true (defense-in-depth around the bearer token).
func (*TenantSource) ListTenants ¶
func (s *TenantSource) ListTenants(ctx context.Context) ([]string, error)
ListTenants walks all pages of the contract endpoint and returns the union of tenant IDs.