#[non_exhaustive]pub struct AppConfig {Show 43 fields
pub db_uri: String,
pub db_schemas: Vec<String>,
pub db_anon_role: Option<String>,
pub db_pool_size: u32,
pub db_pool_timeout: u64,
pub db_tx_isolation: IsolationLevel,
pub db_prepared_statements: bool,
pub db_extra_search_path: Vec<String>,
pub db_channel: String,
pub db_channel_enabled: bool,
pub db_pre_request: Option<String>,
pub db_max_rows: Option<i64>,
pub db_aggregates_enabled: bool,
pub server_host: String,
pub server_port: u16,
pub server_cors_origins: Vec<String>,
pub max_body_size: usize,
pub server_unix_socket: Option<String>,
pub admin_server_port: Option<u16>,
pub jwt_secret: Option<String>,
pub jwt_secret_is_base64: bool,
pub jwt_aud: Option<String>,
pub jwt_iss: Option<String>,
pub jwt_role_claim_key: String,
pub jwt_cache_enabled: bool,
pub jwt_cache_max_lifetime: u64,
pub jwt_jwks_url: Option<String>,
pub jwt_jwks_refresh: u64,
pub hasura_admin_secret: Option<String>,
pub hasura_unauthorized_role: Option<String>,
pub openapi_server_proxy_uri: Option<String>,
pub openapi_mode: OpenApiMode,
pub log_level: LogLevel,
pub log_format: LogFormat,
pub otel_db_statement: bool,
pub role_settings: HashMap<String, RoleSettings>,
pub app_settings: HashMap<String, String>,
pub graphql_federation: bool,
pub graphql_type_prefix: Option<String>,
pub compat_mode: bool,
pub db_errors_verbatim: Vec<String>,
pub db_error_status: BTreeMap<String, u16>,
pub rpc_unwrap: bool,
}Expand description
Main application configuration.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.db_uri: StringPostgreSQL connection URI
db_schemas: Vec<String>Schemas to expose via the API
db_anon_role: Option<String>Role for unauthenticated requests
db_pool_size: u32Connection pool size
db_pool_timeout: u64Pool acquisition timeout in seconds
db_tx_isolation: IsolationLevelIsolation level for the transaction every request runs in.
READ COMMITTED unless set, which is PostgreSQL’s own default; a
stricter level is issued as SET TRANSACTION ISOLATION LEVEL on the
request’s transaction.
db_prepared_statements: boolUse prepared statements
db_extra_search_path: Vec<String>Schemas added to the search_path of every request, after the
request’s own schema.
These are not exposed as API endpoints; they are where a function an
exposed one calls, or a type it references, is allowed to live. An
aggregate returning a domain declared elsewhere cannot resolve that
domain without this. public by default, as in PostgREST.
db_channel: StringLISTEN/NOTIFY channel for schema reload
db_channel_enabled: boolEnable NOTIFY-based schema cache reload
db_pre_request: Option<String>Function called on the request’s transaction before its own query, after every setting is applied. Anything it raises aborts the request.
db_max_rows: Option<i64>Maximum rows allowed in a response
db_aggregates_enabled: boolEnable aggregate functions in select.
Off by default, as in PostgREST: an aggregate over a large table costs far more than the request looks like it asks for.
server_host: StringServer host to bind
server_port: u16Server port
server_cors_origins: Vec<String>Origins allowed by CORS.
Empty means every origin is allowed, which is the default and what
PGRST_SERVER_CORS_ORIGINS="*" selects explicitly. A non-empty list
restricts the Access-Control-Allow-Origin response to exactly those
origins; anything else gets no CORS headers and is refused by the
browser.
max_body_size: usizeMaximum accepted request body, in bytes.
The REST handler applies this when it reads the body; the routes that
take a body extractor get it through axum’s DefaultBodyLimit. Before
this was read, the limit in force was a 10 MiB constant in the request
handler, whatever the variable said.
server_unix_socket: Option<String>Listen on a Unix domain socket instead of host and port.
admin_server_port: Option<u16>Serve liveness and readiness on a second port of their own.
jwt_secret: Option<String>JWT secret: an HMAC secret, or a JSON Web Key or JWK Set.
jwt_secret_is_base64: boolJWT secret as base64
jwt_aud: Option<String>JWT audience claim to validate
jwt_iss: Option<String>The issuer a token’s iss claim must name (PGRST_JWT_ISS). Unset,
iss is not checked.
jwt_role_claim_key: StringJWT claim that contains the role
jwt_cache_enabled: boolCache validated tokens, so a repeated token is not verified again.
jwt_cache_max_lifetime: u64How long a cached validation may be reused, in seconds.
A token’s own exp bounds this; the cache never answers with a token
past its expiry. 0 turns the cache off, as in PostgREST.
jwt_jwks_url: Option<String>Where to fetch a JSON Web Key Set from (PGRST_JWT_JWKS_URL), and
keep fetching it as the identity provider rotates its keys.
https, or http to a loopback host; checked when the server is
built. With jwt_secret also set, a token either one verifies is
accepted. See docs/authentication.md.
jwt_jwks_refresh: u64How often to fetch jwt_jwks_url again, in seconds, when its response
carries no Cache-Control: max-age (PGRST_JWT_JWKS_REFRESH).
hasura_admin_secret: Option<String>The shared secret that authenticates an administrator, and the switch
that makes x-hasura-* headers mean anything at all.
Unset, this server ignores those headers and reads session variables
only from a verified token – because honouring a header nothing
authenticated would let any caller name its own identity, and a policy
reading a value the caller chose is not a policy. Hasura instead treats
an unsecured deployment as wholly administrative; the divergence is
deliberate and is recorded in postrust_auth::hasura.
The role a request falls to when nothing authenticated it. Hasura’s
HASURA_GRAPHQL_UNAUTHORIZED_ROLE; unset means such a request is
refused rather than answered as a stranger.
openapi_server_proxy_uri: Option<String>Address to advertise in the specification’s servers, for when the
server sits behind a reverse proxy and its own address is not the one
clients use.
openapi_mode: OpenApiModeOpenAPI mode: disabled, follow-privileges, ignore-privileges
log_level: LogLevelLog level: crit, error, warn, info, debug
log_format: LogFormatHow log lines are written: text for a person at a terminal, json
for a log shipper. JSON lines carry the fields of every span the event
happened in, so each one names its request_id and trace_id.
Like log_level, the binaries read the variable themselves before the
configuration is loaded – the subscriber has to exist first to report
what loading it rejects – and this field is that same value, kept for
anything that reads the configuration afterwards.
otel_db_statement: boolRecord the SQL of a request’s main query on its db.query span, as
OpenTelemetry’s db.query.text.
Off by default. The statement is parameterized, so the values a client sent are not in it – but the table, column and function names are, and whatever collects traces may be read by more people than the schema is meant for. Formatting it costs nothing while it is off.
role_settings: HashMap<String, RoleSettings>Per-role settings (isolation level, timeout)
app_settings: HashMap<String, String>App-level settings to expose via GUC
graphql_federation: boolExpose the GraphQL API as an Apollo Federation subgraph.
graphql_type_prefix: Option<String>Namespace applied to generated GraphQL table types and root fields.
compat_mode: boolPostgREST compatibility mode.
When enabled, the REST surface is also served at the root (so canonical
PostgREST paths like /rpc/<name> and /<table> work in addition to
the /api-prefixed paths), and RPC responses are un-wrapped to match
PostgREST’s shape (bare object/scalar for non-set-returning functions,
a top-level array for set-returning ones) instead of the array-wrapped,
function-name-keyed default.
db_errors_verbatim: Vec<String>The SQLSTATEs whose database errors are answered in the database’s own
words – its code, message, detail and hint – rather than as
"Database error".
Each entry is a five-character SQLSTATE (P0001) or a prefix ending in
* (PT*); * alone is every one. Empty by default, because most of
what PostgreSQL says describes the schema rather than the request: a
constraint’s name, a missing table. What a function raises on purpose
for the person using the app is the exception worth listing.
Compatibility mode passes every database error through regardless.
db_error_status: BTreeMap<String, u16>The HTTP status a database error is answered with, by SQLSTATE.
Each key is a SQLSTATE (P0002) or a prefix ending in * (23*),
spelt as in db_errors_verbatim, and each
value a status from 400 to 599. The most specific key that matches
wins: a whole SQLSTATE over any prefix, a longer prefix over a shorter
one. Empty by default, which leaves the built-in table in charge –
PostgREST’s, except that outside compatibility mode P0002
(no_data_found) is a 404 rather than a 500. An entry here wins over
that in both modes, so P0002:500 puts PostgREST’s answer back.
What a function raises with sqlstate 'PGRST' or PT<nnn> is a
request for a status from the schema itself, and is never overridden.
rpc_unwrap: boolAnswer POST /rpc/<fn> the way PostgREST does – a bare object or
scalar for a function that returns one row, a top-level array for a set
– instead of the default [{"<fn>": ...}], without the rest of
compatibility mode. Off by default. Compatibility mode implies it; ask
unwrap_rpc_results rather than this field.
Implementations§
Source§impl AppConfig
impl AppConfig
Sourcepub fn from_env() -> Self
pub fn from_env() -> Self
Load configuration from environment variables.
§Panics
Panics if a boolean environment variable has an unsupported value. Use
Self::try_from_env when the caller can propagate a startup error.
Sourcepub fn try_from_env() -> Result<Self, ConfigError>
pub fn try_from_env() -> Result<Self, ConfigError>
Load configuration from environment variables, rejecting invalid boolean values.
Sourcepub fn try_from_vars<I, K, V>(vars: I) -> Result<Self, ConfigError>
pub fn try_from_vars<I, K, V>(vars: I) -> Result<Self, ConfigError>
Load configuration from name/value pairs spelled as the environment variables are, for a host with no process environment – a Cloudflare Worker reads its bindings instead. Where a name appears twice, the last one wins. Names are matched exactly, case included.
Sourcepub fn is_authenticated_role(&self, role: &str) -> bool
pub fn is_authenticated_role(&self, role: &str) -> bool
Whether a request that runs as role counts as authenticated, which
decides whether a missing grant is answered 403 rather than 401.
As PostgREST decides it: the role differs from the configured anonymous role, so with no anonymous role configured every role does.
Sourcepub fn verbatim_db_error(&self, error: &Error) -> bool
pub fn verbatim_db_error(&self, error: &Error) -> bool
Whether error is answered in the database’s own words: a database
error, in compatibility mode or with a SQLSTATE
db_errors_verbatim lists.
Sourcepub fn db_error_status(&self, error: &DatabaseError) -> Option<StatusCode>
pub fn db_error_status(&self, error: &DatabaseError) -> Option<StatusCode>
The status this configuration gives a database error, where it has an
opinion; None leaves the built-in table
(DatabaseError::status_code_as)
to decide.
An error the schema chose the status of – RAISE sqlstate 'PGRST' or
PT<nnn> – is never remapped: a function that asked for a 402 meant it.
Otherwise the most specific entry of
db_error_status wins, a whole SQLSTATE over
any prefix and a longer prefix over a shorter. With none, P0002
(no_data_found) is a 404 outside compatibility mode, where a function
that found nothing is reporting a missing thing, and stays PostgREST’s
500 inside it.
Sourcepub fn any_verbatim_db_errors(&self) -> bool
pub fn any_verbatim_db_errors(&self) -> bool
Whether any database error can be answered in its own words, which is what decides if a custom route’s errors need rendering again.
Sourcepub fn unwrap_rpc_results(&self) -> bool
pub fn unwrap_rpc_results(&self) -> bool
Whether RPC responses are un-nested PostgREST-style: in compatibility
mode, or with rpc_unwrap on its own.
Sourcepub fn default_schema(&self) -> &str
pub fn default_schema(&self) -> &str
Get the default schema (first in the list).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for AppConfig
impl<'de> Deserialize<'de> for AppConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Forget for AppConfig
impl Freeze for AppConfig
impl Move for AppConfig
impl RefUnwindSafe for AppConfig
impl Send for AppConfig
impl Sync for AppConfig
impl Unpin for AppConfig
impl UnsafeUnpin for AppConfig
impl UnwindSafe for AppConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more