Skip to main content

parse_connection_details

Function parse_connection_details 

Source
fn parse_connection_details<'a>(a: &'a str) -> Result<Jsonb, EvalError>
Expand description

Extracts connection-detail metadata from a catalog create_sql.

Returns a per-connection-type object with the fields that the mz_kafka_connections, mz_ssh_tunnel_connections, and mz_aws_connections builtin views need. For everything else (other connection types, including aws-privatelink whose only detail is context-derived, and non-connection statements) it returns jsonb null, so callers filter on IS NOT NULL and gate on the connection type separately (via parse_catalog_create_sql(...)->>'connection_type', the way mz_connections already does).

The shape per type:

// kafka
{ "brokers": ["host:port", ...], "progress_topic": <text | null> }
// ssh-tunnel
{ "public_key_1": "<text>", "public_key_2": "<text>" }
// aws
{
  "auth_kind": "credentials" | "assume-role",
  "endpoint": <text | null>, "region": <text | null>,
  "access_key_id": <text | null>, "access_key_id_secret_id": <text | null>,
  "secret_access_key_secret_id": <text | null>,
  "session_token": <text | null>, "session_token_secret_id": <text | null>,
  "assume_role_arn": <text | null>, "assume_role_session_name": <text | null>
}

progress_topic is null when the connection does not set an explicit PROGRESS TOPIC. The default (_materialize-progress-<env>-<conn_id>) is reconstructed by the view, not here, because it needs the environment id and the connection’s own id. Values derived only from environment context (AWS principal, external id, trust policy, privatelink principal) are also left to the view. This keeps the helper a pure function of the create_sql.

For aws, an option is either an inline value or a secret reference. Inline values land in access_key_id/session_token; a secret reference lands in the matching *_secret_id as the referenced secret’s catalog item id (the persisted create_sql stores resolved references as [uNNN AS name]). auth_kind is assume-role when ASSUME ROLE ARN is present, else credentials, matching the AwsAuth variant the removed packer read.

Errors if the statement fails to parse.