MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / parse_l7_config

Function parse_l7_config

crates/openshell-supervisor-network/src/l7/mod.rs:164–267  ·  view source on GitHub ↗

Parse an L7 endpoint config from a regorus Value (returned by Rego query). The value is expected to be the raw endpoint object from the Rego data, containing fields: `protocol`, optionally `tls`, `enforcement`.

(val: &regorus::Value)

Source from the content-addressed store, hash-verified

162/// The value is expected to be the raw endpoint object from the Rego data,
163/// containing fields: `protocol`, optionally `tls`, `enforcement`.
164pub fn parse_l7_config(val: &regorus::Value) -> Option<L7EndpointConfig> {
165 let protocol_val = get_object_str(val, "protocol")?;
166 let protocol = L7Protocol::parse(&protocol_val)?;
167
168 let tls = match get_object_str(val, "tls").as_deref() {
169 Some("skip") => TlsMode::Skip,
170 Some("terminate") => {
171 let event = openshell_ocsf::NetworkActivityBuilder::new(openshell_ocsf::ctx::ctx())
172 .activity(openshell_ocsf::ActivityId::Other)
173 .severity(openshell_ocsf::SeverityId::Medium)
174 .message(
175 "'tls: terminate' is deprecated; TLS termination is now automatic. \
176 Use 'tls: skip' to explicitly disable. This field will be removed in a future version.",
177 )
178 .build();
179 openshell_ocsf::ocsf_emit!(event);
180 TlsMode::Auto
181 }
182 Some("passthrough") => {
183 let event = openshell_ocsf::NetworkActivityBuilder::new(openshell_ocsf::ctx::ctx())
184 .activity(openshell_ocsf::ActivityId::Other)
185 .severity(openshell_ocsf::SeverityId::Medium)
186 .message(
187 "'tls: passthrough' is deprecated; TLS termination is now automatic. \
188 Use 'tls: skip' to explicitly disable. This field will be removed in a future version.",
189 )
190 .build();
191 openshell_ocsf::ocsf_emit!(event);
192 TlsMode::Auto
193 }
194 _ => TlsMode::Auto,
195 };
196
197 let enforcement = match get_object_str(val, "enforcement").as_deref() {
198 Some("enforce") => EnforcementMode::Enforce,
199 _ => EnforcementMode::Audit,
200 };
201
202 let allow_encoded_slash = get_object_bool(val, "allow_encoded_slash").unwrap_or(false);
203 let websocket_credential_rewrite =
204 get_object_bool(val, "websocket_credential_rewrite").unwrap_or(false);
205 let request_body_credential_rewrite =
206 get_object_bool(val, "request_body_credential_rewrite").unwrap_or(false);
207 let websocket_graphql_policy =
208 protocol == L7Protocol::Websocket && endpoint_has_graphql_policy(val);
209 let graphql_max_body_bytes = get_object_u64(val, "graphql_max_body_bytes")
210 .and_then(|v| usize::try_from(v).ok())
211 .filter(|v| *v > 0)
212 .unwrap_or(graphql::DEFAULT_MAX_BODY_BYTES);
213 let json_rpc_max_body_bytes = get_object_u64(val, "json_rpc_max_body_bytes")
214 .and_then(|v| usize::try_from(v).ok())
215 .filter(|v| *v > 0)
216 .unwrap_or(jsonrpc::DEFAULT_MAX_BODY_BYTES);
217 let mcp_strict_tool_names = protocol == L7Protocol::Mcp
218 && get_object_bool(val, "mcp_strict_tool_names").unwrap_or(true);
219
220 let credential_signing = match get_object_str(val, "credential_signing").as_deref() {
221 Some("sigv4") => CredentialSigning::SigV4,

Calls 9

get_object_strFunction · 0.85
get_object_boolFunction · 0.85
get_object_u64Function · 0.85
messageMethod · 0.80
is_sigv4Method · 0.80
ctxFunction · 0.50
buildMethod · 0.45
is_emptyMethod · 0.45