#![allow(clippy::uninlined_format_args)]
#![allow(dead_code)]
mod batch;
mod buckets;
mod multipart;
mod objects;
pub mod types;
pub use types::*;
use raps_kernel::auth::AuthClient;
use raps_kernel::config::Config;
use raps_kernel::http::HttpClientConfig;
#[derive(Clone)]
pub struct OssClient {
pub(crate) config: Config,
pub(crate) auth: AuthClient,
pub(crate) http_client: reqwest::Client,
}
impl OssClient {
pub fn new(config: Config, auth: AuthClient) -> Self {
Self::new_with_http_config(config, auth, HttpClientConfig::default())
}
pub fn new_with_http_config(
config: Config,
auth: AuthClient,
http_config: HttpClientConfig,
) -> Self {
let http_client = http_config
.create_client()
.unwrap_or_else(|_| reqwest::Client::new());
Self {
config,
auth,
http_client,
}
}
pub fn get_urn(&self, bucket_key: &str, object_key: &str) -> String {
use base64::Engine;
let object_id = format!("urn:adsk.objects:os.object:{}/{}", bucket_key, object_key);
base64::engine::general_purpose::URL_SAFE_NO_PAD.encode(object_id)
}
}
#[cfg(test)]
mod integration_tests {
use super::*;
use raps_kernel::auth::AuthClient;
use raps_kernel::config::Config;
fn create_mock_client(mock_url: &str) -> OssClient {
let config = Config {
client_id: "test-client-id".to_string(),
client_secret: "test-client-secret".to_string(),
base_url: mock_url.to_string(),
callback_url: "http://localhost:8080/callback".to_string(),
da_nickname: None,
http_config: HttpClientConfig::default(),
};
let auth = AuthClient::new(config.clone());
OssClient::new(config, auth)
}
#[tokio::test]
async fn test_client_creation() {
let server = raps_mock::TestServer::start_default().await.unwrap();
let client = create_mock_client(&server.url);
assert!(client.auth.config().base_url.starts_with("http://"));
}
}