Documentation
¶
Overview ¶
Package api contains representation types for Relay's REST endpoints which may be referenced from multiple packages.
Index ¶
Constants ¶
const ExpectParam = "expect"
ExpectParam is the query parameter that carries the assertion clauses.
Variables ¶
This section is empty.
Functions ¶
func ParseExpectQuery ¶
ParseExpectQuery reads the "expect" clauses out of a raw URL query string. requested reports whether the caller used the parameter at all; malformed reports whether the query string could be parsed.
This does not go through Request.URL.Query(), which discards the parse error from url.ParseQuery and drops only the offending segment. A clause the relay cannot decode would then look identical to no clause at all, and the handler would answer 200 with the full status document for an assertion it never evaluated. Go rejects a segment holding a raw ";" or a bad "%" escape, and hand-encoding is exactly what the bracket-quoted environment keys ask callers to do, so this is reachable from a single-character typo. A verdict endpoint has to fail closed, so the error is surfaced to the caller instead.
Types ¶
type BigSegmentStatusRep ¶
type BigSegmentStatusRep struct {
Available bool `json:"available"`
PotentiallyStale bool `json:"potentiallyStale"`
LastSynchronizedOn ldtime.UnixMillisecondTime `json:"lastSynchronizedOn"`
}
BigSegmentStatusRep is the big segment status representation returned by the status endpoint.
This is exported for use in integration test code.
type ConnectionErrorRep ¶
type ConnectionErrorRep struct {
Kind interfaces.DataSourceErrorKind `json:"kind"`
Time ldtime.UnixMillisecondTime `json:"time"`
}
ConnectionErrorRep is the optional error information in ConnectionStatusRep.
This is exported for use in integration test code.
type ConnectionStatusRep ¶
type ConnectionStatusRep struct {
State interfaces.DataSourceState `json:"state"`
StateSince ldtime.UnixMillisecondTime `json:"stateSince"`
LastError *ConnectionErrorRep `json:"lastError,omitempty"`
}
ConnectionStatusRep is the data source status representation returned by the status endpoint.
This is exported for use in integration test code.
type DataStoreStatusRep ¶
type DataStoreStatusRep struct {
State string `json:"state"`
StateSince ldtime.UnixMillisecondTime `json:"stateSince"`
Database string `json:"database,omitempty"`
DBServer string `json:"dbServer,omitempty"`
DBPrefix string `json:"dbPrefix,omitempty"`
DBTable string `json:"dbTable,omitempty"`
}
DataStoreStatusRep is the data store status representation returned by the status endpoint.
This is exported for use in integration test code.
type EnvironmentStatusRep ¶
type EnvironmentStatusRep struct {
SDKKey string `json:"sdkKey"`
EnvID string `json:"envId,omitempty"`
EnvKey string `json:"envKey,omitempty"`
EnvName string `json:"envName,omitempty"`
ProjKey string `json:"projKey,omitempty"`
ProjName string `json:"projName,omitempty"`
MobileKey string `json:"mobileKey,omitempty"`
ExpiringSDKKey string `json:"expiringSdkKey,omitempty"`
Status string `json:"status"`
ConnectionStatus ConnectionStatusRep `json:"connectionStatus"`
DataStoreStatus DataStoreStatusRep `json:"dataStoreStatus"`
BigSegmentStatus *BigSegmentStatusRep `json:"bigSegmentStatus,omitempty"`
}
EnvironmentStatusRep is the per-environment JSON representation returned by the status endpoint.
This is exported for use in integration test code.
type ExpectationResult ¶
type ExpectationResult struct {
// Expr is the original clause as supplied by the caller.
Expr string `json:"expr"`
// Expected is the value the clause asserted. It is omitted for a clause that was not evaluated.
Expected string `json:"expected,omitempty"`
// Actual is the value found at the clause's path, rendered as a string. It is omitted for a
// clause that was not evaluated, and empty when the path is absent from the body.
Actual string `json:"actual,omitempty"`
// Problem describes why the clause could not be evaluated. It is empty for a clause that was.
Problem string `json:"problem,omitempty"`
// OK reports whether the clause held. It is false for a clause that was not evaluated.
OK bool `json:"ok"`
}
ExpectationResult is the outcome of evaluating a single "expect" clause.
type ExpectationsResult ¶
type ExpectationsResult struct {
// Satisfied reports whether every clause was evaluated and held.
Satisfied bool `json:"satisfied"`
// Results contains one entry per clause, in the order supplied.
Results []ExpectationResult `json:"results,omitempty"`
// Error describes why the whole query was abandoned, as opposed to a problem with one clause.
Error string `json:"error,omitempty"`
}
ExpectationsResult is the body returned when a status request includes "expect" clauses.
func EvaluateExpectations ¶
func EvaluateExpectations(body []byte, clauses []string, schema StatusSchema) (ExpectationsResult, int)
EvaluateExpectations evaluates the "expect" clauses against a marshaled status body and returns the per-clause results together with the HTTP status code the handler should write. Every clause is evaluated, so one request reports every problem the caller needs to fix; the response code is the most serious outcome across all of them:
- http.StatusBadRequest (400) when any clause does not parse.
- http.StatusUnprocessableEntity (422) when any clause parses but names an operator or a field that cannot be evaluated against the schema.
- http.StatusPreconditionFailed (412) when every clause is evaluable but at least one does not hold. A clause whose path is absent from the body is treated as unsatisfied: if the field the caller asserted about is not even present, the relay is not in the state they assumed.
- http.StatusOK (200) when every clause holds.
body is the JSON the handler would otherwise have written, so a clause path matches exactly what the caller sees in the response. schema says which document that is.
type StatusRep ¶
type StatusRep struct {
Environments map[string]EnvironmentStatusRep `json:"environments"`
Status string `json:"status"`
Version string `json:"version"`
ClientVersion string `json:"clientVersion"`
}
StatusRep is the JSON representation returned by the status endpoint.
This is exported for use in integration test code.
type StatusSchema ¶
type StatusSchema int
StatusSchema identifies which status document a set of clauses is evaluated against. Paths are relative to the body of the route that serves them, so the two routes validate against different roots.
const ( // SchemaAllEnvironments is the body of the /status route: a StatusRep. SchemaAllEnvironments StatusSchema = iota // SchemaSingleEnvironment is the body of the per-environment status routes: a bare // EnvironmentStatusRep, with no "environments" wrapper. SchemaSingleEnvironment )