olai-uc-server 0.0.5

Unity Catalog REST server with pluggable storage backends.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
use crate::api::{
    AgentHandler, AgentSkillHandler, CatalogHandler, CredentialHandler, EntityTagAssignmentHandler,
    ExternalLocationHandler, FunctionHandler, ModelVersionHandler, PolicyHandler, ProviderHandler,
    RecipientHandler, RegisteredModelHandler, SchemaHandler, ShareHandler, StagingTableHandler,
    TableHandler, TagPolicyHandler, TemporaryCredentialHandler, VolumeHandler,
};
use axum::routing::{delete, get, patch, post};

/// Router for the UC Delta v1 API (`/delta/v1/...`).
///
/// The `unitycatalog-delta-api` crate builds a state-agnostic router from a handler
/// plus a context extractor; here we supply the same `Principal → RequestContext`
/// extraction the auth middleware + [`RequestContext`](crate::api::RequestContext)
/// extractor perform elsewhere (read the [`Principal`](crate::policy::Principal)
/// that `AuthenticationMiddleware` inserted into the request extensions, falling
/// back to anonymous). Returns a fully-stated `Router<()>` so it `.merge`s into the
/// rest of the server's router tree unchanged.
// The extractor's `Err` is an axum `Response` (never produced here — extraction is
// infallible with an anonymous fallback), so the size lint does not apply.
#[allow(clippy::result_large_err)]
pub fn create_delta_router(
    handler: crate::services::ServerHandler<crate::api::RequestContext>,
) -> axum::Router {
    use std::sync::Arc;

    use unitycatalog_delta_api::router::{ContextExtractor, router_with_context};

    use crate::api::RequestContext;
    use crate::policy::Principal;

    let extract_cx: ContextExtractor<RequestContext> = Arc::new(|parts| {
        let recipient = parts
            .extensions
            .get::<Principal>()
            .cloned()
            .unwrap_or_else(Principal::anonymous);
        Box::pin(async move { Ok(RequestContext { recipient }) })
    });
    router_with_context::<(), _>(Arc::new(handler), extract_cx).with_state(())
}

/// Router for the same-origin storage byte-proxy (`/storage-proxy/{securable}/{*key}`).
///
/// Mirrors [`create_delta_router`]: the `unitycatalog-storage-proxy` crate builds a
/// state-agnostic router from a [`StorageProxyBackend`] plus the same
/// `Principal → RequestContext` extractor, and we hand it the local-arm backend
/// (`ServerHandler`, which implements the port). Returns a fully-stated `Router<()>`
/// mounted at the default `/storage-proxy` base, so it `.merge`s at the server root.
///
/// [`StorageProxyBackend`]: unitycatalog_storage_proxy::StorageProxyBackend
#[cfg(feature = "bin")]
#[allow(clippy::result_large_err)]
pub fn create_storage_proxy_router(
    handler: crate::services::ServerHandler<crate::api::RequestContext>,
) -> axum::Router {
    use std::sync::Arc;

    use unitycatalog_storage_proxy::{ContextExtractor, router_with_context};

    use crate::api::RequestContext;
    use crate::policy::Principal;

    let extract_cx: ContextExtractor<RequestContext> = Arc::new(|parts| {
        let recipient = parts
            .extensions
            .get::<Principal>()
            .cloned()
            .unwrap_or_else(Principal::anonymous);
        Box::pin(async move { Ok(RequestContext { recipient }) })
    });
    router_with_context::<(), _>(Arc::new(handler), extract_cx).with_state(())
}

pub fn create_catalogs_router<T, Cx>(handler: T) -> axum::Router
where
    T: CatalogHandler<Cx> + Clone,
    Cx: axum::extract::FromRequestParts<T> + Send + 'static,
{
    use crate::codegen::catalogs::server::*;

    axum::Router::new()
        .route("/catalogs", get(list_catalogs::<T, Cx>))
        .route("/catalogs", post(create_catalog::<T, Cx>))
        .route("/catalogs/{name}", get(get_catalog::<T, Cx>))
        .route("/catalogs/{name}", patch(update_catalog::<T, Cx>))
        .route("/catalogs/{name}", delete(delete_catalog::<T, Cx>))
        .with_state(handler)
}

pub fn create_credentials_router<T, Cx>(handler: T) -> axum::Router
where
    T: CredentialHandler<Cx> + Clone,
    Cx: axum::extract::FromRequestParts<T> + Send + 'static,
{
    use crate::codegen::credentials::server::*;

    axum::Router::new()
        .route("/credentials", get(list_credentials::<T, Cx>))
        .route("/credentials", post(create_credential::<T, Cx>))
        .route("/credentials/{name}", get(get_credential::<T, Cx>))
        .route("/credentials/{name}", patch(update_credential::<T, Cx>))
        .route("/credentials/{name}", delete(delete_credential::<T, Cx>))
        .with_state(handler)
}

pub fn create_external_locations_router<T, Cx>(handler: T) -> axum::Router
where
    T: ExternalLocationHandler<Cx> + Clone,
    Cx: axum::extract::FromRequestParts<T> + Send + 'static,
{
    use crate::codegen::external_locations::server::*;

    axum::Router::new()
        .route("/external-locations", get(list_external_locations::<T, Cx>))
        .route(
            "/external-locations",
            post(create_external_location::<T, Cx>),
        )
        .route(
            "/external-locations/{name}",
            get(get_external_location::<T, Cx>),
        )
        .route(
            "/external-locations/{name}",
            patch(update_external_location::<T, Cx>),
        )
        .route(
            "/external-locations/{name}",
            delete(delete_external_location::<T, Cx>),
        )
        .with_state(handler)
}

pub fn create_recipients_router<T, Cx>(handler: T) -> axum::Router
where
    T: RecipientHandler<Cx> + Clone,
    Cx: axum::extract::FromRequestParts<T> + Send + 'static,
{
    use crate::codegen::recipients::server::*;

    axum::Router::new()
        .route("/recipients", get(list_recipients::<T, Cx>))
        .route("/recipients", post(create_recipient::<T, Cx>))
        .route("/recipients/{name}", get(get_recipient::<T, Cx>))
        .route("/recipients/{name}", patch(update_recipient::<T, Cx>))
        .route("/recipients/{name}", delete(delete_recipient::<T, Cx>))
        .with_state(handler)
}

pub fn create_providers_router<T, Cx>(handler: T) -> axum::Router
where
    T: ProviderHandler<Cx> + Clone,
    Cx: axum::extract::FromRequestParts<T> + Send + 'static,
{
    use crate::codegen::providers::server::*;

    axum::Router::new()
        .route("/providers", get(list_providers::<T, Cx>))
        .route("/providers", post(create_provider::<T, Cx>))
        .route("/providers/{name}", get(get_provider::<T, Cx>))
        .route("/providers/{name}", patch(update_provider::<T, Cx>))
        .route("/providers/{name}", delete(delete_provider::<T, Cx>))
        .with_state(handler)
}

pub fn create_schemas_router<T, Cx>(handler: T) -> axum::Router
where
    T: SchemaHandler<Cx> + Clone,
    Cx: axum::extract::FromRequestParts<T> + Send + 'static,
{
    use crate::codegen::schemas::server::*;

    axum::Router::new()
        .route("/schemas", get(list_schemas::<T, Cx>))
        .route("/schemas", post(create_schema::<T, Cx>))
        .route("/schemas/{name}", get(get_schema::<T, Cx>))
        .route("/schemas/{name}", patch(update_schema::<T, Cx>))
        .route("/schemas/{name}", delete(delete_schema::<T, Cx>))
        .with_state(handler)
}

pub fn create_staging_tables_router<T, Cx>(handler: T) -> axum::Router
where
    T: StagingTableHandler<Cx> + Clone,
    Cx: axum::extract::FromRequestParts<T> + Send + 'static,
{
    use crate::codegen::staging_tables::server::*;

    axum::Router::new()
        .route("/staging-tables", post(create_staging_table::<T, Cx>))
        .with_state(handler)
}

pub fn create_shares_router<T, Cx>(handler: T) -> axum::Router
where
    T: ShareHandler<Cx> + Clone,
    Cx: axum::extract::FromRequestParts<T> + Send + 'static,
{
    use crate::codegen::shares::server::*;

    axum::Router::new()
        .route("/shares", get(list_shares::<T, Cx>))
        .route("/shares", post(create_share::<T, Cx>))
        .route("/shares/{name}", get(get_share::<T, Cx>))
        .route("/shares/{name}", patch(update_share::<T, Cx>))
        .route("/shares/{name}", delete(delete_share::<T, Cx>))
        .route("/shares/{name}/permissions", get(get_permissions::<T, Cx>))
        .route(
            "/shares/{name}/permissions",
            patch(update_permissions::<T, Cx>),
        )
        .with_state(handler)
}

pub fn create_tables_router<T, Cx>(handler: T) -> axum::Router
where
    T: TableHandler<Cx> + Clone,
    Cx: axum::extract::FromRequestParts<T> + Send + 'static,
{
    use crate::codegen::tables::server::*;

    axum::Router::new()
        .route("/table-summaries", get(list_table_summaries::<T, Cx>))
        .route("/tables", get(list_tables::<T, Cx>))
        .route("/tables", post(create_table::<T, Cx>))
        .route("/tables/{full_name}", get(get_table::<T, Cx>))
        .route("/tables/{full_name}/exists", get(get_table_exists::<T, Cx>))
        .route("/tables/{full_name}", delete(delete_table::<T, Cx>))
        .with_state(handler)
}

pub fn create_temporary_credentials_router<T, Cx>(handler: T) -> axum::Router
where
    T: TemporaryCredentialHandler<Cx> + Clone,
    Cx: axum::extract::FromRequestParts<T> + Send + 'static,
{
    use crate::codegen::temporary_credentials::server::*;

    axum::Router::new()
        .route(
            "/temporary-table-credentials",
            post(generate_temporary_table_credentials::<T, Cx>),
        )
        .route(
            "/temporary-path-credentials",
            post(generate_temporary_path_credentials::<T, Cx>),
        )
        .route(
            "/temporary-volume-credentials",
            post(generate_temporary_volume_credentials::<T, Cx>),
        )
        .route(
            "/temporary-model-version-credentials",
            post(generate_temporary_model_version_credentials::<T, Cx>),
        )
        .with_state(handler)
}

pub fn create_registered_models_router<T, Cx>(handler: T) -> axum::Router
where
    T: RegisteredModelHandler<Cx> + Clone,
    Cx: axum::extract::FromRequestParts<T> + Send + 'static,
{
    use crate::codegen::registered_models::server::*;

    axum::Router::new()
        .route("/models", get(list_registered_models::<T, Cx>))
        .route("/models", post(create_registered_model::<T, Cx>))
        .route("/models/{full_name}", get(get_registered_model::<T, Cx>))
        .route(
            "/models/{full_name}",
            patch(update_registered_model::<T, Cx>),
        )
        .route(
            "/models/{full_name}",
            delete(delete_registered_model::<T, Cx>),
        )
        .with_state(handler)
}

pub fn create_model_versions_router<T, Cx>(handler: T) -> axum::Router
where
    T: ModelVersionHandler<Cx> + Clone,
    Cx: axum::extract::FromRequestParts<T> + Send + 'static,
{
    use crate::codegen::model_versions::server::*;

    axum::Router::new()
        .route("/models/versions", post(create_model_version::<T, Cx>))
        .route(
            "/models/{full_name}/versions",
            get(list_model_versions::<T, Cx>),
        )
        .route(
            "/models/{full_name}/versions/{version}",
            get(get_model_version::<T, Cx>),
        )
        .route(
            "/models/{full_name}/versions/{version}",
            patch(update_model_version::<T, Cx>),
        )
        .route(
            "/models/{full_name}/versions/{version}",
            delete(delete_model_version::<T, Cx>),
        )
        .route(
            "/models/{full_name}/versions/{version}/finalize",
            patch(finalize_model_version::<T, Cx>),
        )
        .with_state(handler)
}

pub fn create_volumes_router<T, Cx>(handler: T) -> axum::Router
where
    T: VolumeHandler<Cx> + Clone,
    Cx: axum::extract::FromRequestParts<T> + Send + 'static,
{
    use crate::codegen::volumes::server::*;

    axum::Router::new()
        .route("/volumes", get(list_volumes::<T, Cx>))
        .route("/volumes", post(create_volume::<T, Cx>))
        .route("/volumes/{name}", get(get_volume::<T, Cx>))
        .route("/volumes/{name}", patch(update_volume::<T, Cx>))
        .route("/volumes/{name}", delete(delete_volume::<T, Cx>))
        .with_state(handler)
}

pub fn create_agent_skills_router<T, Cx>(handler: T) -> axum::Router
where
    T: AgentSkillHandler<Cx> + Clone,
    Cx: axum::extract::FromRequestParts<T> + Send + 'static,
{
    use crate::codegen::agent_skills::server::*;

    axum::Router::new()
        .route("/agent-skills", get(list_agent_skills::<T, Cx>))
        .route("/agent-skills", post(create_agent_skill::<T, Cx>))
        .route("/agent-skills/{name}", get(get_agent_skill::<T, Cx>))
        .route("/agent-skills/{name}", patch(update_agent_skill::<T, Cx>))
        .route("/agent-skills/{name}", delete(delete_agent_skill::<T, Cx>))
        .with_state(handler)
}

pub fn create_agents_router<T, Cx>(handler: T) -> axum::Router
where
    T: AgentHandler<Cx> + Clone,
    Cx: axum::extract::FromRequestParts<T> + Send + 'static,
{
    use crate::codegen::agents::server::*;

    axum::Router::new()
        .route("/agents", get(list_agents::<T, Cx>))
        .route("/agents", post(create_agent::<T, Cx>))
        .route("/agents/{name}", get(get_agent::<T, Cx>))
        .route("/agents/{name}", patch(update_agent::<T, Cx>))
        .route("/agents/{name}", delete(delete_agent::<T, Cx>))
        .with_state(handler)
}

pub fn create_functions_router<T, Cx>(handler: T) -> axum::Router
where
    T: FunctionHandler<Cx> + Clone,
    Cx: axum::extract::FromRequestParts<T> + Send + 'static,
{
    use crate::codegen::functions::server::*;

    axum::Router::new()
        .route("/functions", get(list_functions::<T, Cx>))
        .route("/functions", post(create_function::<T, Cx>))
        .route("/functions/{name}", get(get_function::<T, Cx>))
        .route("/functions/{name}", patch(update_function::<T, Cx>))
        .route("/functions/{name}", delete(delete_function::<T, Cx>))
        .with_state(handler)
}

/// Router for the ABAC Policies API (row-filter / column-mask policies bound to securables).
pub fn create_policies_router<T, Cx>(handler: T) -> axum::Router
where
    T: PolicyHandler<Cx> + Clone,
    Cx: axum::extract::FromRequestParts<T> + Send + 'static,
{
    use crate::codegen::policies::server::*;

    axum::Router::new()
        .route(
            "/policies/{on_securable_type}/{on_securable_fullname}",
            get(list_policies::<T, Cx>),
        )
        .route(
            "/policies/{on_securable_type}/{on_securable_fullname}",
            post(create_policy::<T, Cx>),
        )
        .route(
            "/policies/{on_securable_type}/{on_securable_fullname}/{name}",
            get(get_policy::<T, Cx>),
        )
        .route(
            "/policies/{on_securable_type}/{on_securable_fullname}/{name}",
            patch(update_policy::<T, Cx>),
        )
        .route(
            "/policies/{on_securable_type}/{on_securable_fullname}/{name}",
            delete(delete_policy::<T, Cx>),
        )
        .with_state(handler)
}

/// Router for the Tag Policies (governed tag definitions) API.
///
/// Unlike the Unity Catalog securable APIs, these routes live under `/api/2.1/tag-policies`
/// (not `/api/2.1/unity-catalog/...`), so this router is mounted at a distinct base by the
/// server setup.
pub fn create_tag_policies_router<T, Cx>(handler: T) -> axum::Router
where
    T: TagPolicyHandler<Cx> + Clone,
    Cx: axum::extract::FromRequestParts<T> + Send + 'static,
{
    use crate::codegen::tag_policies::server::*;

    axum::Router::new()
        .route("/tag-policies", get(list_tag_policies::<T, Cx>))
        .route("/tag-policies", post(create_tag_policy::<T, Cx>))
        .route("/tag-policies/{tag_key}", get(get_tag_policy::<T, Cx>))
        .route("/tag-policies/{tag_key}", patch(update_tag_policy::<T, Cx>))
        .route(
            "/tag-policies/{tag_key}",
            delete(delete_tag_policy::<T, Cx>),
        )
        .with_state(handler)
}

/// Router for the Entity Tag Assignments API (applying tags to UC securables).
///
/// These routes live under the Unity Catalog surface
/// (`/api/2.1/unity-catalog/entity-tag-assignments/...`), so this router is merged into the
/// `unity-catalog`-nested route set.
pub fn create_entity_tag_assignments_router<T, Cx>(handler: T) -> axum::Router
where
    T: EntityTagAssignmentHandler<Cx> + Clone,
    Cx: axum::extract::FromRequestParts<T> + Send + 'static,
{
    use crate::codegen::entity_tag_assignments::server::*;

    axum::Router::new()
        .route(
            "/entity-tag-assignments",
            post(create_entity_tag_assignment::<T, Cx>),
        )
        .route(
            "/entity-tag-assignments/{entity_type}/{entity_name}/tags",
            get(list_entity_tag_assignments::<T, Cx>),
        )
        .route(
            "/entity-tag-assignments/{entity_type}/{entity_name}/tags/{tag_key}",
            get(get_entity_tag_assignment::<T, Cx>),
        )
        .route(
            "/entity-tag-assignments/{entity_type}/{entity_name}/tags/{tag_key}",
            patch(update_entity_tag_assignment::<T, Cx>),
        )
        .route(
            "/entity-tag-assignments/{entity_type}/{entity_name}/tags/{tag_key}",
            delete(delete_entity_tag_assignment::<T, Cx>),
        )
        .with_state(handler)
}