volcengine_rust_sdk/service/iam/
service_iam.rs

1/*
2 * @Author: Jerry.Yang
3 * @Date: 2024-10-17 15:59:58
4 * @LastEditors: Jerry.Yang
5 * @LastEditTime: 2025-02-05 19:16:39
6 * @Description: IAM (Identity and Access Management) Service
7 */
8use crate::service::iam::api_attach_user_policy;
9use crate::service::iam::api_create_login_profile;
10use crate::service::iam::api_create_policy;
11use crate::service::iam::api_create_project;
12use crate::service::iam::api_create_user;
13use crate::service::iam::api_delete_login_profile;
14use crate::service::iam::api_delete_policy;
15use crate::service::iam::api_delete_user;
16use crate::service::iam::api_detach_user_policy;
17use crate::service::iam::api_get_login_profile;
18use crate::service::iam::api_get_policy;
19use crate::service::iam::api_get_project;
20use crate::service::iam::api_get_security_config;
21use crate::service::iam::api_get_user;
22use crate::service::iam::api_list_attach_user_policy;
23use crate::service::iam::api_list_policy;
24use crate::service::iam::api_set_security_config;
25use crate::service::iam::api_update_login_profile;
26use crate::service::iam::api_update_policy;
27use crate::service::iam::api_update_user;
28use crate::service::iam::{Iam, IamService};
29use crate::volcengine::client::client;
30use crate::volcengine::client::client_info;
31use crate::volcengine::client::config as client_config;
32use crate::volcengine::common;
33use crate::volcengine::error::error;
34use crate::volcengine::request::handles;
35use crate::volcengine::session::session;
36
37/// Implementation of the `IamService` trait for the `Iam` struct.
38/// This implementation provides concrete functionality for all the methods defined in the `IamService` trait.
39/// By implementing this trait, the `Iam` struct can be used to interact with the Identity and Access Management (IAM) service,
40/// performing operations such as creating users, managing policies, and handling security configurations.
41impl IamService for Iam {
42    /// new_iam
43    ///
44    /// This method initializes a new IAM service instance with the provided session.
45    /// It sets up client configuration, client info, and handles, and builds a client for communication with the IAM service.
46    ///
47    /// # Parameters
48    /// - `session`: The session that will be used to create the IAM service.
49    ///
50    /// # Returns
51    /// Returns a result containing the new `Iam` service instance or an error.
52    fn new_iam(session: session::Session) -> Result<Self, error::Error> {
53        // Create new client configuration using the session
54        let client_config = session.new_client_config(client_config::ClientServiceName::Iam);
55
56        // Set up the client information, including service name and API version
57        let client_info = client_info::ClientInfo::builder()
58            .with_service_name(client_config::ClientServiceName::Iam)
59            .with_api_version(common::COMMON_VERSION)
60            .with_signing_region(&client_config.signing_region)
61            .build()?;
62
63        // Create request handles (for managing requests and responses)
64        let request_handles = handles::Handles {};
65
66        // Build the client with the necessary configuration and client info
67        let client = client::Client::builder()
68            .with_client_info(&client_info)
69            .with_config(&client_config)
70            .with_handles(&request_handles)
71            .build()?;
72
73        // Return the newly created IAM service instance
74        Ok(Iam { client: client })
75    }
76
77    /// new_create_user
78    ///
79    /// This method creates a new user in the IAM system using the provided request parameters.
80    ///
81    /// # Parameters
82    /// - `request`: The request object containing the details for creating the user.
83    ///
84    /// # Returns
85    /// Returns a result containing the response object for creating the user or an error.
86    async fn new_create_user(
87        &self,
88        request: volcengine_sdk_protobuf::protobuf::iam_user::CreateUserReq,
89    ) -> Result<volcengine_sdk_protobuf::protobuf::iam_user::CreateUserResp, error::Error> {
90        // Delegate to the API for creating the user
91        api_create_user::ApiCreateUserIam
92            .new_create_user(self, request)
93            .await
94    }
95
96    /// new_get_user
97    ///
98    /// This method retrieves the details of an existing user from the IAM system.
99    ///
100    /// # Parameters
101    /// - `request`: The request object containing the details for retrieving the user.
102    ///
103    /// # Returns
104    /// Returns a result containing the response object with user details or an error.
105    async fn new_get_user(
106        &self,
107        request: volcengine_sdk_protobuf::protobuf::iam_user::GetUserReq,
108    ) -> Result<volcengine_sdk_protobuf::protobuf::iam_user::GetUserResp, error::Error> {
109        // Delegate to the API for retrieving the user
110        api_get_user::ApiGetUserIam
111            .new_get_user(self, request)
112            .await
113    }
114
115    /// new_update_user
116    ///
117    /// This method updates an existing user's details in the IAM system.
118    ///
119    /// # Parameters
120    /// - `request`: The request object containing the details for updating the user.
121    ///
122    /// # Returns
123    /// Returns a result containing the response object for updating the user or an error.
124    async fn new_update_user(
125        &self,
126        request: volcengine_sdk_protobuf::protobuf::iam_user::UpdateUserReq,
127    ) -> Result<volcengine_sdk_protobuf::protobuf::iam_user::UpdateUserResp, error::Error> {
128        // Delegate to the API for updating the user
129        api_update_user::ApiUpdateUserIam
130            .new_update_user(self, request)
131            .await
132    }
133
134    /// new_create_login_profile
135    ///
136    /// This method creates a login profile for an existing user in the IAM system.
137    ///
138    /// # Parameters
139    /// - `request`: The request object containing the details for creating the login profile.
140    ///
141    /// # Returns
142    /// Returns a result containing the response object for creating the login profile or an error.
143    async fn new_create_login_profile(
144        &self,
145        request: volcengine_sdk_protobuf::protobuf::iam_user::CreateLoginProfileReq,
146    ) -> Result<volcengine_sdk_protobuf::protobuf::iam_user::CreateLoginProfileResp, error::Error>
147    {
148        // Delegate to the API for creating the login profile
149        api_create_login_profile::ApiCreateLoginProfileIam
150            .new_create_login_profile(self, request)
151            .await
152    }
153
154    /// new_get_login_profile
155    ///
156    /// This method retrieves the login profile of an existing user from the IAM system.
157    ///
158    /// # Parameters
159    /// - `request`: The request object containing the details for retrieving the login profile.
160    ///
161    /// # Returns
162    /// Returns a result containing the response object with login profile details or an error.
163    async fn new_get_login_profile(
164        &self,
165        request: volcengine_sdk_protobuf::protobuf::iam_user::GetLoginProfileReq,
166    ) -> Result<volcengine_sdk_protobuf::protobuf::iam_user::GetLoginProfileResp, error::Error>
167    {
168        // Delegate to the API for retrieving the login profile
169        api_get_login_profile::ApiGetLoginProfileIam
170            .new_get_login_profile(self, request)
171            .await
172    }
173
174    /// new_update_login_profile
175    ///
176    /// This method updates an existing user's login profile in the IAM system.
177    ///
178    /// # Parameters
179    /// - `request`: The request object containing the details for updating the login profile.
180    ///
181    /// # Returns
182    /// Returns a result containing the response object for updating the login profile or an error.
183    async fn new_update_login_profile(
184        &self,
185        request: volcengine_sdk_protobuf::protobuf::iam_user::UpdateLoginProfileReq,
186    ) -> Result<volcengine_sdk_protobuf::protobuf::iam_user::UpdateLoginProfileResp, error::Error>
187    {
188        // Delegate to the API for updating the login profile
189        api_update_login_profile::ApiUpdateLoginProfileIam
190            .new_update_login_profile(self, request)
191            .await
192    }
193
194    /// new_delete_login_profile
195    ///
196    /// This method deletes an existing user's login profile from the IAM system.
197    ///
198    /// # Parameters
199    /// - `request`: The request object containing the details for deleting the login profile.
200    ///
201    /// # Returns
202    /// Returns a result containing the response object for deleting the login profile or an error.
203    async fn new_delete_login_profile(
204        &self,
205        request: volcengine_sdk_protobuf::protobuf::iam_user::DeleteLoginProfileReq,
206    ) -> Result<volcengine_sdk_protobuf::protobuf::iam_user::DeleteLoginProfileResp, error::Error>
207    {
208        // Delegate to the API for deleting the login profile
209        api_delete_login_profile::ApiDeleteLoginProfileIam
210            .new_delete_login_profile(self, request)
211            .await
212    }
213
214    /// new_set_security_config
215    ///
216    /// This method sets the security configuration for a user in the IAM system.
217    ///
218    /// # Parameters
219    /// - `request`: The request object containing the details for setting the security configuration.
220    ///
221    /// # Returns
222    /// Returns a result containing the response object for setting the security configuration or an error.
223    async fn new_set_security_config(
224        &self,
225        request: volcengine_sdk_protobuf::protobuf::iam_user::SetSecurityConfigReq,
226    ) -> Result<volcengine_sdk_protobuf::protobuf::iam_user::SetSecurityConfigResp, error::Error>
227    {
228        // Delegate to the API for setting the security configuration
229        api_set_security_config::ApiSetSecurityConfigIam
230            .new_set_security_config(self, request)
231            .await
232    }
233
234    /// new_get_security_config
235    ///
236    /// # Parameters
237    /// - `&self`
238    /// - `request`: A `GetSecurityConfigReq` structure from `volcengine_sdk_protobuf::protobuf::iam_user`
239    ///
240    /// # Returns
241    /// - On success, returns a `GetSecurityConfigResp` structure from `volcengine_sdk_protobuf::protobuf::iam_user`
242    /// - On failure, returns an `error::Error`
243    async fn new_get_security_config(
244        &self,
245        request: volcengine_sdk_protobuf::protobuf::iam_user::GetSecurityConfigReq,
246    ) -> Result<volcengine_sdk_protobuf::protobuf::iam_user::GetSecurityConfigResp, error::Error>
247    {
248        api_get_security_config::ApiGetSecurityConfigIam
249            .new_get_security_config(self, request)
250            .await
251    }
252
253    /// new_create_project
254    ///
255    /// # Parameters
256    /// - `&self`
257    /// - `request`: A `CreateProjectReq` structure from `volcengine_sdk_protobuf::protobuf::iam_project`
258    ///
259    /// # Returns
260    /// - On success, returns a `CreateProjectResp` structure from `volcengine_sdk_protobuf::protobuf::iam_project`
261    /// - On failure, returns an `error::Error`
262    async fn new_create_project(
263        &self,
264        request: volcengine_sdk_protobuf::protobuf::iam_project::CreateProjectReq,
265    ) -> Result<volcengine_sdk_protobuf::protobuf::iam_project::CreateProjectResp, error::Error>
266    {
267        api_create_project::ApiCreateProjectIam
268            .new_create_project(self, request)
269            .await
270    }
271
272    /// new_get_project
273    ///
274    /// # Parameters
275    /// - `&self`
276    /// - `request`: A `GetProjectReq` structure from `volcengine_sdk_protobuf::protobuf::iam_project`
277    ///
278    /// # Returns
279    /// - On success, returns a `GetProjectResp` structure from `volcengine_sdk_protobuf::protobuf::iam_project`
280    /// - On failure, returns an `error::Error`
281    async fn new_get_project(
282        &self,
283        request: volcengine_sdk_protobuf::protobuf::iam_project::GetProjectReq,
284    ) -> Result<volcengine_sdk_protobuf::protobuf::iam_project::GetProjectResp, error::Error> {
285        api_get_project::ApiGetProjectIam
286            .new_get_project(self, request)
287            .await
288    }
289
290    /// new_create_policy
291    ///
292    /// # Parameters
293    /// - `&self`
294    /// - `request`: A `CreatePolicyReq` structure from `volcengine_sdk_protobuf::protobuf::iam_policy`
295    ///
296    /// # Returns
297    /// - On success, returns a `CreatePolicyResp` structure from `volcengine_sdk_protobuf::protobuf::iam_policy`
298    /// - On failure, returns an `error::Error`
299    async fn new_create_policy(
300        &self,
301        request: volcengine_sdk_protobuf::protobuf::iam_policy::CreatePolicyReq,
302    ) -> Result<volcengine_sdk_protobuf::protobuf::iam_policy::CreatePolicyResp, error::Error> {
303        api_create_policy::ApiCreatePolicyIam
304            .new_create_policy(self, request)
305            .await
306    }
307
308    /// new_get_policy
309    ///
310    /// # Parameters
311    /// - `&self`
312    /// - `request`: A `GetPolicyReq` structure from `volcengine_sdk_protobuf::protobuf::iam_policy`
313    ///
314    /// # Returns
315    /// - On success, returns a `GetPolicyResp` structure from `volcengine_sdk_protobuf::protobuf::iam_policy`
316    /// - On failure, returns an `error::Error`
317    async fn new_get_policy(
318        &self,
319        request: volcengine_sdk_protobuf::protobuf::iam_policy::GetPolicyReq,
320    ) -> Result<volcengine_sdk_protobuf::protobuf::iam_policy::GetPolicyResp, error::Error> {
321        api_get_policy::ApiGetPolicyIam
322            .new_get_policy(self, request)
323            .await
324    }
325
326    /// new_list_policy
327    ///
328    /// # Parameters
329    /// - `&self`
330    /// - `request`: A `ListPoliciesReq` structure from `volcengine_sdk_protobuf::protobuf::iam_policy`
331    ///
332    /// # Returns
333    /// - On success, returns a `ListPoliciesResp` structure from `volcengine_sdk_protobuf::protobuf::iam_policy`
334    /// - On failure, returns an `error::Error`
335    async fn new_list_policy(
336        &self,
337        request: volcengine_sdk_protobuf::protobuf::iam_policy::ListPoliciesReq,
338    ) -> Result<volcengine_sdk_protobuf::protobuf::iam_policy::ListPoliciesResp, error::Error> {
339        api_list_policy::ApiListPolicyIam
340            .new_list_policy(self, request)
341            .await
342    }
343
344    /// new_update_policy
345    ///
346    /// # Parameters
347    /// - `&self`
348    /// - `request`: A `UpdatePolicyReq` structure from `volcengine_sdk_protobuf::protobuf::iam_policy`
349    ///
350    /// # Returns
351    /// - On success, returns a `UpdatePolicyResp` structure from `volcengine_sdk_protobuf::protobuf::iam_policy`
352    /// - On failure, returns an `error::Error`
353    async fn new_update_policy(
354        &self,
355        request: volcengine_sdk_protobuf::protobuf::iam_policy::UpdatePolicyReq,
356    ) -> Result<volcengine_sdk_protobuf::protobuf::iam_policy::UpdatePolicyResp, error::Error> {
357        api_update_policy::ApiUpdatePolicyIam
358            .new_update_policy(self, request)
359            .await
360    }
361
362    /// new_delete_policy
363    ///
364    /// # Parameters
365    /// - `&self`
366    /// - `request`: A `DeletePolicyReq` structure from `volcengine_sdk_protobuf::protobuf::iam_policy`
367    ///
368    /// # Returns
369    /// - On success, returns a `DeletePolicyResp` structure from `volcengine_sdk_protobuf::protobuf::iam_policy`
370    /// - On failure, returns an `error::Error`
371    async fn new_delete_policy(
372        &self,
373        request: volcengine_sdk_protobuf::protobuf::iam_policy::DeletePolicyReq,
374    ) -> Result<volcengine_sdk_protobuf::protobuf::iam_policy::DeletePolicyResp, error::Error> {
375        api_delete_policy::ApiDeletePolicyIam
376            .new_delete_policy(self, request)
377            .await
378    }
379
380    /// new_attach_user_policy
381    ///
382    /// # Parameters
383    /// - `&self`
384    /// - `request`: An `AttachUserPolicyReq` structure from `volcengine_sdk_protobuf::protobuf::iam_policy`
385    ///
386    /// # Returns
387    /// - On success, returns an `AttachUserPolicyResp` structure from `volcengine_sdk_protobuf::protobuf::iam_policy`
388    /// - On failure, returns an `error::Error`
389    async fn new_attach_user_policy(
390        &self,
391        request: volcengine_sdk_protobuf::protobuf::iam_policy::AttachUserPolicyReq,
392    ) -> Result<volcengine_sdk_protobuf::protobuf::iam_policy::AttachUserPolicyResp, error::Error>
393    {
394        api_attach_user_policy::ApiAttachUserPolicyIam
395            .new_attach_user_policy(self, request)
396            .await
397    }
398
399    /// new_list_attach_user_policy
400    ///
401    /// # Parameters
402    /// - `&self`
403    /// - `request`: A `ListAttachedUserPoliciesReq` structure from `volcengine_sdk_protobuf::protobuf::iam_policy`
404    ///
405    /// # Returns
406    /// - On success, returns a `ListAttachedUserPoliciesResp` structure from `volcengine_sdk_protobuf::protobuf::iam_policy`
407    /// - On failure, returns an `error::Error`
408    async fn new_list_attach_user_policy(
409        &self,
410        request: volcengine_sdk_protobuf::protobuf::iam_policy::ListAttachedUserPoliciesReq,
411    ) -> Result<
412        volcengine_sdk_protobuf::protobuf::iam_policy::ListAttachedUserPoliciesResp,
413        error::Error,
414    > {
415        api_list_attach_user_policy::ApiListAttachUserPolicyIam
416            .new_list_attach_user_policy(self, request)
417            .await
418    }
419
420    /// new_detach_user_policy
421    ///
422    /// # Parameters
423    /// - `&self`
424    /// - `request`: A `DetachUserPolicyReq` structure from `volcengine_sdk_protobuf::protobuf::iam_policy`
425    ///
426    /// # Returns
427    /// - On success, returns a `DetachUserPolicyResp` structure from `volcengine_sdk_protobuf::protobuf::iam_policy`
428    /// - On failure, returns an `error::Error`
429    async fn new_detach_user_policy(
430        &self,
431        request: volcengine_sdk_protobuf::protobuf::iam_policy::DetachUserPolicyReq,
432    ) -> Result<volcengine_sdk_protobuf::protobuf::iam_policy::DetachUserPolicyResp, error::Error>
433    {
434        api_detach_user_policy::ApiDetachUserPolicyIam
435            .new_detach_user_policy(self, request)
436            .await
437    }
438
439    /// new_delete_user
440    ///
441    /// # Parameters
442    /// - `&self`
443    /// - `request`: A `DeleteUserReq` structure from `volcengine_sdk_protobuf::protobuf::iam_user`
444    ///
445    /// # Returns
446    /// - On success, returns a `DeleteUserResp` structure from `volcengine_sdk_protobuf::protobuf::iam_user`
447    /// - On failure, returns an `error::Error`
448    async fn new_delete_user(
449        &self,
450        request: volcengine_sdk_protobuf::protobuf::iam_user::DeleteUserReq,
451    ) -> Result<volcengine_sdk_protobuf::protobuf::iam_user::DeleteUserResp, error::Error> {
452        api_delete_user::ApiDeleteUserIam
453            .new_delete_user(self, request)
454            .await
455    }
456}