Skip to main content

burn_central_client/artifact/
mod.rs

1pub mod request;
2pub mod response;
3
4use crate::{
5    Client, ClientError,
6    artifact::{
7        request::{
8            AddFilesToArtifactRequest, ArtifactFileSpecRequest, CompleteUploadRequest,
9            CreateArtifactRequest,
10        },
11        response::{
12            ArtifactAddFileResponse, ArtifactCreationResponse, ArtifactDownloadResponse,
13            ArtifactListResponse, ArtifactResponse,
14        },
15    },
16};
17
18impl Client {
19    /// Creates an artifact entry on the Burn Central server with the given files.
20    ///
21    /// The client must be logged in before calling this method.
22    pub fn create_artifact(
23        &self,
24        owner_name: &str,
25        project_name: &str,
26        exp_num: i32,
27        req: CreateArtifactRequest,
28    ) -> Result<ArtifactCreationResponse, ClientError> {
29        let url = self.join(&format!(
30            "projects/{owner_name}/{project_name}/experiments/{exp_num}/artifacts"
31        ));
32
33        self.post_json::<CreateArtifactRequest, ArtifactCreationResponse>(url, Some(req))
34    }
35
36    /// Add files to an existing artifact.
37    ///
38    /// The client must be logged in before calling this method.
39    pub fn add_files_to_artifact(
40        &self,
41        owner_name: &str,
42        project_name: &str,
43        exp_num: i32,
44        artifact_id: &str,
45        files: Vec<ArtifactFileSpecRequest>,
46    ) -> Result<ArtifactAddFileResponse, ClientError> {
47        let url = self.join(&format!(
48            "projects/{owner_name}/{project_name}/experiments/{exp_num}/artifacts/{artifact_id}/files"
49        ));
50
51        self.post_json::<AddFilesToArtifactRequest, ArtifactAddFileResponse>(
52            url,
53            Some(AddFilesToArtifactRequest { files }),
54        )
55    }
56
57    /// Complete an artifact upload.
58    ///
59    /// The client must be logged in before calling this method.
60    ///
61    /// If `file_names` is None, all files in the artifact will be marked as complete.
62    /// If `file_names` is Some, only the specified files will be marked as complete.
63    pub fn complete_artifact_upload(
64        &self,
65        owner_name: &str,
66        project_name: &str,
67        exp_num: i32,
68        artifact_id: &str,
69        file_names: Option<Vec<String>>,
70    ) -> Result<(), ClientError> {
71        let url = self.join(&format!(
72            "projects/{owner_name}/{project_name}/experiments/{exp_num}/artifacts/{artifact_id}/complete"
73        ));
74
75        let body = Some(CompleteUploadRequest { file_names });
76        self.post(url, body)
77    }
78
79    /// List artifacts for the given experiment.
80    ///
81    /// The client must be logged in before calling this method.
82    pub fn list_artifacts(
83        &self,
84        owner_name: &str,
85        project_name: &str,
86        exp_num: i32,
87    ) -> Result<ArtifactListResponse, ClientError> {
88        let url = self.join(&format!(
89            "projects/{owner_name}/{project_name}/experiments/{exp_num}/artifacts"
90        ));
91
92        self.get_json::<ArtifactListResponse>(url)
93    }
94
95    /// Query artifacts by name for the given experiment.
96    ///
97    /// The client must be logged in before calling this method.
98    pub fn list_artifacts_by_name(
99        &self,
100        owner_name: &str,
101        project_name: &str,
102        exp_num: i32,
103        name: &str,
104    ) -> Result<ArtifactListResponse, ClientError> {
105        let mut url = self.join(&format!(
106            "projects/{owner_name}/{project_name}/experiments/{exp_num}/artifacts"
107        ));
108        url.query_pairs_mut().append_pair("name", name);
109
110        self.get_json::<ArtifactListResponse>(url)
111    }
112
113    /// Get details about a specific artifact by its ID.
114    ///
115    /// The client must be logged in before calling this method.
116    pub fn get_artifact(
117        &self,
118        owner_name: &str,
119        project_name: &str,
120        exp_num: i32,
121        artifact_id: &str,
122    ) -> Result<ArtifactResponse, ClientError> {
123        let url = self.join(&format!(
124            "projects/{owner_name}/{project_name}/experiments/{exp_num}/artifacts/{artifact_id}"
125        ));
126
127        self.get_json::<ArtifactResponse>(url)
128    }
129
130    /// Request presigned URLs to download an artifact's files from the Burn Central server.
131    ///
132    /// The client must be logged in before calling this method.
133    pub fn presign_artifact_download(
134        &self,
135        owner_name: &str,
136        project_name: &str,
137        exp_num: i32,
138        artifact_id: &str,
139    ) -> Result<ArtifactDownloadResponse, ClientError> {
140        let url = self.join(&format!(
141            "projects/{owner_name}/{project_name}/experiments/{exp_num}/artifacts/{artifact_id}/download"
142        ));
143
144        self.get_json::<ArtifactDownloadResponse>(url)
145    }
146}