runpod_sdk/service/registry.rs
1use std::future::Future;
2
3#[cfg(feature = "tracing")]
4use crate::TRACING_TARGET_SERVICE;
5use crate::model::{
6 ContainerRegistryAuth, ContainerRegistryAuthCreateInput, ContainerRegistryAuths,
7};
8use crate::{Result, RunpodClient};
9
10/// Trait for managing container registry authentication.
11///
12/// Provides methods for creating, listing, retrieving, and deleting container registry authentications.
13/// This trait is implemented on the [`RunpodClient`](crate::client::RunpodClient).
14pub trait RegistryService {
15 /// Creates a new container registry authentication.
16 ///
17 /// # Arguments
18 ///
19 /// * `input` - Configuration for the new container registry authentication
20 ///
21 /// # Returns
22 ///
23 /// Returns the created container registry authentication information.
24 ///
25 /// # Example
26 ///
27 /// ```no_run
28 /// # use runpod_sdk::{RunpodClient, RunpodConfig, Result};
29 /// # use runpod_sdk::model::ContainerRegistryAuthCreateInput;
30 /// # use runpod_sdk::service::RegistryService;
31 /// # async fn example() -> Result<()> {
32 /// let config = RunpodConfig::builder().with_api_key("your-api-key").build()?;
33 /// let client = RunpodClient::new(config)?;
34 ///
35 /// let input = ContainerRegistryAuthCreateInput {
36 /// name: "My Docker Credentials".to_string(),
37 /// username: "my_username".to_string(),
38 /// password: "my_password".to_string(),
39 /// };
40 ///
41 /// let auth = client.create_registry_auth(input).await?;
42 /// println!("Created auth: {}", auth.id);
43 /// # Ok(())
44 /// # }
45 /// ```
46 fn create_registry_auth(
47 &self,
48 input: ContainerRegistryAuthCreateInput,
49 ) -> impl Future<Output = Result<ContainerRegistryAuth>>;
50
51 /// Lists all container registry authentications.
52 ///
53 /// # Returns
54 ///
55 /// Returns a vector of all container registry authentications associated with the account.
56 ///
57 /// # Example
58 ///
59 /// ```no_run
60 /// # use runpod_sdk::{RunpodClient, RunpodConfig, Result};
61 /// # use runpod_sdk::service::RegistryService;
62 /// # async fn example() -> Result<()> {
63 /// let config = RunpodConfig::builder().with_api_key("your-api-key").build()?;
64 /// let client = RunpodClient::new(config)?;
65 ///
66 /// let auths = client.list_registry_auths().await?;
67 /// println!("Found {} auths", auths.len());
68 /// # Ok(())
69 /// # }
70 /// ```
71 fn list_registry_auths(&self) -> impl Future<Output = Result<ContainerRegistryAuths>>;
72
73 /// Gets a specific container registry authentication by ID.
74 ///
75 /// # Arguments
76 ///
77 /// * `auth_id` - The unique identifier of the container registry authentication
78 ///
79 /// # Returns
80 ///
81 /// Returns the container registry authentication information.
82 ///
83 /// # Example
84 ///
85 /// ```no_run
86 /// # use runpod_sdk::{RunpodClient, RunpodConfig, Result};
87 /// # use runpod_sdk::service::RegistryService;
88 /// # async fn example() -> Result<()> {
89 /// let config = RunpodConfig::builder().with_api_key("your-api-key").build()?;
90 /// let client = RunpodClient::new(config)?;
91 ///
92 /// let auth = client.get_registry_auth("auth_id").await?;
93 /// println!("Auth: {:?}", auth);
94 /// # Ok(())
95 /// # }
96 /// ```
97 fn get_registry_auth(
98 &self,
99 auth_id: &str,
100 ) -> impl Future<Output = Result<ContainerRegistryAuth>>;
101
102 /// Deletes a container registry authentication.
103 ///
104 /// This operation will permanently remove the container registry authentication.
105 ///
106 /// # Arguments
107 ///
108 /// * `auth_id` - The unique identifier of the authentication to delete
109 ///
110 /// # Example
111 ///
112 /// ```no_run
113 /// # use runpod_sdk::{RunpodClient, RunpodConfig, Result};
114 /// # use runpod_sdk::service::RegistryService;
115 /// # async fn example() -> Result<()> {
116 /// let config = RunpodConfig::builder().with_api_key("your-api-key").build()?;
117 /// let client = RunpodClient::new(config)?;
118 ///
119 /// client.delete_registry_auth("auth_id").await?;
120 /// println!("Auth deleted");
121 /// # Ok(())
122 /// # }
123 /// ```
124 fn delete_registry_auth(&self, auth_id: &str) -> impl Future<Output = Result<()>>;
125}
126
127impl RegistryService for RunpodClient {
128 async fn create_registry_auth(
129 &self,
130 input: ContainerRegistryAuthCreateInput,
131 ) -> Result<ContainerRegistryAuth> {
132 #[cfg(feature = "tracing")]
133 tracing::debug!(target: TRACING_TARGET_SERVICE, "Creating registry auth");
134
135 let response = self
136 .post("/containerregistryauth")
137 .json(&input)
138 .send()
139 .await?;
140 let response = response.error_for_status()?;
141 let auth: ContainerRegistryAuth = response.json().await?;
142
143 #[cfg(feature = "tracing")]
144 tracing::debug!(target: TRACING_TARGET_SERVICE, auth_id = %auth.id, "Registry auth created successfully");
145
146 Ok(auth)
147 }
148
149 async fn list_registry_auths(&self) -> Result<ContainerRegistryAuths> {
150 #[cfg(feature = "tracing")]
151 tracing::debug!(target: TRACING_TARGET_SERVICE, "Listing registry auths");
152
153 let response = self.get("/containerregistryauth").send().await?;
154 let response = response.error_for_status()?;
155 let auths: ContainerRegistryAuths = response.json().await?;
156
157 #[cfg(feature = "tracing")]
158 tracing::debug!(target: TRACING_TARGET_SERVICE, count = auths.len(), "Registry auths retrieved successfully");
159
160 Ok(auths)
161 }
162
163 async fn get_registry_auth(&self, auth_id: &str) -> Result<ContainerRegistryAuth> {
164 #[cfg(feature = "tracing")]
165 tracing::debug!(target: TRACING_TARGET_SERVICE, "Getting registry auth");
166
167 let path = format!("/containerregistryauth/{}", auth_id);
168 let response = self.get(&path).send().await?;
169 let response = response.error_for_status()?;
170 let auth: ContainerRegistryAuth = response.json().await?;
171
172 #[cfg(feature = "tracing")]
173 tracing::debug!(target: TRACING_TARGET_SERVICE, "Registry auth retrieved successfully");
174
175 Ok(auth)
176 }
177
178 async fn delete_registry_auth(&self, auth_id: &str) -> Result<()> {
179 #[cfg(feature = "tracing")]
180 tracing::debug!(target: TRACING_TARGET_SERVICE, "Deleting registry auth");
181
182 let path = format!("/containerregistryauth/{}", auth_id);
183 let response = self.delete(&path).send().await?;
184 response.error_for_status()?;
185
186 #[cfg(feature = "tracing")]
187 tracing::debug!(target: TRACING_TARGET_SERVICE, "Registry auth deleted successfully");
188
189 Ok(())
190 }
191}