phlo-api 0.17.0__tar.gz → 0.19.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {phlo_api-0.17.0 → phlo_api-0.19.0}/PKG-INFO +16 -3
- phlo_api-0.19.0/README.md +169 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/pyproject.toml +21 -3
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/Dockerfile +38 -19
- phlo_api-0.19.0/src/phlo_api/api/asset_preview_filters.py +55 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/api/authentication.py +75 -51
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/api/authoring.py +21 -16
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/api/authorization.py +35 -332
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/api/continuity.py +106 -69
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/api/maintenance.py +10 -9
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/api/observability.py +46 -31
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/api/operation_controls.py +447 -181
- phlo_api-0.19.0/src/phlo_api/api/v1.py +597 -0
- phlo_api-0.19.0/src/phlo_api/api/v1_action_availability.py +245 -0
- phlo_api-0.19.0/src/phlo_api/api/v1_admin_audit.py +318 -0
- phlo_api-0.19.0/src/phlo_api/api/v1_admin_identity.py +914 -0
- phlo_api-0.19.0/src/phlo_api/api/v1_asset_insights.py +690 -0
- phlo_api-0.19.0/src/phlo_api/api/v1_assets.py +3923 -0
- phlo_api-0.19.0/src/phlo_api/api/v1_audit_proposals.py +313 -0
- phlo_api-0.19.0/src/phlo_api/api/v1_authoring.py +46 -0
- phlo_api-0.19.0/src/phlo_api/api/v1_branch_workflows.py +1756 -0
- phlo_api-0.19.0/src/phlo_api/api/v1_data_products.py +483 -0
- phlo_api-0.19.0/src/phlo_api/api/v1_datasets.py +73 -0
- phlo_api-0.19.0/src/phlo_api/api/v1_extensions.py +98 -0
- phlo_api-0.19.0/src/phlo_api/api/v1_git_review.py +325 -0
- phlo_api-0.19.0/src/phlo_api/api/v1_jobs.py +1640 -0
- phlo_api-0.19.0/src/phlo_api/api/v1_loads.py +324 -0
- phlo_api-0.19.0/src/phlo_api/api/v1_metrics.py +583 -0
- phlo_api-0.19.0/src/phlo_api/api/v1_operations.py +140 -0
- phlo_api-0.19.0/src/phlo_api/api/v1_packages.py +273 -0
- phlo_api-0.19.0/src/phlo_api/api/v1_pages.py +58 -0
- phlo_api-0.19.0/src/phlo_api/api/v1_query.py +851 -0
- phlo_api-0.19.0/src/phlo_api/api/v1_query_sql.py +86 -0
- phlo_api-0.19.0/src/phlo_api/api/v1_readiness.py +226 -0
- phlo_api-0.19.0/src/phlo_api/api/v1_search.py +114 -0
- phlo_api-0.19.0/src/phlo_api/api/v1_staging.py +877 -0
- phlo_api-0.19.0/src/phlo_api/api/v1_transform_editor.py +1122 -0
- phlo_api-0.19.0/src/phlo_api/api/v1_upload_ingestion.py +840 -0
- phlo_api-0.19.0/src/phlo_api/api/v1_uploads.py +663 -0
- phlo_api-0.19.0/src/phlo_api/api/v1_wap.py +217 -0
- phlo_api-0.19.0/src/phlo_api/branch_schema_comparison.py +62 -0
- phlo_api-0.19.0/src/phlo_api/branch_schema_resolution.py +390 -0
- phlo_api-0.19.0/src/phlo_api/candidate_runtime.py +398 -0
- phlo_api-0.19.0/src/phlo_api/entrypoint.sh +54 -0
- phlo_api-0.19.0/src/phlo_api/errors.py +95 -0
- phlo_api-0.19.0/src/phlo_api/incidents.py +1546 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/main.py +121 -24
- phlo_api-0.19.0/src/phlo_api/migrations.py +113 -0
- phlo_api-0.19.0/src/phlo_api/notifications.py +219 -0
- phlo_api-0.19.0/src/phlo_api/observatory_api/_loki_regex_worker.py +68 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/observatory_api/contributing.py +48 -42
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/observatory_api/dagster.py +137 -635
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/observatory_api/extensions.py +6 -1
- phlo_api-0.19.0/src/phlo_api/observatory_api/http_client.py +32 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/observatory_api/lineage.py +5 -5
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/observatory_api/loki.py +230 -110
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/observatory_api/observatory.py +115 -167
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/observatory_api/observatory_durable_state.py +51 -14
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/observatory_api/observatory_models.py +10 -10
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/observatory_api/observatory_operation_journal.py +1 -12
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/observatory_api/observatory_saved_queries.py +1 -12
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/observatory_api/observatory_search.py +55 -52
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/observatory_api/observatory_services.py +161 -162
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/observatory_api/observatory_workflow_wizard.py +103 -54
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/observatory_api/orchestrator_operations.py +1 -2
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/observatory_api/package_install.py +62 -37
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/observatory_api/run_action_contract.py +1 -1
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/observatory_api/run_report.py +10 -1
- phlo_api-0.19.0/src/phlo_api/observatory_api/service_payloads.py +100 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/observatory_api/settings.py +166 -1
- phlo_api-0.19.0/src/phlo_api/observatory_api/trino.py +317 -0
- phlo_api-0.19.0/src/phlo_api/observatory_api/v1_preview.py +538 -0
- phlo_api-0.19.0/src/phlo_api/preview_preflight.py +23 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/security_manifest.py +777 -85
- phlo_api-0.19.0/src/phlo_api/service.yaml +326 -0
- phlo_api-0.19.0/src/phlo_api/settings.py +314 -0
- phlo_api-0.19.0/src/phlo_api/sql/001_incidents.sql +93 -0
- phlo_api-0.19.0/src/phlo_api/sql/002_query_usage.sql +26 -0
- phlo_api-0.19.0/src/phlo_api/sql/003_incident_query_parity.sql +57 -0
- phlo_api-0.19.0/src/phlo_api/sql/004_configurable_environments.sql +18 -0
- phlo_api-0.19.0/src/phlo_api/sql/004_notification_read_state.sql +11 -0
- phlo_api-0.19.0/src/phlo_api/usage.py +366 -0
- phlo_api-0.19.0/src/phlo_api/v1_contract.py +96 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api.egg-info/PKG-INFO +16 -3
- phlo_api-0.19.0/src/phlo_api.egg-info/SOURCES.txt +186 -0
- phlo_api-0.19.0/src/phlo_api.egg-info/requires.txt +33 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/tests/test_api_backend_endpoints.py +4 -2
- phlo_api-0.19.0/tests/test_api_settings.py +130 -0
- phlo_api-0.19.0/tests/test_asset_operations.py +762 -0
- phlo_api-0.19.0/tests/test_asset_read_parity.py +605 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/tests/test_auth_helper_meta.py +9 -0
- phlo_api-0.19.0/tests/test_authentication_api.py +452 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/tests/test_authoring_api.py +59 -15
- {phlo_api-0.17.0 → phlo_api-0.19.0}/tests/test_authorization_api.py +51 -123
- phlo_api-0.19.0/tests/test_branch_schema_comparison.py +86 -0
- phlo_api-0.19.0/tests/test_branch_schema_resolution.py +288 -0
- phlo_api-0.19.0/tests/test_candidate_runtime.py +244 -0
- phlo_api-0.19.0/tests/test_continuity_api.py +1083 -0
- phlo_api-0.19.0/tests/test_cors.py +30 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/tests/test_dataset_cutover_parity.py +50 -1
- {phlo_api-0.17.0 → phlo_api-0.19.0}/tests/test_dataset_overlay_retirement.py +27 -0
- phlo_api-0.19.0/tests/test_error_envelope.py +226 -0
- phlo_api-0.19.0/tests/test_governance_settings.py +865 -0
- phlo_api-0.19.0/tests/test_identity_authority_postgres.py +174 -0
- phlo_api-0.19.0/tests/test_incident_query_parity.py +518 -0
- phlo_api-0.19.0/tests/test_incident_signed_resolution_postgres.py +175 -0
- phlo_api-0.19.0/tests/test_incidents_postgres.py +461 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/tests/test_integration_api.py +78 -108
- {phlo_api-0.17.0 → phlo_api-0.19.0}/tests/test_loki_api.py +18 -34
- {phlo_api-0.17.0 → phlo_api-0.19.0}/tests/test_maintenance_api.py +7 -9
- phlo_api-0.19.0/tests/test_no_fork_multiprocessing.py +27 -0
- phlo_api-0.19.0/tests/test_notifications.py +187 -0
- phlo_api-0.19.0/tests/test_notifications_postgres.py +165 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/tests/test_observability_api.py +7 -5
- {phlo_api-0.17.0 → phlo_api-0.19.0}/tests/test_observatory_actions.py +9 -1
- {phlo_api-0.17.0 → phlo_api-0.19.0}/tests/test_observatory_api.py +315 -128
- {phlo_api-0.17.0 → phlo_api-0.19.0}/tests/test_observatory_capabilities.py +22 -6
- {phlo_api-0.17.0 → phlo_api-0.19.0}/tests/test_observatory_legacy_api.py +23 -129
- {phlo_api-0.17.0 → phlo_api-0.19.0}/tests/test_observatory_operation_journal.py +73 -4
- {phlo_api-0.17.0 → phlo_api-0.19.0}/tests/test_observatory_package_install.py +25 -28
- {phlo_api-0.17.0 → phlo_api-0.19.0}/tests/test_observatory_read_models.py +5 -5
- {phlo_api-0.17.0 → phlo_api-0.19.0}/tests/test_observatory_run_action_contract.py +14 -6
- {phlo_api-0.17.0 → phlo_api-0.19.0}/tests/test_observatory_surfaces.py +11 -3
- {phlo_api-0.17.0 → phlo_api-0.19.0}/tests/test_observatory_workflow_wizard.py +138 -4
- {phlo_api-0.17.0 → phlo_api-0.19.0}/tests/test_operation_controls.py +339 -40
- phlo_api-0.19.0/tests/test_operation_controls_postgres.py +496 -0
- phlo_api-0.19.0/tests/test_operational_observations.py +856 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/tests/test_pagination.py +1 -0
- phlo_api-0.19.0/tests/test_preview_provision_integration.py +537 -0
- phlo_api-0.19.0/tests/test_require_scope.py +244 -0
- phlo_api-0.19.0/tests/test_route_inventory.py +259 -0
- phlo_api-0.19.0/tests/test_run_report_postgres_recovery.py +106 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/tests/test_security_manifest.py +34 -1
- phlo_api-0.19.0/tests/test_security_manifest_action_dispatch.py +182 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/tests/test_service_correlation_runtime.py +18 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/tests/test_service_url_resolution.py +16 -10
- phlo_api-0.19.0/tests/test_trino_defaults.py +106 -0
- phlo_api-0.19.0/tests/test_trino_query_bound.py +98 -0
- phlo_api-0.19.0/tests/test_trino_sql.py +57 -0
- phlo_api-0.19.0/tests/test_usage.py +263 -0
- phlo_api-0.19.0/tests/test_usage_trino_integration.py +494 -0
- phlo_api-0.19.0/tests/test_v1_action_availability.py +204 -0
- phlo_api-0.19.0/tests/test_v1_admin_audit.py +255 -0
- phlo_api-0.19.0/tests/test_v1_admin_identity.py +463 -0
- phlo_api-0.19.0/tests/test_v1_api.py +3536 -0
- phlo_api-0.19.0/tests/test_v1_asset_row_count.py +243 -0
- phlo_api-0.19.0/tests/test_v1_audit_parity.py +222 -0
- phlo_api-0.19.0/tests/test_v1_branch_nessie_contract.py +113 -0
- phlo_api-0.19.0/tests/test_v1_branch_workflows.py +856 -0
- phlo_api-0.19.0/tests/test_v1_contract.py +346 -0
- phlo_api-0.19.0/tests/test_v1_data_products.py +622 -0
- phlo_api-0.19.0/tests/test_v1_git_review.py +242 -0
- phlo_api-0.19.0/tests/test_v1_jobs_read.py +1296 -0
- phlo_api-0.19.0/tests/test_v1_loads.py +282 -0
- phlo_api-0.19.0/tests/test_v1_metrics.py +762 -0
- phlo_api-0.19.0/tests/test_v1_observatory_reads.py +677 -0
- phlo_api-0.19.0/tests/test_v1_package_install.py +183 -0
- phlo_api-0.19.0/tests/test_v1_preview.py +454 -0
- phlo_api-0.19.0/tests/test_v1_query_api.py +471 -0
- phlo_api-0.19.0/tests/test_v1_query_sql.py +105 -0
- phlo_api-0.19.0/tests/test_v1_readiness.py +194 -0
- phlo_api-0.19.0/tests/test_v1_staging.py +715 -0
- phlo_api-0.19.0/tests/test_v1_transform.py +278 -0
- phlo_api-0.19.0/tests/test_v1_transform_editor.py +719 -0
- phlo_api-0.19.0/tests/test_v1_upload_ingestion.py +1164 -0
- phlo_api-0.19.0/tests/test_v1_uploads.py +519 -0
- phlo_api-0.19.0/tests/test_v1_wap.py +475 -0
- phlo_api-0.19.0/tests/test_windows_api_imports.py +34 -0
- phlo_api-0.19.0/tests/test_workflow_wizard_boundaries.py +159 -0
- phlo_api-0.17.0/README.md +0 -76
- phlo_api-0.17.0/src/phlo_api/entrypoint.sh +0 -41
- phlo_api-0.17.0/src/phlo_api/observatory_api/iceberg.py +0 -536
- phlo_api-0.17.0/src/phlo_api/observatory_api/nessie.py +0 -410
- phlo_api-0.17.0/src/phlo_api/observatory_api/quality.py +0 -606
- phlo_api-0.17.0/src/phlo_api/observatory_api/search.py +0 -169
- phlo_api-0.17.0/src/phlo_api/observatory_api/trino.py +0 -742
- phlo_api-0.17.0/src/phlo_api/observatory_api/trino_sql.py +0 -213
- phlo_api-0.17.0/src/phlo_api/service.yaml +0 -103
- phlo_api-0.17.0/src/phlo_api.egg-info/SOURCES.txt +0 -90
- phlo_api-0.17.0/src/phlo_api.egg-info/requires.txt +0 -15
- phlo_api-0.17.0/tests/test_authentication_api.py +0 -188
- phlo_api-0.17.0/tests/test_continuity_api.py +0 -639
- phlo_api-0.17.0/tests/test_cors.py +0 -39
- phlo_api-0.17.0/tests/test_lakehouse_compatibility.py +0 -104
- phlo_api-0.17.0/tests/test_trino_defaults.py +0 -222
- phlo_api-0.17.0/tests/test_trino_sql.py +0 -90
- {phlo_api-0.17.0 → phlo_api-0.19.0}/setup.cfg +0 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/__init__.py +0 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/api/__init__.py +0 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/observatory_api/__init__.py +0 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/observatory_api/extension_settings.py +0 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/observatory_api/observatory_actions.py +0 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/observatory_api/observatory_cache.py +3 -3
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/observatory_api/observatory_capabilities.py +0 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/observatory_api/observatory_metadata.py +0 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/observatory_api/observatory_runs.py +0 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/pagination.py +0 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/plugin.py +0 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/regulated_surface_adapter.py +0 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api/run_evidence.py +0 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api.egg-info/dependency_links.txt +0 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api.egg-info/entry_points.txt +0 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/src/phlo_api.egg-info/top_level.txt +0 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/tests/test_api_import_boundaries.py +0 -0
- {phlo_api-0.17.0 → phlo_api-0.19.0}/tests/test_lineage_api.py +0 -0
|
@@ -1,23 +1,36 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: phlo-api
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.19.0
|
|
4
4
|
Summary: Phlo API - Backend service exposing Phlo internals to Observatory
|
|
5
5
|
Author-email: Phlo Team <team@phlo.dev>
|
|
6
6
|
License: MIT
|
|
7
7
|
Requires-Python: >=3.12
|
|
8
8
|
Description-Content-Type: text/plain
|
|
9
|
-
Requires-Dist: phlo<0.
|
|
10
|
-
Requires-Dist: fastapi
|
|
9
|
+
Requires-Dist: phlo<0.20,>=0.19.0
|
|
10
|
+
Requires-Dist: fastapi<0.137,>=0.127.0
|
|
11
11
|
Requires-Dist: httpx>=0.28.1
|
|
12
12
|
Requires-Dist: anyio>=4.14.2
|
|
13
13
|
Requires-Dist: psycopg2-binary>=2.9.11
|
|
14
|
+
Requires-Dist: phlo-pandera<0.18,>=0.17.0
|
|
15
|
+
Requires-Dist: phlo-postgres<0.19,>=0.18.0
|
|
14
16
|
Requires-Dist: pydantic>=2.0
|
|
15
17
|
Requires-Dist: pyyaml>=6.0.1
|
|
18
|
+
Requires-Dist: sqlglot<31,>=30.2.1
|
|
16
19
|
Requires-Dist: uvicorn>=0.38.0
|
|
20
|
+
Provides-Extra: dagster
|
|
21
|
+
Requires-Dist: phlo-dagster>=0.3.2; extra == "dagster"
|
|
17
22
|
Provides-Extra: dev
|
|
18
23
|
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
19
24
|
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
25
|
+
Provides-Extra: dlt
|
|
26
|
+
Requires-Dist: phlo-dlt<0.19,>=0.18.0; extra == "dlt"
|
|
27
|
+
Provides-Extra: iceberg
|
|
28
|
+
Requires-Dist: phlo-iceberg<0.19,>=0.18.0; extra == "iceberg"
|
|
20
29
|
Provides-Extra: lineage
|
|
21
30
|
Requires-Dist: phlo-lineage>=0.1.0; extra == "lineage"
|
|
31
|
+
Provides-Extra: transform
|
|
32
|
+
Requires-Dist: phlo-transform<0.3,>=0.2.0; extra == "transform"
|
|
33
|
+
Provides-Extra: trino
|
|
34
|
+
Requires-Dist: phlo-trino<0.19,>=0.18.0; extra == "trino"
|
|
22
35
|
|
|
23
36
|
Phlo API backend for Observatory.
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# phlo-api
|
|
2
|
+
|
|
3
|
+
Backend API service for Phlo Observatory.
|
|
4
|
+
|
|
5
|
+
## Description
|
|
6
|
+
|
|
7
|
+
FastAPI-based backend service exposing Phlo internals to the Observatory UI. Provides endpoints for lineage, quality checks, assets, and metadata.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install phlo-api
|
|
13
|
+
# or
|
|
14
|
+
phlo plugin install api
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Configuration
|
|
18
|
+
|
|
19
|
+
| Variable | Default | Description |
|
|
20
|
+
| --------------- | --------- | --------------- |
|
|
21
|
+
| `PHLO_API_PORT` | `4000` | API server port |
|
|
22
|
+
| `HOST` | `0.0.0.0` | API server host |
|
|
23
|
+
| `PHLO_AUTHORIZATION_BACKEND` | unset | Authorization backend capability name |
|
|
24
|
+
| `PHLO_AUTHORIZATION_MODE` | `required` in production, `optional` otherwise | Guard behavior when no authorization backend exists |
|
|
25
|
+
|
|
26
|
+
`PHLO_AUTHORIZATION_MODE=optional` leaves guarded routes reachable until an
|
|
27
|
+
authorization backend is configured. `PHLO_AUTHORIZATION_MODE=required` makes
|
|
28
|
+
guarded routes fail closed with HTTP `503` when no backend is available.
|
|
29
|
+
|
|
30
|
+
Production (`PHLO_ENVIRONMENT=production`, `prod`, `staging`, or `regulated`,
|
|
31
|
+
or any regulated deployment) defaults to `required` and fails startup if you
|
|
32
|
+
explicitly configure `optional`. Development stays opt-in unless you set the
|
|
33
|
+
mode explicitly or enable regulated mode. Production requires an
|
|
34
|
+
authentication provider and an authorization backend; the preflight report
|
|
35
|
+
(`phlo services preflight --production`) verifies the locally inspectable part
|
|
36
|
+
of that contract.
|
|
37
|
+
|
|
38
|
+
You can also declare these settings in `phlo.yaml` via `api.authorization` or
|
|
39
|
+
`services.phlo-api.authorization`.
|
|
40
|
+
|
|
41
|
+
## Auto-Configuration
|
|
42
|
+
|
|
43
|
+
This package is **fully auto-configured**:
|
|
44
|
+
|
|
45
|
+
| Feature | How It Works |
|
|
46
|
+
| --------------------- | ------------------------------------------------------- |
|
|
47
|
+
| **Metrics Labels** | Exposes Prometheus metrics at `/metrics` |
|
|
48
|
+
| **Service Discovery** | Automatically scraped by Prometheus |
|
|
49
|
+
| **Health Check** | Provides `/health` endpoint for container orchestration |
|
|
50
|
+
|
|
51
|
+
## Usage
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
# Start the API service
|
|
55
|
+
phlo services start --service phlo-api
|
|
56
|
+
|
|
57
|
+
# For local source development, initialize dev mode first.
|
|
58
|
+
phlo services init --dev --phlo-source /path/to/phlo
|
|
59
|
+
phlo services start --service phlo-api
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Endpoints
|
|
63
|
+
|
|
64
|
+
- **API Base**: `http://localhost:4000`
|
|
65
|
+
- **Health**: `http://localhost:4000/health`
|
|
66
|
+
- **Metrics**: `http://localhost:4000/metrics`
|
|
67
|
+
- **OpenAPI Docs**: `http://localhost:4000/docs`
|
|
68
|
+
|
|
69
|
+
## API Routes
|
|
70
|
+
|
|
71
|
+
| Route | Description |
|
|
72
|
+
| --------------- | ------------------------- |
|
|
73
|
+
| `/api/lineage` | Data lineage queries |
|
|
74
|
+
| `/api/quality` | Quality check results |
|
|
75
|
+
| `/api/assets` | Dagster asset information |
|
|
76
|
+
| `/api/branches` | Nessie branch management |
|
|
77
|
+
|
|
78
|
+
## Retained CSV candidate lifecycle
|
|
79
|
+
|
|
80
|
+
`GET /api/v1/uploads/csv?env=<environment>` lists the current actor's retained
|
|
81
|
+
uploads with their original filename, checksum, and timestamps. The optional
|
|
82
|
+
`include_archived=true` also returns archived uploads. Other actors' uploads
|
|
83
|
+
are not visible.
|
|
84
|
+
|
|
85
|
+
`POST /api/v1/uploads/csv/{upload_id}/archive?env=<environment>` accepts
|
|
86
|
+
`{"archived": true, "reason": "Superseded review"}`. Use `false` to restore the
|
|
87
|
+
upload. Archiving preserves the upload bytes, review recipe, generated source,
|
|
88
|
+
candidate receipt, run evidence, and mutation fences. It neither reclaims
|
|
89
|
+
disk space nor resets retained-byte and global collection limits. Archived
|
|
90
|
+
uploads cannot change review, prepare a destination, plan, or load.
|
|
91
|
+
|
|
92
|
+
The candidate endpoints below use the same upload path and environment:
|
|
93
|
+
|
|
94
|
+
- `GET .../candidate/review` returns immutable evidence and a stale marker.
|
|
95
|
+
A changed base prevents release eligibility but permits a bounded preview
|
|
96
|
+
when the exact candidate hash and snapshot still verify. Candidate drift
|
|
97
|
+
or unavailable providers suppress rows rather than hiding the receipt.
|
|
98
|
+
- `POST .../candidate/reconcile` verifies the confirmed Dagster run, immutable
|
|
99
|
+
plan identity, table snapshot, and reviewed row count before recording a
|
|
100
|
+
loaded result. It never launches a run or retries a write. Without an exact
|
|
101
|
+
run receipt, an uncertain launch remains unresolved. A partially prepared
|
|
102
|
+
catalog can recover only from a complete recorded binding with no later
|
|
103
|
+
branch writes. Reconciliation never adopts an unrecorded catalog.
|
|
104
|
+
- `GET .../candidate/handoff` exports the attested contract and workflow files
|
|
105
|
+
with checksums and candidate evidence. The generated files remain
|
|
106
|
+
candidate-specific until a source review adapts and commits them. Existing
|
|
107
|
+
branch checks, trial merge, and signed merge remain separate authorised POST
|
|
108
|
+
operations. Export does not publish source or promote candidate data.
|
|
109
|
+
|
|
110
|
+
## Explicit payload reclamation
|
|
111
|
+
|
|
112
|
+
Reclamation is irreversible and separate from archive. It requires an archived
|
|
113
|
+
record, write authorisation, `confirmed: true`, a non-blank `reason`, and the
|
|
114
|
+
current version, checksum, or revision digest. Provider tables, candidate
|
|
115
|
+
branches, catalogues, release records, and operation claims are not deleted.
|
|
116
|
+
|
|
117
|
+
All paths below have the `/api/v1` prefix and require `env`:
|
|
118
|
+
|
|
119
|
+
| POST path | Required precondition | Local content reclaimed |
|
|
120
|
+
| --- | --- | --- |
|
|
121
|
+
| `/metric-models/{model_id}/reclaim` | `expected_version` | Full draft definition |
|
|
122
|
+
| `/data-products/{product_id}/reclaim` | `expected_version` | Full draft definition |
|
|
123
|
+
| `/uploads/csv/{upload_id}/reclaim` | `expected_checksum` | Raw retained CSV bytes |
|
|
124
|
+
| `/transform/models/{model_id}/drafts/{draft_id}/{revision}/reclaim` | `expected_revision_digest` | Copied workspace inputs |
|
|
125
|
+
| `/transform/models/{model_id}/drafts/{draft_id}/{revision}/executions/{execution_id}/reclaim` | `expected_revision_digest` | Local execution workspace |
|
|
126
|
+
|
|
127
|
+
Metric and product definitions become compact permanent tombstones. Their IDs
|
|
128
|
+
cannot be reused, and later definition reads, exports, or restores return 410.
|
|
129
|
+
Reclamation frees one full-definition slot, not the retained identity evidence.
|
|
130
|
+
CSV and native metadata remain available, but reclaimed payloads cannot be
|
|
131
|
+
restored. Retained reports, checksums, SQL handoff evidence, and audit records
|
|
132
|
+
remain. Completed cleanup frees the corresponding payload quota. Interrupted
|
|
133
|
+
cleanup stays fenced until an explicit confirmed retry completes it.
|
|
134
|
+
|
|
135
|
+
Pending or unknown mutations block reclamation. The operation-store guard
|
|
136
|
+
holds the claim lock through local disposal, so a new claim cannot race the
|
|
137
|
+
safety check. Unknown persisted metadata also blocks disposal rather than
|
|
138
|
+
silently discarding a future fence or reference.
|
|
139
|
+
|
|
140
|
+
When `audit.retention_years` is configured, explicit reclamation also preserves
|
|
141
|
+
supporting payloads for that minimum period. Definition changes reset their
|
|
142
|
+
retention age. CSV and native payloads must satisfy the minimum from both
|
|
143
|
+
creation and their latest archival timestamp, so recent supporting activity
|
|
144
|
+
cannot rely on an old creation date. Audit records and tombstones do not expire
|
|
145
|
+
when payloads become eligible. An unset minimum does not bypass archive,
|
|
146
|
+
identity, authorisation, or unresolved-mutation checks.
|
|
147
|
+
|
|
148
|
+
## Load observation pagination
|
|
149
|
+
|
|
150
|
+
`GET /api/v1/loads?env=<environment>&limit=100` returns authorised private CSV
|
|
151
|
+
observations followed by ingestion runs. `limit` defaults to 100 and accepts
|
|
152
|
+
values from 1 to 300. The response includes `next_cursor`; passing that value
|
|
153
|
+
as `after` continues the inventory. A cursor belongs to the actor, environment,
|
|
154
|
+
Dagster location, and configured reference that created it.
|
|
155
|
+
|
|
156
|
+
CSV observations use descending receipt identity. Ingestion runs follow
|
|
157
|
+
Dagster's creation order, with assets ordered by ID within each run. This is
|
|
158
|
+
not a global ordering by load completion time. The continuation preserves a
|
|
159
|
+
partially returned run so runs with many assets do not lose observations.
|
|
160
|
+
|
|
161
|
+
Each request scans at most 100 provider runs. An empty page can still have a
|
|
162
|
+
`next_cursor` when unrelated or denied runs consume that scan. The inventory
|
|
163
|
+
is live, not a frozen snapshot. Refreshing includes new observations before
|
|
164
|
+
the current cursor. Observatory's filters and JSON export apply to loaded
|
|
165
|
+
observations, not pages that have not been fetched.
|
|
166
|
+
|
|
167
|
+
Pagination does not expand the underlying evidence. Asset materialisation
|
|
168
|
+
row-count history covers the last seven days. An ingestion run is not a
|
|
169
|
+
per-file receipt, and an unknown CSV receipt timestamp remains unknown.
|
|
@@ -7,19 +7,22 @@ requires = [
|
|
|
7
7
|
|
|
8
8
|
[project]
|
|
9
9
|
dependencies = [
|
|
10
|
-
"phlo>=0.
|
|
11
|
-
"fastapi>=0.127.0",
|
|
10
|
+
"phlo>=0.19.0,<0.20",
|
|
11
|
+
"fastapi>=0.127.0,<0.137",
|
|
12
12
|
"httpx>=0.28.1",
|
|
13
13
|
"anyio>=4.14.2",
|
|
14
14
|
"psycopg2-binary>=2.9.11",
|
|
15
|
+
"phlo-pandera>=0.17.0,<0.18",
|
|
16
|
+
"phlo-postgres>=0.18.0,<0.19",
|
|
15
17
|
"pydantic>=2.0",
|
|
16
18
|
"pyyaml>=6.0.1",
|
|
19
|
+
"sqlglot>=30.2.1,<31",
|
|
17
20
|
"uvicorn>=0.38.0",
|
|
18
21
|
]
|
|
19
22
|
description = "Phlo API - Backend service exposing Phlo internals to Observatory"
|
|
20
23
|
name = "phlo-api"
|
|
21
24
|
requires-python = ">=3.12"
|
|
22
|
-
version = "0.
|
|
25
|
+
version = "0.19.0"
|
|
23
26
|
|
|
24
27
|
[[project.authors]]
|
|
25
28
|
email = "team@phlo.dev"
|
|
@@ -32,16 +35,30 @@ phlo-api = "phlo_api.plugin:PhloApiServicePlugin"
|
|
|
32
35
|
text = "MIT"
|
|
33
36
|
|
|
34
37
|
[project.optional-dependencies]
|
|
38
|
+
dagster = ["phlo-dagster>=0.3.2"]
|
|
35
39
|
dev = [
|
|
36
40
|
"pytest>=7.0",
|
|
37
41
|
"ruff>=0.1.0",
|
|
38
42
|
]
|
|
43
|
+
dlt = ["phlo-dlt>=0.18.0,<0.19"]
|
|
44
|
+
iceberg = ["phlo-iceberg>=0.18.0,<0.19"]
|
|
39
45
|
lineage = ["phlo-lineage>=0.1.0"]
|
|
46
|
+
transform = ["phlo-transform>=0.2.0,<0.3"]
|
|
47
|
+
trino = ["phlo-trino>=0.18.0,<0.19"]
|
|
40
48
|
|
|
41
49
|
[project.readme]
|
|
42
50
|
content-type = "text/plain"
|
|
43
51
|
text = "Phlo API backend for Observatory."
|
|
44
52
|
|
|
53
|
+
[tool.mutmut]
|
|
54
|
+
only_mutate = ["src/phlo_api/observatory_api/trino.py"]
|
|
55
|
+
pytest_add_cli_args = [
|
|
56
|
+
"--confcutdir=.",
|
|
57
|
+
"--import-mode=importlib",
|
|
58
|
+
]
|
|
59
|
+
pytest_add_cli_args_test_selection = ["tests/test_trino_sql.py"]
|
|
60
|
+
source_paths = ["src/"]
|
|
61
|
+
|
|
45
62
|
[tool.ruff]
|
|
46
63
|
line-length = 100
|
|
47
64
|
target-version = "py312"
|
|
@@ -55,6 +72,7 @@ phlo_api = [
|
|
|
55
72
|
"Dockerfile",
|
|
56
73
|
"entrypoint.sh",
|
|
57
74
|
"observatory_api/**/*.py",
|
|
75
|
+
"sql/*.sql",
|
|
58
76
|
]
|
|
59
77
|
|
|
60
78
|
[tool.setuptools.package-dir]
|
|
@@ -1,45 +1,59 @@
|
|
|
1
|
-
|
|
1
|
+
# Native transform releases target GNU libc, matching the Dagster runtime.
|
|
2
|
+
FROM python:3.12-slim@sha256:a6e34c598f2467ed0e9a8d349809fcd8b5c603269512df273a0bb1784edc11b1 AS phlo-build-context
|
|
2
3
|
|
|
3
4
|
WORKDIR /opt/phlo-build-context
|
|
4
5
|
|
|
6
|
+
ARG PHLO_TRANSFORM_BINARY=
|
|
7
|
+
ARG PHLO_TRANSFORM_SHA256=
|
|
8
|
+
|
|
5
9
|
COPY . .
|
|
6
10
|
RUN set -eux; \
|
|
7
11
|
if [ -f entrypoint.sh ]; then entrypoint=entrypoint.sh; else entrypoint=phlo-api/entrypoint.sh; fi; \
|
|
8
12
|
install -m 0755 "$entrypoint" /opt/phlo-build-context/phlo-api-entrypoint.sh; \
|
|
9
|
-
mkdir -p /opt/phlo-build-context/wheelhouse
|
|
13
|
+
mkdir -p /opt/phlo-build-context/wheelhouse /opt/phlo-native; \
|
|
14
|
+
if [ -n "$PHLO_TRANSFORM_BINARY" ]; then \
|
|
15
|
+
test -n "$PHLO_TRANSFORM_SHA256"; \
|
|
16
|
+
printf '%s %s\n' "$PHLO_TRANSFORM_SHA256" "$PHLO_TRANSFORM_BINARY" > /tmp/phlo-transform.sha256; \
|
|
17
|
+
sha256sum -c /tmp/phlo-transform.sha256; \
|
|
18
|
+
install -m 0755 "$PHLO_TRANSFORM_BINARY" /opt/phlo-native/phlo-transform; \
|
|
19
|
+
fi
|
|
10
20
|
|
|
11
|
-
FROM python:3.12-
|
|
21
|
+
FROM python:3.12-slim@sha256:a6e34c598f2467ed0e9a8d349809fcd8b5c603269512df273a0bb1784edc11b1 AS runtime
|
|
12
22
|
|
|
13
23
|
WORKDIR /app
|
|
14
24
|
|
|
15
25
|
ARG PHLO_VERSION=
|
|
16
26
|
ARG PHLO_API_VERSION=
|
|
17
27
|
ARG PHLO_WHEELHOUSE=
|
|
28
|
+
ARG PHLO_API_EXTRAS=
|
|
29
|
+
|
|
30
|
+
ENV PHLO_API_EXTRAS=${PHLO_API_EXTRAS}
|
|
18
31
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
#
|
|
22
|
-
#
|
|
23
|
-
# hadolint ignore=
|
|
24
|
-
RUN
|
|
25
|
-
&&
|
|
26
|
-
&&
|
|
27
|
-
|
|
28
|
-
musl-dev \
|
|
32
|
+
RUN python -c 'import os; extras = set(filter(None, os.environ["PHLO_API_EXTRAS"].split(","))); unknown = extras - {"dagster", "dlt", "iceberg", "lineage", "transform", "trino"}; assert not unknown, f"Unsupported API provider extras: {sorted(unknown)}"'
|
|
33
|
+
|
|
34
|
+
# Match the existing GNU-native provider runtime rather than relying on musl shims.
|
|
35
|
+
# Apply Debian fixes even when the digest-pinned base predates them.
|
|
36
|
+
# hadolint ignore=DL3008
|
|
37
|
+
RUN apt-get update \
|
|
38
|
+
&& apt-get upgrade --no-install-recommends --yes \
|
|
39
|
+
&& apt-get install -y --no-install-recommends ca-certificates gcc libc6-dev \
|
|
40
|
+
&& rm -rf /var/lib/apt/lists/* \
|
|
29
41
|
&& pip install --no-cache-dir \
|
|
30
42
|
"setuptools==83.0.0" \
|
|
31
43
|
"wheel==0.47.0" \
|
|
32
|
-
"uv==0.
|
|
44
|
+
"uv==0.13.4"
|
|
33
45
|
|
|
34
46
|
COPY --from=phlo-build-context /opt/phlo-build-context/wheelhouse /opt/phlo-wheelhouse
|
|
35
47
|
|
|
36
48
|
# Phlo currently pins the unpublished observe packages by URL. uv requires
|
|
37
49
|
# transitive URL dependencies to be repeated as direct installation inputs.
|
|
50
|
+
# Keep the if block outside an && chain, which would disable set -e inside it.
|
|
38
51
|
RUN set -eux; \
|
|
39
52
|
PHLO_REQUIREMENT="phlo"; \
|
|
40
53
|
if [ -n "$PHLO_VERSION" ]; then PHLO_REQUIREMENT="phlo==$PHLO_VERSION"; fi; \
|
|
41
54
|
PHLO_API_REQUIREMENT="phlo-api"; \
|
|
42
|
-
if [ -n "$
|
|
55
|
+
if [ -n "${PHLO_API_EXTRAS:-}" ]; then PHLO_API_REQUIREMENT="phlo-api[$PHLO_API_EXTRAS]"; fi; \
|
|
56
|
+
if [ -n "$PHLO_API_VERSION" ]; then PHLO_API_REQUIREMENT="$PHLO_API_REQUIREMENT==$PHLO_API_VERSION"; fi; \
|
|
43
57
|
if [ -n "$PHLO_WHEELHOUSE" ]; then \
|
|
44
58
|
test -d /opt/phlo-wheelhouse; \
|
|
45
59
|
uv pip install --system --no-index --no-deps --reinstall --find-links /opt/phlo-wheelhouse "$PHLO_REQUIREMENT" "$PHLO_API_REQUIREMENT"; \
|
|
@@ -54,15 +68,20 @@ RUN set -eux; \
|
|
|
54
68
|
uv pip install --system --no-deps phlo; \
|
|
55
69
|
python -c 'import importlib.metadata as md; print("\n".join(r.split(";", 1)[0].strip() for r in (md.metadata("phlo").get_all("Requires-Dist") or []) if " @ " in r))' > /tmp/phlo-url-requirements.txt; \
|
|
56
70
|
uv pip install --system --requirement /tmp/phlo-url-requirements.txt phlo "$PHLO_API_REQUIREMENT"; \
|
|
57
|
-
fi
|
|
71
|
+
fi
|
|
58
72
|
|
|
59
73
|
# Do not retain uv's downloaded archives in the runtime image; they are not needed to run Phlo.
|
|
60
|
-
RUN
|
|
74
|
+
RUN apt-get purge -y --auto-remove gcc libc6-dev \
|
|
75
|
+
&& rm -rf /var/lib/apt/lists/* /root/.cache/uv
|
|
61
76
|
|
|
62
77
|
COPY --from=phlo-build-context /opt/phlo-build-context/phlo-api-entrypoint.sh /usr/local/bin/phlo-api-entrypoint.sh
|
|
78
|
+
COPY --from=phlo-build-context /opt/phlo-native/ /usr/local/bin/
|
|
79
|
+
|
|
80
|
+
# Reject an unusable approved binary in the final runtime, not on the first save.
|
|
81
|
+
RUN if [ -f /usr/local/bin/phlo-transform ]; then phlo-transform --version; fi
|
|
63
82
|
|
|
64
|
-
RUN
|
|
65
|
-
&&
|
|
83
|
+
RUN groupadd --system phlo \
|
|
84
|
+
&& useradd --system --gid phlo --home-dir /app --no-create-home phlo \
|
|
66
85
|
&& chown -R phlo:phlo /app
|
|
67
86
|
|
|
68
87
|
USER phlo
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""Compile bounded typed preview predicates without accepting SQL fragments."""
|
|
2
|
+
|
|
3
|
+
from typing import Annotated, Literal
|
|
4
|
+
|
|
5
|
+
from pydantic import (
|
|
6
|
+
BaseModel,
|
|
7
|
+
ConfigDict,
|
|
8
|
+
Field,
|
|
9
|
+
StrictBool,
|
|
10
|
+
StrictFloat,
|
|
11
|
+
StrictInt,
|
|
12
|
+
StrictStr,
|
|
13
|
+
TypeAdapter,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class ComparisonFilter(BaseModel):
|
|
18
|
+
model_config = ConfigDict(extra="forbid", allow_inf_nan=False)
|
|
19
|
+
column: str = Field(min_length=1, max_length=256)
|
|
20
|
+
operator: Literal["eq", "ne", "lt", "lte", "gt", "gte"]
|
|
21
|
+
value: StrictStr | StrictInt | StrictFloat | StrictBool
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class NullFilter(BaseModel):
|
|
25
|
+
model_config = ConfigDict(extra="forbid")
|
|
26
|
+
column: str = Field(min_length=1, max_length=256)
|
|
27
|
+
operator: Literal["is_null", "is_not_null"]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
PreviewFilter = ComparisonFilter | NullFilter
|
|
31
|
+
preview_filters = TypeAdapter(Annotated[list[PreviewFilter], Field(max_length=20)])
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def preview_where(filters: list[PreviewFilter], columns: set[str]) -> str:
|
|
35
|
+
predicates = []
|
|
36
|
+
operators = {"eq": "=", "ne": "<>", "lt": "<", "lte": "<=", "gt": ">", "gte": ">="}
|
|
37
|
+
for predicate in filters:
|
|
38
|
+
if predicate.column not in columns or "\x00" in predicate.column:
|
|
39
|
+
raise ValueError("Filter column is not in the selected table schema.")
|
|
40
|
+
column = '"' + predicate.column.replace('"', '""') + '"'
|
|
41
|
+
if isinstance(predicate, NullFilter):
|
|
42
|
+
expression = "IS NULL" if predicate.operator == "is_null" else "IS NOT NULL"
|
|
43
|
+
else:
|
|
44
|
+
value = predicate.value
|
|
45
|
+
if isinstance(value, str):
|
|
46
|
+
if len(value) > 2048 or "\x00" in value:
|
|
47
|
+
raise ValueError("Filter value exceeds the supported text budget.")
|
|
48
|
+
literal = "'" + value.replace("'", "''") + "'"
|
|
49
|
+
elif isinstance(value, bool):
|
|
50
|
+
literal = "TRUE" if value else "FALSE"
|
|
51
|
+
else:
|
|
52
|
+
literal = str(value)
|
|
53
|
+
expression = f"{operators[predicate.operator]} {literal}"
|
|
54
|
+
predicates.append(f"{column} {expression}")
|
|
55
|
+
return " WHERE " + " AND ".join(predicates) if predicates else ""
|
|
@@ -32,21 +32,20 @@ Example:
|
|
|
32
32
|
|
|
33
33
|
from __future__ import annotations
|
|
34
34
|
|
|
35
|
-
import os
|
|
36
|
-
from typing import Any
|
|
37
|
-
|
|
38
35
|
from fastapi import HTTPException, Request
|
|
39
|
-
|
|
40
36
|
from phlo.capabilities import (
|
|
37
|
+
AuthenticatedSession,
|
|
38
|
+
AuthenticationProvider,
|
|
41
39
|
AuthPrincipal,
|
|
42
40
|
AuthResult,
|
|
43
|
-
AuthenticationProvider,
|
|
44
41
|
RequestContext,
|
|
45
42
|
list_capabilities,
|
|
46
43
|
resolve_capability,
|
|
47
44
|
)
|
|
45
|
+
from phlo.config.process import get_process_settings
|
|
48
46
|
from phlo.infrastructure.config import get_configured_authentication_provider_name
|
|
49
47
|
from phlo.logging import get_logger
|
|
48
|
+
from phlo.security.oidc_identity import OIDCVerificationUnavailable
|
|
50
49
|
|
|
51
50
|
logger = get_logger(__name__)
|
|
52
51
|
|
|
@@ -108,6 +107,10 @@ def create_request_context(request: Request) -> RequestContext:
|
|
|
108
107
|
headers_dict: dict[str, str] = {}
|
|
109
108
|
for key, value in request.headers.items():
|
|
110
109
|
headers_dict[key.lower()] = value
|
|
110
|
+
if "authorization" not in headers_dict:
|
|
111
|
+
access_token = headers_dict.get("x-auth-request-access-token", "")
|
|
112
|
+
if access_token and "\r" not in access_token and "\n" not in access_token:
|
|
113
|
+
headers_dict["authorization"] = f"Bearer {access_token}"
|
|
111
114
|
cookies_dict = dict(request.cookies)
|
|
112
115
|
query_params_dict = dict(request.query_params)
|
|
113
116
|
|
|
@@ -134,6 +137,12 @@ def authenticate_request(request: Request) -> AuthResult:
|
|
|
134
137
|
if hasattr(request.state, _AUTH_RESULT_CACHE_KEY):
|
|
135
138
|
return request.state[_AUTH_RESULT_CACHE_KEY]
|
|
136
139
|
|
|
140
|
+
managed_account = _authenticate_managed_service_account(request)
|
|
141
|
+
if managed_account is not None:
|
|
142
|
+
request.state[_AUTH_RESULT_CACHE_KEY] = managed_account
|
|
143
|
+
request.state[_AUTH_PRINCIPAL_CACHE_KEY] = managed_account.principal
|
|
144
|
+
return managed_account
|
|
145
|
+
|
|
137
146
|
provider = get_authentication_provider()
|
|
138
147
|
if provider is None:
|
|
139
148
|
result = AuthResult(
|
|
@@ -144,7 +153,13 @@ def authenticate_request(request: Request) -> AuthResult:
|
|
|
144
153
|
return result
|
|
145
154
|
|
|
146
155
|
request_context = create_request_context(request)
|
|
147
|
-
|
|
156
|
+
try:
|
|
157
|
+
result = provider.authenticate(request_context)
|
|
158
|
+
except OIDCVerificationUnavailable as exc:
|
|
159
|
+
raise HTTPException(
|
|
160
|
+
status_code=503,
|
|
161
|
+
detail={"error": "service_unavailable", "reason": "oidc_verification_unavailable"},
|
|
162
|
+
) from exc
|
|
148
163
|
request.state[_AUTH_RESULT_CACHE_KEY] = result
|
|
149
164
|
return result
|
|
150
165
|
|
|
@@ -158,17 +173,68 @@ def get_request_principal(request: Request) -> AuthPrincipal | None:
|
|
|
158
173
|
if hasattr(request.state, _AUTH_PRINCIPAL_CACHE_KEY):
|
|
159
174
|
return request.state[_AUTH_PRINCIPAL_CACHE_KEY]
|
|
160
175
|
|
|
176
|
+
managed_account = _authenticate_managed_service_account(request)
|
|
177
|
+
if managed_account is not None:
|
|
178
|
+
request.state[_AUTH_RESULT_CACHE_KEY] = managed_account
|
|
179
|
+
request.state[_AUTH_PRINCIPAL_CACHE_KEY] = managed_account.principal
|
|
180
|
+
return managed_account.principal
|
|
181
|
+
|
|
161
182
|
provider = get_authentication_provider()
|
|
162
183
|
if provider is None:
|
|
163
184
|
request.state[_AUTH_PRINCIPAL_CACHE_KEY] = None
|
|
164
185
|
return None
|
|
165
186
|
|
|
166
|
-
|
|
167
|
-
|
|
187
|
+
try:
|
|
188
|
+
principal = provider.current_principal(create_request_context(request))
|
|
189
|
+
except OIDCVerificationUnavailable as exc:
|
|
190
|
+
raise HTTPException(
|
|
191
|
+
status_code=503,
|
|
192
|
+
detail={"error": "service_unavailable", "reason": "oidc_verification_unavailable"},
|
|
193
|
+
) from exc
|
|
168
194
|
request.state[_AUTH_PRINCIPAL_CACHE_KEY] = principal
|
|
169
195
|
return principal
|
|
170
196
|
|
|
171
197
|
|
|
198
|
+
def _authenticate_managed_service_account(request: Request) -> AuthResult | None:
|
|
199
|
+
"""Authenticate a Phlo-issued service secret against its stored hash."""
|
|
200
|
+
if not get_process_settings().phlo_identity_authority_enabled:
|
|
201
|
+
return None
|
|
202
|
+
authorization = request.headers.get("authorization", "")
|
|
203
|
+
if not authorization.startswith("Bearer "):
|
|
204
|
+
return None
|
|
205
|
+
|
|
206
|
+
from phlo.identity.authority import IdentityAuthority
|
|
207
|
+
from phlo.plugins.observatory_settings import StorageUnavailableError
|
|
208
|
+
|
|
209
|
+
try:
|
|
210
|
+
matched = IdentityAuthority().authenticate_service_token(authorization[7:])
|
|
211
|
+
except StorageUnavailableError as exc:
|
|
212
|
+
raise HTTPException(
|
|
213
|
+
status_code=503,
|
|
214
|
+
detail={"error": "service_unavailable", "reason": "identity_authority_unavailable"},
|
|
215
|
+
) from exc
|
|
216
|
+
if matched is None:
|
|
217
|
+
return None
|
|
218
|
+
|
|
219
|
+
subject, name = matched
|
|
220
|
+
principal = AuthPrincipal(
|
|
221
|
+
subject=subject,
|
|
222
|
+
principal_type="service",
|
|
223
|
+
issuer="phlo-identity-authority",
|
|
224
|
+
attributes={"name": name, "authentication_source": "phlo-service-account"},
|
|
225
|
+
)
|
|
226
|
+
return AuthResult(
|
|
227
|
+
authenticated=True,
|
|
228
|
+
principal=principal,
|
|
229
|
+
session=AuthenticatedSession(
|
|
230
|
+
principal=principal,
|
|
231
|
+
auth_method="bearer_token",
|
|
232
|
+
provider_name="phlo_identity_authority",
|
|
233
|
+
),
|
|
234
|
+
reason_code="authenticated",
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
|
|
172
238
|
def require_principal(request: Request) -> AuthPrincipal:
|
|
173
239
|
"""Get the authenticated principal from the request or raise 401.
|
|
174
240
|
|
|
@@ -184,19 +250,7 @@ def require_principal(request: Request) -> AuthPrincipal:
|
|
|
184
250
|
detail={"error": "unauthorized", "reason": "no_auth_result"},
|
|
185
251
|
)
|
|
186
252
|
|
|
187
|
-
|
|
188
|
-
result = request.state[_AUTH_RESULT_CACHE_KEY]
|
|
189
|
-
else:
|
|
190
|
-
provider = get_authentication_provider()
|
|
191
|
-
if provider is None:
|
|
192
|
-
logger.warning("authentication_provider_not_configured")
|
|
193
|
-
raise HTTPException(
|
|
194
|
-
status_code=401,
|
|
195
|
-
detail={"error": "unauthorized", "reason": "provider_unavailable"},
|
|
196
|
-
)
|
|
197
|
-
request_context = create_request_context(request)
|
|
198
|
-
result = provider.authenticate(request_context)
|
|
199
|
-
request.state[_AUTH_RESULT_CACHE_KEY] = result
|
|
253
|
+
result = authenticate_request(request)
|
|
200
254
|
|
|
201
255
|
if not result.authenticated:
|
|
202
256
|
logger.warning(
|
|
@@ -218,33 +272,3 @@ def require_principal(request: Request) -> AuthPrincipal:
|
|
|
218
272
|
|
|
219
273
|
request.state[_AUTH_PRINCIPAL_CACHE_KEY] = result.principal
|
|
220
274
|
return result.principal
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
def optional_authenticate(request: Request) -> AuthPrincipal | None:
|
|
224
|
-
"""Attempt to authenticate a request, returning None if not authenticated.
|
|
225
|
-
|
|
226
|
-
Unlike require_principal, this does not raise on failure.
|
|
227
|
-
"""
|
|
228
|
-
provider = get_authentication_provider()
|
|
229
|
-
if provider is None:
|
|
230
|
-
return None
|
|
231
|
-
|
|
232
|
-
request_context = create_request_context(request)
|
|
233
|
-
result = provider.authenticate(request_context)
|
|
234
|
-
|
|
235
|
-
if result.authenticated and result.principal is not None:
|
|
236
|
-
return result.principal
|
|
237
|
-
|
|
238
|
-
return None
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
def get_capabilities_metadata() -> dict[str, Any]:
|
|
242
|
-
"""Get metadata about available authentication capabilities."""
|
|
243
|
-
available_providers = list_capabilities("authentication_provider")
|
|
244
|
-
current_provider = os.environ.get(_AUTHENTICATION_PROVIDER_ENV)
|
|
245
|
-
|
|
246
|
-
return {
|
|
247
|
-
"available_providers": available_providers,
|
|
248
|
-
"current_provider": current_provider,
|
|
249
|
-
"environment_variable": _AUTHENTICATION_PROVIDER_ENV,
|
|
250
|
-
}
|