MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / plan_create_network_policy

Function plan_create_network_policy

src/sql/src/plan/statement/ddl.rs:4537–4588  ·  view source on GitHub ↗
(
    ctx: &StatementContext,
    CreateNetworkPolicyStatement { name, options }: CreateNetworkPolicyStatement<Aug>,
)

Source from the content-addressed store, hash-verified

4535}
4536
4537pub fn plan_create_network_policy(
4538 ctx: &StatementContext,
4539 CreateNetworkPolicyStatement { name, options }: CreateNetworkPolicyStatement<Aug>,
4540) -> Result<Plan, PlanError> {
4541 ctx.require_feature_flag(&vars::ENABLE_NETWORK_POLICIES)?;
4542 let policy_options: NetworkPolicyOptionExtracted = options.try_into()?;
4543
4544 let Some(rule_defs) = policy_options.rules else {
4545 sql_bail!("RULES must be specified when creating network policies.");
4546 };
4547
4548 let mut rules = vec![];
4549 for NetworkPolicyRuleDefinition { name, options } in rule_defs {
4550 let NetworkPolicyRuleOptionExtracted {
4551 seen: _,
4552 direction,
4553 action,
4554 address,
4555 } = options.try_into()?;
4556 let (direction, action, address) = match (direction, action, address) {
4557 (Some(direction), Some(action), Some(address)) => (
4558 NetworkPolicyRuleDirection::try_from(direction.as_str())?,
4559 NetworkPolicyRuleAction::try_from(action.as_str())?,
4560 PolicyAddress::try_from(address.as_str())?,
4561 ),
4562 (_, _, _) => {
4563 sql_bail!("Direction, Address, and Action must specified when creating a rule")
4564 }
4565 };
4566 rules.push(NetworkPolicyRule {
4567 name: normalize::ident(name),
4568 direction,
4569 action,
4570 address,
4571 });
4572 }
4573
4574 if rules.len()
4575 > ctx
4576 .catalog
4577 .system_vars()
4578 .max_rules_per_network_policy()
4579 .try_into()?
4580 {
4581 sql_bail!("RULES count exceeds max_rules_per_network_policy.")
4582 }
4583
4584 Ok(Plan::CreateNetworkPolicy(CreateNetworkPolicyPlan {
4585 name: normalize::ident(name),
4586 rules,
4587 }))
4588}
4589
4590pub fn plan_alter_network_policy(
4591 ctx: &StatementContext,

Callers 1

planFunction · 0.85

Calls 8

identFunction · 0.85
require_feature_flagMethod · 0.45
try_intoMethod · 0.45
as_strMethod · 0.45
pushMethod · 0.45
lenMethod · 0.45
system_varsMethod · 0.45

Tested by

no test coverage detected