controld

package
v1.5.9 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	ReasonTokenInvalid      = "token_invalid"
	ReasonTokenExpired      = "token_expired"
	ReasonTokenLimitReached = "token_limit_reached"
	ReasonTokenDisabled     = "token_disabled"
)

Provisioning-token rejection reasons the API sends in error.metadata.reason (HTTP 400, code 40003). This list can grow; a value outside it is not an error, just one cmd/cli does not classify yet.

View Source
const (
	// SplitDNSModeOS resolves the domain through the endpoint's own OS/default
	// resolver, so it follows DHCP and VPN resolver changes.
	SplitDNSModeOS = "os"
	// SplitDNSModeResolvers resolves the domain through the addresses in
	// Resolvers first. When none of them answers, or they answer SERVFAIL or
	// NXDOMAIN, the query falls back to the resolvers of the endpoint's active
	// network and VPN. This is the default explicit selection.
	SplitDNSModeResolvers = "resolvers"
	// SplitDNSModeResolversOnly resolves the domain through the addresses in
	// Resolvers and nothing else: their answer, or their failure, is final.
	SplitDNSModeResolversOnly = "resolvers_only"
)

Internal Domain resolution modes. Mode is what the administrator selected; Resolvers is only meaningful under SplitDNSModeResolvers and SplitDNSModeResolversOnly.

View Source
const (
	InvalidConfigCode = 40402
)
View Source
const MaintenanceCode = 50302

MaintenanceCode is the error.code the API answers with in hard maintenance mode (Application::ERROR_HARD_MAINTENANCE), on HTTP 503, for every public API request including /utility and /logs.

The code decides. The message match in IsMaintenance stays as the compatibility path for deployments that answer without it.

Two neighbouring codes are deliberately not maintenance. 50301 is the generic "service unavailable" (a provisioning rate limit, Internal Domains or log storage down), a failure rather than a maintenance window. 50003 is read-only mode, which only gates authenticated controllers and so never answers /utility or /logs; its message ("Maintenance is in progress, cannot make any modifications.") does not match MaintenanceMessage either.

View Source
const MaintenanceMessage = "Maintenance is in progress."

MaintenanceMessage is what the API says while it is in hard maintenance. It classifies an answer that carries no MaintenanceCode. Matched as a substring because the answer carries guidance after it ("Please try again later.") that is not part of the condition itself.

Variables

This section is empty.

Functions

func DoWithFallbackForTest added in v1.5.6

func DoWithFallbackForTest(client *http.Client, req *http.Request, apiIp string) (*http.Response, error)

DoWithFallbackForTest exposes doWithFallback so tests outside this package can drive the real two-attempt composition through the real retry predicate, rather than asserting a copy of this error shape against another copy of it.

func IsMaintenance added in v1.5.9

func IsMaintenance(err error) bool

IsMaintenance reports whether err is the Control D API saying it is in maintenance, rather than refusing this particular request.

Maintenance is temporary and says nothing about the configuration that was asked for, so a caller must not treat it as a permanent rejection: the same request succeeds once the window ends. The HTTP status cannot classify it on its own, because a maintenance answer can arrive with a client-error status that otherwise means "this request will be refused again".

func ParseRawUID added in v1.3.0

func ParseRawUID(rawUID string) (string, string)

ParseRawUID parse the input raw UID, returning real UID and ClientID. The raw UID can have 2 forms:

- <uid> - <uid>/<client_id>

func ProbeReachability added in v1.5.8

func ProbeReachability(ctx context.Context, cdDev bool) error

ProbeReachability makes one lightweight request to the ControlD API host, reusing the same transport and IP-fallback logic real provisioning traffic takes. Any HTTP response, even an error status, counts as reachable: this checks the network path, not whether the endpoint accepts the request.

The caller controls how long to wait via ctx; there is no timeout here beyond what ctx enforces.

func SendLogs added in v1.4.0

func SendLogs(ctx context.Context, lr *LogsRequest, cdDev bool) error

SendLogs sends runtime log to ControlD API.

Types

type ErrorResponse added in v1.4.0

type ErrorResponse struct {
	ErrorField struct {
		Message  string        `json:"message"`
		Code     int           `json:"code"`
		Metadata errorMetadata `json:"metadata"`
	} `json:"error"`
	// StatusCode is the HTTP status the API answered with. It is not part of the JSON
	// body: this type is built for *any* non-200 whose body decodes, so the body alone
	// cannot tell a permanent rejection of the request from a transient server-side
	// failure, and callers that act differently on the two need the status to tell them
	// apart. Zero means the status was not recorded.
	StatusCode int `json:"-"`
}

func (ErrorResponse) Error added in v1.4.0

func (u ErrorResponse) Error() string

type LogsRequest added in v1.4.0

type LogsRequest struct {
	UID  string        `json:"uid"`
	Data io.ReadCloser `json:"-"`
}

LogsRequest contains request data for sending runtime logs to API.

type ResolverConfig

type ResolverConfig struct {
	DOH   string `json:"doh"`
	Ctrld struct {
		CustomConfig     string `json:"custom_config"`
		CustomLastUpdate int64  `json:"custom_last_update"`
		VersionTarget    string `json:"version_target"`
	} `json:"ctrld"`
	Exclude         []string   `json:"exclude"`
	SplitDNS        []SplitDNS `json:"split_dns"`
	UID             string     `json:"uid"`
	DeactivationPin *int64     `json:"deactivation_pin,omitempty"`
}

ResolverConfig represents Control D resolver data.

func FetchResolverConfig

func FetchResolverConfig(ctx context.Context, req *ResolverConfigRequest, cdDev bool) (*ResolverConfig, error)

FetchResolverConfig fetch Control D config for given uid.

func FetchResolverUID added in v1.3.0

func FetchResolverUID(ctx context.Context, req *UtilityOrgRequest, version string, cdDev bool) (*ResolverConfig, error)

FetchResolverUID fetch resolver uid from a given request.

func UpdateCustomLastFailed added in v1.3.8

func UpdateCustomLastFailed(ctx context.Context, rawUID, version string, cdDev, lastUpdatedFailed bool) (*ResolverConfig, error)

UpdateCustomLastFailed calls API to mark custom config is bad.

type ResolverConfigRequest added in v1.4.9

type ResolverConfigRequest struct {
	RawUID               string
	Version              string
	Metadata             map[string]string
	IncludeHostnameHints bool
}

ResolverConfigRequest contains request data for fetching resolver config.

type SplitDNS added in v1.5.8

type SplitDNS struct {
	Domain    string   `json:"domain"`
	Mode      string   `json:"mode"`
	Resolvers []string `json:"resolvers"`
}

SplitDNS is one organization Internal Domain: a domain suffix, the resolution mode the organization administrator selected for it, and the resolver addresses that mode may need.

Mode decides the routing. Resolvers is read only under the explicit modes, so addresses left behind by an earlier selection cannot resurrect themselves once the administrator switches back to the OS resolver. An empty Mode is a deployment that predates the field; the caller infers the mode from Resolvers in that case.

type UtilityOrgRequest added in v1.3.10

type UtilityOrgRequest struct {
	ProvToken string            `json:"prov_token"`
	Hostname  string            `json:"hostname"`
	Metadata  map[string]string `json:"metadata"`
}

UtilityOrgRequest contains request data for calling Org API.

Jump to

Keyboard shortcuts

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