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

Function check_role_allowed

src/environmentd/src/http.rs:1564–1578  ·  view source on GitHub ↗

TODO move this somewhere it can be shared with PGWIRE

(name: &str, allowed_roles: AllowedRoles)

Source from the content-addressed store, hash-verified

1562
1563// TODO move this somewhere it can be shared with PGWIRE
1564fn check_role_allowed(name: &str, allowed_roles: AllowedRoles) -> Result<(), AuthError> {
1565 let is_internal_user = INTERNAL_USER_NAMES.contains(name);
1566 // this is a superset of internal users
1567 let is_reserved_user = mz_adapter::catalog::is_reserved_role_name(name);
1568 let role_allowed = match allowed_roles {
1569 AllowedRoles::Normal => !is_reserved_user,
1570 AllowedRoles::Internal => is_internal_user,
1571 AllowedRoles::NormalAndInternal => !is_reserved_user || is_internal_user,
1572 };
1573 if role_allowed {
1574 Ok(())
1575 } else {
1576 Err(AuthError::RoleDisallowed(name.to_owned()))
1577 }
1578}
1579
1580/// Default layers that should be applied to all routes, and should get applied to both the
1581/// internal http and external http routers.

Callers 5

handle_loginFunction · 0.85
http_authFunction · 0.85
init_wsFunction · 0.85
authFunction · 0.85

Calls 3

is_reserved_role_nameFunction · 0.85
containsMethod · 0.45
to_ownedMethod · 0.45

Tested by

no test coverage detected