pub mod applications;
pub mod artifact_storage;
pub mod cron;
pub mod document_ai;
pub mod error;
pub mod images;
pub mod sandbox_images;
pub mod sandbox_templates;
pub mod sandboxes;
pub mod secrets;
use applications::*;
use artifact_storage::*;
use cron::*;
use document_ai::*;
use images::*;
use sandbox_templates::*;
use sandboxes::*;
use secrets::*;
mod client;
pub use client::{Client, ClientBuilder, Traced};
pub fn resolve_sandbox_lifecycle_url(api_url: &str) -> String {
if let Ok(parsed) = url::Url::parse(api_url) {
let host = parsed.host_str().unwrap_or("");
if host == "localhost" || host == "127.0.0.1" {
return api_url.to_string();
}
if let Some(rest) = host.strip_prefix("api.") {
return format!("{}://sandbox.{}", parsed.scheme(), rest);
}
}
"https://sandbox.tensorlake.ai".to_string()
}
pub fn resolve_artifact_storage_url(api_url: &str) -> String {
artifact_storage::resolve_artifact_storage_url(api_url)
}
#[derive(Clone)]
pub struct Sdk {
client: Client,
api_url: String,
}
impl Sdk {
pub fn new(base_url: &str, bearer_token: &str) -> Result<Self, error::SdkError> {
let client = ClientBuilder::new(base_url)
.bearer_token(bearer_token)
.build()?;
Ok(Self {
client,
api_url: base_url.to_string(),
})
}
pub fn with_client_builder(builder: ClientBuilder) -> Result<Self, error::SdkError> {
let api_url = builder.base_url().to_string();
let client = builder.build()?;
Ok(Self { client, api_url })
}
pub fn applications(&self) -> ApplicationsClient {
ApplicationsClient::new(self.client.clone())
}
pub fn images(&self) -> ImagesClient {
ImagesClient::new(self.client.clone())
}
pub fn artifact_storage(&self) -> Result<ArtifactStorageClient, error::SdkError> {
ArtifactStorageClient::new(
self.client.clone(),
resolve_artifact_storage_url(&self.api_url),
)
}
pub fn artifact_storage_with_url(
&self,
git_base_url: &str,
) -> Result<ArtifactStorageClient, error::SdkError> {
ArtifactStorageClient::new(self.client.clone(), git_base_url)
}
pub fn sandbox_templates(
&self,
organization_id: &str,
project_id: &str,
) -> SandboxTemplatesClient {
SandboxTemplatesClient::new(
self.client.clone(),
organization_id.to_string(),
project_id.to_string(),
)
}
pub fn sandboxes(&self, namespace: &str, use_namespaced_endpoints: bool) -> SandboxesClient {
let lifecycle_client = self
.client
.with_base_url(&resolve_sandbox_lifecycle_url(&self.api_url));
SandboxesClient::new(
lifecycle_client,
namespace.to_string(),
use_namespaced_endpoints,
)
.with_log_client(self.client.clone())
}
pub fn document_ai(&self) -> DocumentAiClient {
DocumentAiClient::new(self.client.clone())
}
pub fn secrets(&self) -> SecretsClient {
SecretsClient::new(self.client.clone())
}
pub fn cron(&self) -> CronClient {
CronClient::new(self.client.clone())
}
}