Documentation
¶
Overview ¶
Package api implements a minimal HTTP client for the Dymmer hosting API.
Index ¶
- Constants
- type APIError
- type AttachInput
- type AuthStatus
- type Client
- func (c *Client) AllowSendAs(ctx context.Context, zone, id, credentialID string) (*Identity, error)
- func (c *Client) AttachStorage(ctx context.Context, zone, id string, input AttachInput) (*Identity, error)
- func (c *Client) CreateIdentity(ctx context.Context, zone string, input IdentityInput) (*Identity, error)
- 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) DeleteIdentity(ctx context.Context, zone, id string) error
- func (c *Client) DeleteRecord(ctx context.Context, domain, id string) (*Record, error)
- func (c *Client) DeleteStorage(ctx context.Context, zone, id string) 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) ListDeployments(ctx context.Context, project, env, deployment string) ([]Deployment, error)
- func (c *Client) ListIdentities(ctx context.Context, zone string) ([]Identity, error)
- func (c *Client) ListRecords(ctx context.Context, domain, recordType string) ([]Record, error)
- func (c *Client) ListStorages(ctx context.Context, zone string) ([]Storage, error)
- func (c *Client) ListWebBuckets(ctx context.Context) ([]WebBucket, 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) RevokeSendAs(ctx context.Context, zone, id, credentialID string) (*Identity, error)
- func (c *Client) SetWebOptions(ctx context.Context, zone, server, host string, options map[string]any, ...) (*WebOptions, error)
- func (c *Client) UpdateIdentity(ctx context.Context, zone, id string, input IdentityInput) (*Identity, 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 Deployment
- type DeploymentHost
- type Identity
- type IdentityForwarding
- type IdentityInput
- type IdentityMailbox
- type Receive
- type Record
- type RecordInput
- type SecretEntry
- type SecretsResult
- type Storage
- type WebBucket
- 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 AttachInput ¶ added in v0.19.0
AttachInput says who takes a deleted mailbox back: a new identity (Username, with Password) or, for administrators, an existing one (IdentityID).
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) AllowSendAs ¶ added in v0.19.0
AllowSendAs lets the identity credentialID send as the identity id, and returns the latter.
func (*Client) AttachStorage ¶ added in v0.19.0
func (c *Client) AttachStorage(ctx context.Context, zone, id string, input AttachInput) (*Identity, error)
AttachStorage gives the deleted mailbox id to an identity, with its mail, and returns the identity.
func (*Client) CreateIdentity ¶ added in v0.19.0
func (c *Client) CreateIdentity(ctx context.Context, zone string, input IdentityInput) (*Identity, error)
CreateIdentity creates an identity on zone.
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) DeleteIdentity ¶ added in v0.19.0
DeleteIdentity deletes the identity id for good; the storage of its mailbox, if it has one, is kept for a while.
func (*Client) DeleteRecord ¶
DeleteRecord removes the record identified by id on domain and returns the record as it existed just before deletion.
func (*Client) DeleteStorage ¶ added in v0.19.0
DeleteStorage deletes the mail of a deleted mailbox now, for good, and frees its place.
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) ListDeployments ¶ added in v0.15.0
func (*Client) ListIdentities ¶ added in v0.19.0
ListIdentities fetches the identities of zone.
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) ListStorages ¶ added in v0.19.0
ListStorages fetches the deleted mailboxes of zone that can still be taken back.
func (*Client) ListWebBuckets ¶ added in v0.11.0
ListWebBuckets lists the buckets of the user.
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) RevokeSendAs ¶ added in v0.19.0
func (c *Client) RevokeSendAs(ctx context.Context, zone, id, credentialID string) (*Identity, error)
RevokeSendAs stops the identity credentialID from sending as the identity id, and returns the latter.
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) UpdateIdentity ¶ added in v0.19.0
func (c *Client) UpdateIdentity(ctx context.Context, zone, id string, input IdentityInput) (*Identity, error)
UpdateIdentity changes what input names of the identity id.
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 Deployment ¶ added in v0.15.0
type Deployment struct {
ID string `json:"id"`
Name string `json:"name"`
AppType string `json:"app_type"`
Hosts []DeploymentHost `json:"hosts"`
}
Deployment keeps shared app metadata separate from each host's configuration.
type DeploymentHost ¶ added in v0.15.0
type DeploymentHost struct {
ID string `json:"id"`
HostID string `json:"host_id"`
Name string `json:"name"`
Status string `json:"status"`
Ports []int `json:"ports"`
WorkingPath string `json:"working_path"`
ExecPath string `json:"exec_path"`
CommandType string `json:"command_type"`
ServiceParam string `json:"service_param"`
Operations []string `json:"operations"`
}
type Identity ¶ added in v0.19.0
type Identity struct {
ID string `json:"id"`
Username string `json:"username"`
Enabled bool `json:"enabled"`
HasPassword bool `json:"has_password"`
Mailbox *IdentityMailbox `json:"mailbox"`
Forwarding *IdentityForwarding `json:"forwarding"`
Authorizations []string `json:"authorizations"`
}
Identity is a mail address of a zone with what it can do: send with a password, receive in a mailbox or forward, and the addresses that send as it. The API also returns the hash of the password, for mail servers; it is never kept here: only whether there is one.
func (*Identity) UnmarshalJSON ¶ added in v0.19.0
UnmarshalJSON reads an identity as the API sends it, dropping the password hash.
type IdentityForwarding ¶ added in v0.19.0
type IdentityForwarding struct {
Destination []string `json:"destination"`
}
IdentityForwarding is the forwarding of an identity.
type IdentityInput ¶ added in v0.19.0
type IdentityInput struct {
Username *string
Enabled *bool
Password *string
RemovePassword bool
Receive *Receive
UpdateDestinations bool
}
IdentityInput is what a caller wants to set when creating or changing an identity. Nil and empty fields are not sent, so that a change only touches what it names. RemovePassword stops the identity from sending by itself.
type IdentityMailbox ¶ added in v0.19.0
type IdentityMailbox struct {
QuotaTier string `json:"quota_tier"`
QuotaUsedMB int `json:"quota_used_mb"`
StorageKey string `json:"storage_key"`
}
IdentityMailbox is the mailbox of an identity.
type Receive ¶ added in v0.19.0
Receive says how an identity receives mail: Type is "mailbox", "forwarding" or "none". StorageID (a deleted mailbox to take back) only goes with "mailbox", and Destination with "forwarding".
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 Storage ¶ added in v0.19.0
type Storage struct {
ID string `json:"id"`
Name string `json:"name"`
AbandonedAt string `json:"abandoned_at"`
PurgeAfter string `json:"purge_after"`
DaysLeft int `json:"days_left"`
UsageBytes *int64 `json:"usage_bytes"`
}
Storage is a mailbox that nobody owns now, kept for a while so that it can be taken back.
type WebBucket ¶ added in v0.11.0
type WebBucket struct {
Name string `json:"name"`
}
WebBucket is a Garage bucket that belongs to the user: a static URI can only point to one of these.
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.