1 use crate::url_builder::build_project_url;
2 use anyhow::Result;
3 use reqwest::Client;
4 use smbcloud_model::{
5 error_codes::ErrorResponse,
6 project::{Project, ProjectCreate},
7 };
8 use smbcloud_network::{environment::Environment, network::request};
9 use smbcloud_networking::{constants::SMB_USER_AGENT, smb_client::SmbClient};
10
11 /// `tenant_id` selects which tenant the project is created under, via the
12 /// `X-Smbcloud-Tenant-Id` header — the API falls back to the user's personal
13 /// tenant when it's absent, so this is the only way to create a project under
14 /// an organization tenant.
15 pub async fn create_project(
16 env: Environment,
17 client: (&SmbClient, &str),
18 access_token: String,
19 project: ProjectCreate,
20 tenant_id: Option<String>,
21 ) -> Result<Project, ErrorResponse> {
22 let mut builder = Client::new()
23 .post(build_project_url(env, client))
24 .json(&project)
25 .header("Authorization", access_token)
26 .header("User-agent", SMB_USER_AGENT);
27 if let Some(tenant_id) = tenant_id {
28 builder = builder.header("X-Smbcloud-Tenant-Id", tenant_id);
29 }
30 request(builder).await
31 }