Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: help build prepare build-amd64 build-arm64
.PHONY: help build prepare build-amd64 build-arm64 cargo-run

.DEFAULT_GOAL := help

Expand Down Expand Up @@ -28,8 +28,14 @@ build-arm64: prepare
build: prepare
@docker buildx build -t permitio/pdp-v2:$(VERSION) . --load

build-latest: prepare
@docker buildx build -t permitio/pdp-v2:latest . --load

run: run-prepare
@docker run -it --rm -p 7766:7000 --env PDP_API_KEY=$(API_KEY) --env PDP_DEBUG=true permitio/pdp-v2:$(VERSION)

run-on-background: run-prepare
@docker run -it --rm -d -p 7766:7000 --env PDP_API_KEY=$(API_KEY) --env PDP_DEBUG=true permitio/pdp-v2:$(VERSION)

cargo-run:
cargo run --bin pdp-server --package pdp-server -- --port 7766
2 changes: 2 additions & 0 deletions pdp-server/src/api/horizon_fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ mod tests {
debug: None,
port: 0,
use_new_authorized_users: false,
allow_unauthenticated_trino: false,
healthcheck_timeout: 1.0,
// Point to a non-existent server with a reserved port
horizon: crate::config::horizon::HorizonConfig {
Expand Down Expand Up @@ -591,6 +592,7 @@ mod tests {
debug: None,
port: 0,
use_new_authorized_users: false,
allow_unauthenticated_trino: false,
healthcheck_timeout: 1.0,
horizon: crate::config::horizon::HorizonConfig {
host: horizon_mock.address().ip().to_string(),
Expand Down
23 changes: 17 additions & 6 deletions pdp-server/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub(crate) mod authz;
pub(crate) mod authzen;
pub(crate) mod health;
mod horizon_fallback;
pub(crate) mod trino;

use crate::api::authn_middleware::authentication_middleware;
use crate::api::horizon_fallback::fallback_to_horizon;
Expand All @@ -11,17 +12,27 @@ use axum::{middleware, routing::any, Router};

/// Combines all API routes into a single router
pub(super) fn router(state: &AppState) -> Router<AppState> {
Router::new()
.merge(health::router())
.merge(protected_routes(state))
let mut root = Router::new().merge(health::router());

if state.config.allow_unauthenticated_trino {
root = root.merge(trino::router());
}

root.merge(protected_routes(state))
}

/// Creates a router for protected routes that require API key authentication
fn protected_routes(state: &AppState) -> Router<AppState> {
// Protected routes that require API key authentication
Router::new()
let mut router = Router::new()
.merge(authz::router())
.merge(authzen::router())
.merge(authzen::router());

if !state.config.allow_unauthenticated_trino {
router = router.merge(trino::router());
}

// Protected routes that require API key authentication
router
// Add fallback route to handle any unmatched requests
.fallback(any(fallback_to_horizon))
// we must use layer here and not route_layer because, route_layer only
Expand Down
Loading
Loading