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
94 changes: 94 additions & 0 deletions clients/typescript/src/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,22 @@ export interface paths {
patch?: never;
trace?: never;
};
"/api/control/locations/{location_id}/targets/{target}/providers": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
get: operations["readPersonProviders"];
put?: never;
post?: never;
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/api/control/locations/{location_id}/targets/{target}/runs": {
parameters: {
query?: never;
Expand Down Expand Up @@ -2374,6 +2390,46 @@ export interface components {
state_database?: string | null;
state_schema: string;
};
/** @description Code that injects a provider: a node (`loader`, `task`, `asset`, `check`, `hook` or `materialization`, keyed `kind:name`), an `event_exporter` or a `sink`. */
ProviderConsumer: {
kind: string;
name: string;
};
/** @description A provider as its location published it, from the class alone: never a setting value. */
ProviderRecord: {
/** @description The class as `module.qualname`. */
class: string;
/** @description The class docstring. */
description: string;
/** @description Jobs whose selection includes one of those nodes. */
jobs?: string[];
name: string;
/** @description Snapshot nodes that run that code: Python nodes, models calling a hook or using a materialization, and sources a loader fills. */
nodes?: string[];
/** @description The file declaring the class, relative to the project. */
path: string;
settings: components["schemas"]["ProviderSetting"][];
/** @description Code that injects the provider, in discovery order. */
used_by: components["schemas"]["ProviderConsumer"][];
};
/** @description One declared setting field; its value stays in the location's environment. */
ProviderSetting: {
description?: string | null;
/** @description The environment variable the setting is read from. */
env: string;
name: string;
required: boolean;
/** @description Whether the annotation is a pydantic secret type. */
secret: boolean;
/** @description The annotation as written, such as `str` or `SecretStr | None`. */
type: string;
};
/** @description Providers the current snapshot declares; empty before a publish or when the project has none. */
ProvidersRead: {
providers: components["schemas"]["ProviderRecord"][];
/** Format: uuid */
snapshot_id?: string | null;
};
/** @description A changed subject, such as `model:orders`, or `role:analyst` (`role:` for those who can't assign roles). */
PublishedChange: {
change_kind: string;
Expand Down Expand Up @@ -4857,6 +4913,44 @@ export interface operations {
};
};
};
readPersonProviders: {
parameters: {
query?: never;
header?: never;
path: {
location_id: string;
target: string;
};
cookie?: never;
};
requestBody?: never;
responses: {
/** @description Declared providers without setting values */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["ProvidersRead"];
};
};
/** @description Session rejected */
401: {
headers: {
[name: string]: unknown;
};
content?: never;
};
403: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["ApiErrorBody"];
};
};
};
};
listPersonRuns: {
parameters: {
query?: {
Expand Down
5 changes: 5 additions & 0 deletions crates/sqlbuild-host/src/entries/_helpers/user_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ pub(crate) const ENTRIES: &[HostEntry] = &[
kind: HostKind::Function,
edge: HostEdge::UserCode,
},
HostEntry {
name: "provider_settings",
kind: HostKind::Function,
edge: HostEdge::UserCode,
},
HostEntry {
name: "requires_arguments",
kind: HostKind::Function,
Expand Down
1 change: 1 addition & 0 deletions crates/sqlbuild-host/src/entries/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ pub enum UserCodeHost {
ModuleProviderClasses,
ParameterAnnotations,
ProviderUsages,
ProviderSettings,
RequiresArguments,
RestorePythonRootModules,
SourceLine,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ pub(crate) fn person_routes() -> Router<ControlStore> {
"/api/control/locations/{location_id}/targets/{target}/jobs/{job_key}",
get(crate::api::_helpers::resources::person_reads::job),
)
.route(
"/api/control/locations/{location_id}/targets/{target}/providers",
get(crate::api::_helpers::resources::person_reads::providers),
)
.route(
"/api/control/locations/{location_id}/targets/{target}/triggers",
get(crate::api::_helpers::resources::person_reads::triggers),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ use crate::declarations::main::list_person_jobs::list_person_jobs;
use crate::declarations::main::list_person_trigger_changes::list_person_trigger_changes;
use crate::declarations::main::list_person_triggers::list_person_triggers;
use crate::declarations::main::read_person_job::read_person_job;
use crate::declarations::main::read_person_providers::read_person_providers;
use crate::declarations::models::{
JobDetailRecord, JobRecord, PersonTriggerChange, PersonTriggerRecord,
JobDetailRecord, JobRecord, PersonTriggerChange, PersonTriggerRecord, ProvidersRead,
};
use crate::platform::main::list_person_platform_events::list_person_platform_events;
use crate::platform::main::read_person_location_health::read_person_location_health;
Expand Down Expand Up @@ -292,6 +293,27 @@ pub(crate) async fn jobs(
))
}

#[utoipa::path(get, path = "/api/control/locations/{location_id}/targets/{target}/providers", operation_id = "readPersonProviders",
params(("location_id" = Uuid, Path), ("target" = String, Path)),
responses((status = 200, body = ProvidersRead, description = "Declared providers without setting values"), (status = 401, description = "Session rejected"),
(status = 403, body = crate::api::models::ApiErrorBody)), security(("session" = []), ("cliSession" = [])))]
pub(crate) async fn providers(
(State(store), Extension(context)): (State<ControlStore>, Extension<AuditContext>),
Extension(default_role): Extension<DefaultRole>,
Path((location_id, target)): Path<(Uuid, String)>,
Extension(AuthenticatedPerson(principal, _)): Extension<AuthenticatedPerson>,
) -> Result<Json<ProvidersRead>, ApiError> {
Ok(Json(
read_person_providers(
&store,
(&context, principal),
(location_id, &target),
default_role,
)
.await?,
))
}

#[utoipa::path(get, path = "/api/control/locations/{location_id}/targets/{target}/triggers", operation_id = "listPersonTriggers",
params(("location_id" = Uuid, Path), ("target" = String, Path)),
responses((status = 200, body = Vec<PersonTriggerRecord>, description = "Published triggers with their newest tick"), (status = 401, description = "Session rejected"),
Expand Down
1 change: 1 addition & 0 deletions crates/sqlbuild-orchestration/src/api/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use crate::api::_helpers::resources::{
person_reads::run_node_error,
person_reads::jobs,
person_reads::job,
person_reads::providers,
person_reads::triggers,
person_reads::ticks,
person_reads::trigger_changes,
Expand Down
1 change: 1 addition & 0 deletions crates/sqlbuild-orchestration/src/declarations/main/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ pub mod list_triggers;
pub mod pause_development_triggers;
pub(crate) mod publish_definitions;
pub mod read_person_job;
pub mod read_person_providers;
pub mod snapshot_definitions;
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//! A person reads the providers of the current snapshot with view on every current node, like jobs.
use std::collections::BTreeSet;

use serde::Deserialize;
use uuid::Uuid;

use crate::authorization::main::authorize_listing::authorize_listing;
use crate::credentials::models::{AuditContext, DefaultRole};
use crate::declarations::_helpers::reads::jobs_in;
use crate::declarations::models::{ProviderRecord, ProvidersRead};
use crate::snapshots::main::read_current_record::read_current_record;
use crate::snapshots::main::read_snapshot_documents::read_snapshot_documents;
use crate::store::errors::ControlError;
use crate::store::main::{begin::begin, commit::commit};
use crate::store::models::{ControlStore, TransactionMode};

pub async fn read_person_providers(
store: &ControlStore,
credentials: (&AuditContext, Uuid),
(location_id, target): (Uuid, &str),
default_role: DefaultRole,
) -> Result<ProvidersRead, ControlError> {
let (transaction, _) = authorize_listing(
begin(store, TransactionMode::Write).await?,
credentials,
(location_id, target),
default_role,
)
.await?;
let (transaction, snapshot) = read_current_record(transaction, (location_id, target)).await?;
let Some(snapshot) = snapshot else {
commit(transaction).await?;
return Ok(ProvidersRead {
snapshot_id: None,
providers: Vec::new(),
});
};
let (transaction, documents) =
read_snapshot_documents(transaction, snapshot.snapshot_id, Some(&["providers"])).await?;
let (transaction, jobs) = jobs_in(transaction, (location_id, target)).await?;
commit(transaction).await?;
let mut providers = match documents.get("providers") {
Some(document) => Vec::<ProviderRecord>::deserialize(&document["providers"])
.map_err(|error| ControlError::Invalid(format!("providers document: {error}")))?,
None => Vec::new(),
};
for provider in &mut providers {
provider.jobs.clear();
let nodes: BTreeSet<&String> = provider.nodes.iter().collect();
for job in &jobs {
if job.selection.iter().any(|key| nodes.contains(key)) {
provider.jobs.push(job.job_key.clone());
}
}
}
Ok(ProvidersRead {
snapshot_id: Some(snapshot.snapshot_id),
providers,
})
}
50 changes: 50 additions & 0 deletions crates/sqlbuild-orchestration/src/declarations/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,53 @@ pub(crate) struct GroupWaits {
pub(crate) edges: BTreeMap<String, BTreeSet<String>>,
pub(crate) reasons: BTreeMap<(String, String), String>,
}

/// Providers the current snapshot declares; empty before a publish or when the project has none.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, utoipa::ToSchema)]
pub struct ProvidersRead {
pub snapshot_id: Option<uuid::Uuid>,
pub providers: Vec<ProviderRecord>,
}

/// A provider as its location published it, from the class alone: never a setting value.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, utoipa::ToSchema)]
pub struct ProviderRecord {
pub name: String,
/// The class as `module.qualname`.
pub class: String,
/// The class docstring.
pub description: String,
/// The file declaring the class, relative to the project.
pub path: String,
pub settings: Vec<ProviderSetting>,
/// Code that injects the provider, in discovery order.
pub used_by: Vec<ProviderConsumer>,
/// Snapshot nodes that run that code: Python nodes, models calling a hook or using a materialization, and sources a loader fills.
#[serde(default)]
pub nodes: Vec<String>,
/// Jobs whose selection includes one of those nodes.
#[serde(default)]
pub jobs: Vec<String>,
}

/// One declared setting field; its value stays in the location's environment.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, utoipa::ToSchema)]
pub struct ProviderSetting {
pub name: String,
/// The annotation as written, such as `str` or `SecretStr | None`.
#[serde(rename = "type")]
pub type_name: String,
pub required: bool,
/// Whether the annotation is a pydantic secret type.
pub secret: bool,
/// The environment variable the setting is read from.
pub env: String,
pub description: Option<String>,
}

/// Code that injects a provider: a node (`loader`, `task`, `asset`, `check`, `hook` or `materialization`, keyed `kind:name`), an `event_exporter` or a `sink`.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, utoipa::ToSchema)]
pub struct ProviderConsumer {
pub kind: String,
pub name: String,
}
2 changes: 2 additions & 0 deletions crates/sqlbuild-orchestration/tests/api/test_contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ mod test_person_location_work;
mod test_person_plans;
#[path = "test_person_sessions.rs"]
mod test_person_sessions;
#[path = "test_providers.rs"]
mod test_providers;
#[path = "test_proxy.rs"]
mod test_proxy;
#[path = "test_publish_encoding.rs"]
Expand Down
Loading
Loading