Skip to main content

windmill_api/apis/
dbt_api.rs

1/*
2 * Windmill API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: 1.776.0
7 * Contact: contact@windmill.dev
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`dbt_warehouse_exists`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DbtWarehouseExistsError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`get_dbt_warehouse`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetDbtWarehouseError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`record_dbt_run_progress`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum RecordDbtRunProgressError {
36    UnknownValue(serde_json::Value),
37}
38
39
40/// Job-scoped: needs a job token. For a project bringing its own `profiles.yml`, which names a warehouse only to say where its assets belong and never opens the connection.
41pub async fn dbt_warehouse_exists(configuration: &configuration::Configuration, workspace: &str, name: &str) -> Result<(), Error<DbtWarehouseExistsError>> {
42    let local_var_configuration = configuration;
43
44    let local_var_client = &local_var_configuration.client;
45
46    let local_var_uri_str = format!("{}/w/{workspace}/dbt/warehouse_exists/{name}", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace), name=crate::apis::urlencode(name));
47    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
48
49    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
50        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
51    }
52    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
53        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
54    };
55
56    let local_var_req = local_var_req_builder.build()?;
57    let local_var_resp = local_var_client.execute(local_var_req).await?;
58
59    let local_var_status = local_var_resp.status();
60    let local_var_content = local_var_resp.text().await?;
61
62    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
63        Ok(())
64    } else {
65        let local_var_entity: Option<DbtWarehouseExistsError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
66        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
67        Err(Error::ResponseError(local_var_error))
68    }
69}
70
71/// Job-scoped: needs a job token, because the response carries the warehouse's credentials. dbt is unpermissioned by design, so a running job reaches any warehouse the workspace configures.
72pub async fn get_dbt_warehouse(configuration: &configuration::Configuration, workspace: &str, name: &str) -> Result<models::DbtWarehouseConnection, Error<GetDbtWarehouseError>> {
73    let local_var_configuration = configuration;
74
75    let local_var_client = &local_var_configuration.client;
76
77    let local_var_uri_str = format!("{}/w/{workspace}/dbt/warehouse/{name}", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace), name=crate::apis::urlencode(name));
78    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
79
80    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
81        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
82    }
83    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
84        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
85    };
86
87    let local_var_req = local_var_req_builder.build()?;
88    let local_var_resp = local_var_client.execute(local_var_req).await?;
89
90    let local_var_status = local_var_resp.status();
91    let local_var_content = local_var_resp.text().await?;
92
93    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
94        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
95    } else {
96        let local_var_entity: Option<GetDbtWarehouseError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
97        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
98        Err(Error::ResponseError(local_var_error))
99    }
100}
101
102/// Job-scoped: needs a job token, and the job is taken from the token rather than the body. For workers with no database access.
103pub async fn record_dbt_run_progress(configuration: &configuration::Configuration, workspace: &str, record_dbt_run_progress_request_inner: Vec<models::RecordDbtRunProgressRequestInner>) -> Result<(), Error<RecordDbtRunProgressError>> {
104    let local_var_configuration = configuration;
105
106    let local_var_client = &local_var_configuration.client;
107
108    let local_var_uri_str = format!("{}/w/{workspace}/dbt/run_progress", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
109    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
110
111    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
112        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
113    }
114    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
115        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
116    };
117    local_var_req_builder = local_var_req_builder.json(&record_dbt_run_progress_request_inner);
118
119    let local_var_req = local_var_req_builder.build()?;
120    let local_var_resp = local_var_client.execute(local_var_req).await?;
121
122    let local_var_status = local_var_resp.status();
123    let local_var_content = local_var_resp.text().await?;
124
125    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
126        Ok(())
127    } else {
128        let local_var_entity: Option<RecordDbtRunProgressError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
129        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
130        Err(Error::ResponseError(local_var_error))
131    }
132}
133