Documentation
¶
Overview ¶
Package api implements a minimal HTTP client for the Dymmer hosting API.
Index ¶
- Constants
- type APIError
- type AuthStatus
- type Client
- func (c *Client) CreateRecord(ctx context.Context, domain string, input RecordInput) (*Record, error)
- func (c *Client) CreateWebURI(ctx context.Context, zone, server string, fields map[string]string, ...) (*WebResult, error)
- func (c *Client) DeleteRecord(ctx context.Context, domain, id string) (*Record, error)
- func (c *Client) DeleteWebURI(ctx context.Context, zone, server, id string, dryRun bool) (*WebResult, error)
- func (c *Client) GetAuthStatus(ctx context.Context) (*AuthStatus, error)
- func (c *Client) GetSecrets(ctx context.Context, project, env, deployment, format string) (*SecretsResult, error)
- func (c *Client) GetWebOptions(ctx context.Context, zone, server, host string) (*WebOptions, error)
- func (c *Client) ListForwardings(ctx context.Context, domain string) ([]Forwarding, error)
- func (c *Client) ListMailboxes(ctx context.Context, domain string) ([]Mailbox, error)
- func (c *Client) ListRecords(ctx context.Context, domain, recordType string) ([]Record, error)
- func (c *Client) ListWebServers(ctx context.Context) ([]WebServer, error)
- func (c *Client) ListWebSites(ctx context.Context, zone, server, host string) ([]WebSite, error)
- func (c *Client) RestoreWebURI(ctx context.Context, zone, server, id string) (*WebResult, error)
- func (c *Client) SetWebOptions(ctx context.Context, zone, server, host string, options map[string]any, ...) (*WebOptions, error)
- func (c *Client) UpdateRecord(ctx context.Context, domain, id string, input RecordInput) (*Record, error)
- func (c *Client) UpdateWebURI(ctx context.Context, zone, server, id string, fields map[string]string, ...) (*WebResult, error)
- type Forwarding
- type Mailbox
- type Record
- type RecordInput
- type SecretEntry
- type SecretsResult
- type WebOptions
- type WebResult
- type WebServer
- type WebSite
- type WebURI
Constants ¶
const AnyServer = "-"
AnyServer, as the web server of a call, lets the API choose the only one the zone can use.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
APIError represents a non-2xx response from the Dymmer API. Its Error() message never includes request headers or the auth token: it is built exclusively from the response status code and (when parseable) the response body's reason/error fields.
type AuthStatus ¶ added in v0.6.0
type AuthStatus struct {
Unrestricted bool `json:"unrestricted"`
Scopes []string `json:"scopes"`
Constraints map[string]string `json:"constraints"`
}
AuthStatus describes what the current token is allowed to do (backlog dymmer#263): Unrestricted is true for a legacy full-access token or one explicitly granted the "*" scope; Scopes and Constraints are only meaningful when Unrestricted is false.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a thin HTTP client for the Dymmer API. baseURL must already include any API path prefix (e.g. "https://dymmer.com/api/v1"); Client never adds one of its own, it only appends resource paths.
func NewClient ¶
NewClient builds a Client that authenticates every request with "Authorization: Bearer <token>".
func (*Client) CreateRecord ¶
func (c *Client) CreateRecord(ctx context.Context, domain string, input RecordInput) (*Record, error)
CreateRecord creates a new record on domain.
func (*Client) CreateWebURI ¶ added in v0.7.0
func (c *Client) CreateWebURI(ctx context.Context, zone, server string, fields map[string]string, dryRun bool) (*WebResult, error)
CreateWebURI adds a URI. fields holds only what was set: host, uri, type, target, tls.
func (*Client) DeleteRecord ¶
DeleteRecord removes the record identified by id on domain and returns the record as it existed just before deletion.
func (*Client) DeleteWebURI ¶ added in v0.7.0
func (c *Client) DeleteWebURI(ctx context.Context, zone, server, id string, dryRun bool) (*WebResult, error)
DeleteWebURI removes a URI (the server keeps it for a while, so it can be restored).
func (*Client) GetAuthStatus ¶ added in v0.6.0
func (c *Client) GetAuthStatus(ctx context.Context) (*AuthStatus, error)
GetAuthStatus asks the server what the current token's own scopes and resource constraints are (GET /auth/status). Any authenticated token can call this, regardless of its own scopes.
func (*Client) GetSecrets ¶
func (c *Client) GetSecrets(ctx context.Context, project, env, deployment, format string) (*SecretsResult, error)
GetSecrets fetches secrets for project (required), env, and optionally deployment (omitted from the request entirely when empty).
format must be the *wire* value the Dymmer server understands, not a CLI-facing name: pass "" or "json" for JSON output, and the literal string ".env" for dotenv output. The server only recognizes the exact string ".env" to mean dotenv; any other value (including the strings "json" or "dotenv") falls back to JSON. Callers translating a user-facing --format flag (e.g. "dotenv") must map it to ".env" themselves before calling GetSecrets — this package does not do that translation, to keep the CLI/server format-name mismatch visible at the call site instead of hidden here.
func (*Client) GetWebOptions ¶ added in v0.8.0
GetWebOptions reads the options of a name.
func (*Client) ListForwardings ¶
ListForwardings fetches the mail forwardings configured for domain.
func (*Client) ListMailboxes ¶
ListMailboxes fetches the mailboxes configured for domain.
func (*Client) ListRecords ¶
ListRecords fetches the records for domain, optionally filtered by exact record type match (e.g. "A"). An empty recordType omits the filter.
func (*Client) ListWebServers ¶ added in v0.7.0
ListWebServers lists the web servers the user can use.
func (*Client) ListWebSites ¶ added in v0.7.0
ListWebSites lists the names of zone served by server with their URIs; host limits it to one name.
func (*Client) RestoreWebURI ¶ added in v0.7.0
RestoreWebURI brings back a removed URI, if nobody took its place meanwhile.
func (*Client) SetWebOptions ¶ added in v0.8.0
func (c *Client) SetWebOptions(ctx context.Context, zone, server, host string, options map[string]any, dryRun bool) (*WebOptions, error)
SetWebOptions changes the options of a name: a key with a nil value takes the option away, the keys not given stay.
func (*Client) UpdateRecord ¶
func (c *Client) UpdateRecord(ctx context.Context, domain, id string, input RecordInput) (*Record, error)
UpdateRecord replaces the record identified by id on domain.
type Forwarding ¶
type Forwarding struct {
Username string `json:"username"`
Destination []string `json:"destination"`
Enabled bool `json:"enabled"`
}
Forwarding is a single mail forwarding rule as returned by the Dymmer API. Destination can fan out to multiple addresses.
type Mailbox ¶
Mailbox is a single mailbox as returned by the Dymmer API. The API no longer exposes password hashes here; mail servers read credentials from /zones/<domain>/identities (scope identity:read).
type Record ¶
type Record struct {
ID string `json:"id"`
Type string `json:"type"`
Host string `json:"host"`
TimeToLive int `json:"time_to_live"`
Content map[string]string `json:"content"`
}
Record is a single DNS record as returned by the Dymmer API. Content holds the record's type-specific fields (e.g. "ip" for an A record, "value" for a TXT record) as returned by the server, keyed without the "content_" prefix used on the wire for writes.
type RecordInput ¶
RecordInput describes the fields a caller wants to set when creating or updating a record. Content keys are the bare field names (e.g. "ip", "value", "priority") — CreateRecord/UpdateRecord serialize each one as a top-level "content_<key>" field on the request body, so this package never needs to know which record types accept which fields; that mapping lives in the CLI command layer.
Host and TTL are optional: an empty Host is omitted from the request (the server defaults it to "@"), and a nil TTL is omitted (the server defaults it to 3600). Type is always sent, even on updates where it is unchanged, since the server uses it to select content validation.
type SecretEntry ¶
type SecretEntry struct {
Key string `json:"key"`
Value string `json:"value"`
Comments string `json:"comments"`
Removed bool `json:"removed"`
}
SecretEntry is a single secret as returned by the Dymmer API's JSON secrets format.
type SecretsResult ¶
type SecretsResult struct {
Raw string
Entries []SecretEntry
}
SecretsResult holds the outcome of GetSecrets. Exactly one of Raw or Entries is populated, depending on which format was requested: Raw holds the verbatim dotenv text when format was ".env"; Entries holds the decoded array for JSON mode.
type WebOptions ¶ added in v0.8.0
type WebOptions struct {
Status string `json:"status"`
Host string `json:"host"`
Options map[string]any `json:"options"`
DryRun bool `json:"dry_run"`
}
WebOptions are the options of a whole name (not of one URI): hsts, blog_fallback, index_fallback (booleans) and asset_extensions (a string like "jpg|css"). DryRun is true when it was only a check.
type WebResult ¶ added in v0.7.0
type WebResult struct {
Status string `json:"status"`
URI WebURI `json:"uri"`
Warnings []string `json:"warnings"`
DryRun bool `json:"dry_run"`
}
WebResult is the answer to adding, changing, removing or restoring a URI: the URI, the warnings (a name whose DNS does not lead to the web server yet) and whether it was only a check (DryRun).
type WebServer ¶ added in v0.7.0
type WebServer struct {
ID string `json:"id"`
Name string `json:"name"`
Hostname string `json:"hostname"`
Maintenance bool `json:"maintenance"`
}
WebServer is a web server the user can use.
type WebURI ¶ added in v0.7.0
type WebURI struct {
ID string `json:"id"`
URI string `json:"uri"`
Type string `json:"type"`
Target string `json:"target"`
TLS string `json:"tls"`
// RedirectStatus is the code of a redirect (301, 302, 307 or 308); 0 for the other types.
RedirectStatus int `json:"redirect_status"`
State string `json:"state"`
ErrorReason string `json:"error_reason"`
AppliedAt string `json:"applied_at"`
ErroredAt string `json:"errored_at"`
UpdatedAt string `json:"updated_at"`
}
WebURI is one URI of a name and where it stands for its web server: State is "pending" (the server has not applied this version yet), "applied" or "errored", and ErrorReason says why the server refused it.