volcengine_rust_sdk/service/iam/
mod.rs

1/*
2 * @Author: Jerry.Yang
3 * @Date: 2024-10-17 14:34:10
4 * @LastEditors: Jerry.Yang
5 * @LastEditTime: 2025-02-05 19:02:06
6 * @Description: Definition of the IamService module and its related interfaces
7 */
8use crate::volcengine::client::client;
9use crate::volcengine::error::error;
10use crate::volcengine::session::session;
11use std::future::Future;
12
13// Include API models related to the IAM service
14mod api_attach_user_policy;
15mod api_attach_user_policy_model;
16mod api_create_login_profile;
17mod api_create_login_profile_model;
18mod api_create_policy;
19mod api_create_policy_model;
20mod api_create_project;
21mod api_create_project_model;
22mod api_create_user;
23mod api_create_user_model;
24mod api_delete_login_profile;
25mod api_delete_login_profile_model;
26mod api_delete_policy;
27mod api_delete_policy_model;
28mod api_delete_user;
29mod api_delete_user_model;
30mod api_detach_user_policy;
31mod api_detach_user_policy_model;
32mod api_get_login_profile;
33mod api_get_login_profile_model;
34mod api_get_policy;
35mod api_get_policy_model;
36mod api_get_project;
37mod api_get_project_model;
38mod api_get_security_config;
39mod api_get_security_config_model;
40mod api_get_user;
41mod api_get_user_model;
42mod api_list_attach_user_policy;
43mod api_list_attach_user_policy_model;
44mod api_list_policy;
45mod api_list_policy_model;
46mod api_set_security_config;
47mod api_set_security_config_model;
48mod api_update_login_profile;
49mod api_update_login_profile_model;
50mod api_update_policy;
51mod api_update_policy_model;
52mod api_update_user;
53mod api_update_user_model;
54pub mod service_iam;
55mod test;
56
57// Define the IamService trait, which provides a series of API interfaces related to IAM
58pub trait IamService {
59    // Create a new IAM instance
60    /// Creates a new IAM instance.
61    ///
62    /// # Arguments
63    /// - `session`: A `Session` struct containing session information.
64    ///
65    /// # Returns
66    /// - On success, returns an `Iam` instance.
67    /// - On error, returns an `Error` struct indicating the reason for the failure.
68    fn new_iam(session: session::Session) -> Result<Iam, error::Error>;
69
70    // API interface for creating a user, returning the result of an asynchronous operation
71    /// Initiates an API call to create a new user.
72    ///
73    /// # Arguments
74    /// - `&self`: A reference to the current instance implementing the `IamService` trait.
75    /// - `request`: A `CreateUserReq` struct containing the details for creating a user.
76    ///
77    /// # Returns
78    /// - A future that resolves to a `Result` containing either a `CreateUserResp` struct on success
79    ///   or an `Error` struct on failure.
80    fn new_create_user(
81        &self,
82        request: volcengine_sdk_protobuf::protobuf::iam_user::CreateUserReq,
83    ) -> impl Future<
84        Output = Result<volcengine_sdk_protobuf::protobuf::iam_user::CreateUserResp, error::Error>,
85    >;
86
87    // API interface for getting user information
88    /// Initiates an API call to retrieve user information.
89    ///
90    /// # Arguments
91    /// - `&self`: A reference to the current instance implementing the `IamService` trait.
92    /// - `request`: A `GetUserReq` struct containing the details for getting user information.
93    ///
94    /// # Returns
95    /// - A future that resolves to a `Result` containing either a `GetUserResp` struct on success
96    ///   or an `Error` struct on failure.
97    fn new_get_user(
98        &self,
99        request: volcengine_sdk_protobuf::protobuf::iam_user::GetUserReq,
100    ) -> impl Future<
101        Output = Result<volcengine_sdk_protobuf::protobuf::iam_user::GetUserResp, error::Error>,
102    >;
103
104    // API interface for updating user information
105    /// Initiates an asynchronous API call to update user information.
106    ///
107    /// # Arguments
108    /// - `&self`: A reference to the current instance implementing the `IamService` trait.
109    /// - `request`: An `UpdateUserReq` struct that contains the new user information to be updated.
110    ///
111    /// # Returns
112    /// - A future that resolves to a `Result`. On success, it contains an `UpdateUserResp` struct
113    ///   indicating the result of the update operation. On failure, it contains an `Error` struct
114    ///   explaining the reason for the update failure.
115    fn new_update_user(
116        &self,
117        request: volcengine_sdk_protobuf::protobuf::iam_user::UpdateUserReq,
118    ) -> impl Future<
119        Output = Result<volcengine_sdk_protobuf::protobuf::iam_user::UpdateUserResp, error::Error>,
120    >;
121
122    // API interface for creating a login profile
123    /// Initiates an asynchronous API call to create a login profile.
124    ///
125    /// # Arguments
126    /// - `&self`: A reference to the current instance implementing the `IamService` trait.
127    /// - `request`: A `CreateLoginProfileReq` struct that holds the details for creating a login profile.
128    ///
129    /// # Returns
130    /// - A future that resolves to a `Result`. On success, it contains a `CreateLoginProfileResp` struct
131    ///   indicating the successful creation of the login profile. On failure, it contains an `Error` struct
132    ///   with information about the creation failure.
133    fn new_create_login_profile(
134        &self,
135        request: volcengine_sdk_protobuf::protobuf::iam_user::CreateLoginProfileReq,
136    ) -> impl Future<
137        Output = Result<
138            volcengine_sdk_protobuf::protobuf::iam_user::CreateLoginProfileResp,
139            error::Error,
140        >,
141    >;
142
143    // API interface for getting a login profile
144    /// Initiates an asynchronous API call to retrieve a login profile.
145    ///
146    /// # Arguments
147    /// - `&self`: A reference to the current instance implementing the `IamService` trait.
148    /// - `request`: A `GetLoginProfileReq` struct that contains the necessary information to get the login profile.
149    ///
150    /// # Returns
151    /// - A future that resolves to a `Result`. On success, it contains a `GetLoginProfileResp` struct
152    ///   with the retrieved login profile information. On failure, it contains an `Error` struct indicating
153    ///   the reason for the retrieval failure.
154    fn new_get_login_profile(
155        &self,
156        request: volcengine_sdk_protobuf::protobuf::iam_user::GetLoginProfileReq,
157    ) -> impl Future<
158        Output = Result<
159            volcengine_sdk_protobuf::protobuf::iam_user::GetLoginProfileResp,
160            error::Error,
161        >,
162    >;
163
164    // API interface for updating the login profile
165    /// Initiates an asynchronous API call to update the login profile.
166    ///
167    /// # Arguments
168    /// - `&self`: A reference to the current instance implementing the `IamService` trait.
169    /// - `request`: An `UpdateLoginProfileReq` struct that contains the new information for updating the login profile,
170    ///              such as new password, password reset requirements, etc.
171    ///
172    /// # Returns
173    /// - A future that resolves to a `Result`. On success, it contains an `UpdateLoginProfileResp` struct
174    ///   which indicates the result of the update operation. On failure, it contains an `Error` struct
175    ///   explaining the reason for the update failure, like an invalid request or server - side error.
176    fn new_update_login_profile(
177        &self,
178        request: volcengine_sdk_protobuf::protobuf::iam_user::UpdateLoginProfileReq,
179    ) -> impl Future<
180        Output = Result<
181            volcengine_sdk_protobuf::protobuf::iam_user::UpdateLoginProfileResp,
182            error::Error,
183        >,
184    >;
185
186    // API interface for deleting the login profile
187    /// Initiates an asynchronous API call to delete the login profile.
188    ///
189    /// # Arguments
190    /// - `&self`: A reference to the current instance implementing the `IamService` trait.
191    /// - `request`: A `DeleteLoginProfileReq` struct that holds the necessary information to identify
192    ///              the login profile to be deleted, such as the user ID associated with the profile.
193    ///
194    /// # Returns
195    /// - A future that resolves to a `Result`. On success, it contains a `DeleteLoginProfileResp` struct
196    ///   indicating the successful deletion of the login profile. On failure, it contains an `Error` struct
197    ///   with details about the deletion failure, for example, the profile does not exist or there are
198    ///   associated dependencies preventing deletion.
199    fn new_delete_login_profile(
200        &self,
201        request: volcengine_sdk_protobuf::protobuf::iam_user::DeleteLoginProfileReq,
202    ) -> impl Future<
203        Output = Result<
204            volcengine_sdk_protobuf::protobuf::iam_user::DeleteLoginProfileResp,
205            error::Error,
206        >,
207    >;
208
209    // API interface for setting the security configuration
210    /// Initiates an asynchronous API call to set the security configuration.
211    ///
212    /// # Arguments
213    /// - `&self`: A reference to the current instance implementing the `IamService` trait.
214    /// - `request`: A `SetSecurityConfigReq` struct that includes the new security configuration settings,
215    ///              such as password complexity rules, multi - factor authentication requirements, etc.
216    ///
217    /// # Returns
218    /// - A future that resolves to a `Result`. On success, it contains a `SetSecurityConfigResp` struct
219    ///   indicating that the security configuration has been successfully set. On failure, it contains an `Error` struct
220    ///   describing the reason for the configuration - setting failure, like invalid configuration values.
221    fn new_set_security_config(
222        &self,
223        request: volcengine_sdk_protobuf::protobuf::iam_user::SetSecurityConfigReq,
224    ) -> impl Future<
225        Output = Result<
226            volcengine_sdk_protobuf::protobuf::iam_user::SetSecurityConfigResp,
227            error::Error,
228        >,
229    >;
230
231    // API interface for getting the security configuration
232    /// Initiates an asynchronous API call to retrieve the security configuration.
233    ///
234    /// # Arguments
235    /// - `&self`: A reference to the current instance implementing the `IamService` trait.
236    /// - `request`: A `GetSecurityConfigReq` struct that contains the necessary information to identify
237    ///              which security configuration to retrieve, such as the scope or user context.
238    ///
239    /// # Returns
240    /// - A future that resolves to a `Result`. On success, it contains a `GetSecurityConfigResp` struct
241    ///   with the retrieved security configuration details, like password policies, access control settings, etc.
242    ///   On failure, it contains an `Error` struct indicating the reason for the retrieval failure,
243    ///   such as insufficient permissions or a server - side issue.
244    fn new_get_security_config(
245        &self,
246        request: volcengine_sdk_protobuf::protobuf::iam_user::GetSecurityConfigReq,
247    ) -> impl Future<
248        Output = Result<
249            volcengine_sdk_protobuf::protobuf::iam_user::GetSecurityConfigResp,
250            error::Error,
251        >,
252    >;
253
254    // API interface for creating a project
255    /// Initiates an asynchronous API call to create a new project.
256    ///
257    /// # Arguments
258    /// - `&self`: A reference to the current instance implementing the `IamService` trait.
259    /// - `request`: A `CreateProjectReq` struct that holds the details for creating a project,
260    ///              such as the project name, description, and initial settings.
261    ///
262    /// # Returns
263    /// - A future that resolves to a `Result`. On success, it contains a `CreateProjectResp` struct
264    ///   indicating the successful creation of the project, which may include the project ID and other metadata.
265    ///   On failure, it contains an `Error` struct with information about the creation failure,
266    ///   like a duplicate project name or invalid input.
267    fn new_create_project(
268        &self,
269        request: volcengine_sdk_protobuf::protobuf::iam_project::CreateProjectReq,
270    ) -> impl Future<
271        Output = Result<
272            volcengine_sdk_protobuf::protobuf::iam_project::CreateProjectResp,
273            error::Error,
274        >,
275    >;
276
277    // API interface for getting a project
278    /// Initiates an asynchronous API call to retrieve a project's information.
279    ///
280    /// # Arguments
281    /// - `&self`: A reference to the current instance implementing the `IamService` trait.
282    /// - `request`: A `GetProjectReq` struct that contains the necessary information to identify
283    ///              the project to retrieve, such as the project ID.
284    ///
285    /// # Returns
286    /// - A future that resolves to a `Result`. On success, it contains a `GetProjectResp` struct
287    ///   with the retrieved project details, including its name, description, and current status.
288    ///   On failure, it contains an `Error` struct indicating the reason for the retrieval failure,
289    ///   such as the project not existing or insufficient permissions.
290    fn new_get_project(
291        &self,
292        request: volcengine_sdk_protobuf::protobuf::iam_project::GetProjectReq,
293    ) -> impl Future<
294        Output = Result<
295            volcengine_sdk_protobuf::protobuf::iam_project::GetProjectResp,
296            error::Error,
297        >,
298    >;
299
300    // API interface for creating a policy
301    /// Initiates an asynchronous API call to create a new policy.
302    ///
303    /// # Arguments
304    /// - `&self`: A reference to the current instance implementing the `IamService` trait.
305    /// - `request`: A `CreatePolicyReq` struct that holds the details for creating a policy,
306    ///              such as the policy name, description, and permission rules.
307    ///
308    /// # Returns
309    /// - A future that resolves to a `Result`. On success, it contains a `CreatePolicyResp` struct
310    ///   indicating the successful creation of the policy, which may include the policy ID and other metadata.
311    ///   On failure, it contains an `Error` struct with information about the creation failure,
312    ///   like a duplicate policy name or invalid permission rules.
313    fn new_create_policy(
314        &self,
315        request: volcengine_sdk_protobuf::protobuf::iam_policy::CreatePolicyReq,
316    ) -> impl Future<
317        Output = Result<
318            volcengine_sdk_protobuf::protobuf::iam_policy::CreatePolicyResp,
319            error::Error,
320        >,
321    >;
322
323    // API interface for getting a policy
324    /// Initiates an asynchronous API call to retrieve a specific policy.
325    ///
326    /// # Arguments
327    /// - `&self`: A reference to the current instance implementing the `IamService` trait.
328    /// - `reqeust`: Note: There is a possible typo here, it should probably be `request`. A `GetPolicyReq` struct
329    ///              that contains the necessary information to identify the policy to retrieve,
330    ///              such as the policy ID or policy name.
331    ///
332    /// # Returns
333    /// - A future that resolves to a `Result`. On success, it contains a `GetPolicyResp` struct
334    ///   with the detailed information of the requested policy, including its name, description,
335    ///   and permission rules. On failure, it contains an `Error` struct indicating the reason for
336    ///   the retrieval failure, such as the policy not existing or insufficient permissions.
337    fn new_get_policy(
338        &self,
339        reqeust: volcengine_sdk_protobuf::protobuf::iam_policy::GetPolicyReq,
340    ) -> impl Future<
341        Output = Result<volcengine_sdk_protobuf::protobuf::iam_policy::GetPolicyResp, error::Error>,
342    >;
343
344    // API interface for listing policies
345    /// Initiates an asynchronous API call to list existing policies.
346    ///
347    /// # Arguments
348    /// - `&self`: A reference to the current instance implementing the `IamService` trait.
349    /// - `request`: A `ListPoliciesReq` struct that may contain filtering criteria, such as
350    ///              pagination information, policy types, or specific search keywords to narrow down
351    ///              the list of policies to be retrieved.
352    ///
353    /// # Returns
354    /// - A future that resolves to a `Result`. On success, it contains a `ListPoliciesResp` struct
355    ///   which includes a list of policies that match the specified criteria. Each policy in the list
356    ///   may have basic information like policy ID, name, and description. On failure, it contains an `Error`
357    ///   struct indicating the reason for the listing failure, such as an invalid filter parameter or
358    ///   a server - side error.
359    fn new_list_policy(
360        &self,
361        request: volcengine_sdk_protobuf::protobuf::iam_policy::ListPoliciesReq,
362    ) -> impl Future<
363        Output = Result<
364            volcengine_sdk_protobuf::protobuf::iam_policy::ListPoliciesResp,
365            error::Error,
366        >,
367    >;
368
369    // API interface for updating a policy
370    /// Initiates an asynchronous API call to update an existing policy.
371    ///
372    /// # Arguments
373    /// - `&self`: A reference to the current instance implementing the `IamService` trait.
374    /// - `request`: An `UpdatePolicyReq` struct that contains the updated information for the policy,
375    ///              such as new policy name, description, or modified permission rules. It also needs
376    ///              to have information to identify the policy to be updated, like the policy ID.
377    ///
378    /// # Returns
379    /// - A future that resolves to a `Result`. On success, it contains an `UpdatePolicyResp` struct
380    ///   indicating the successful update of the policy. On failure, it contains an `Error` struct
381    ///   explaining the reason for the update failure, such as the policy not existing, invalid update
382    ///   data, or insufficient permissions.
383    fn new_update_policy(
384        &self,
385        request: volcengine_sdk_protobuf::protobuf::iam_policy::UpdatePolicyReq,
386    ) -> impl Future<
387        Output = Result<
388            volcengine_sdk_protobuf::protobuf::iam_policy::UpdatePolicyResp,
389            error::Error,
390        >,
391    >;
392
393    // API interface for deleting a policy
394    /// Initiates an asynchronous API call to delete a specific policy.
395    ///
396    /// # Arguments
397    /// - `&self`: A reference to the current instance implementing the `IamService` trait.
398    /// - `request`: A `DeletePolicyReq` struct that contains the necessary information to identify
399    ///              the policy to be deleted, such as the policy ID or policy name.
400    ///
401    /// # Returns
402    /// - A future that resolves to a `Result`. On success, it contains a `DeletePolicyResp` struct
403    ///   indicating that the policy has been successfully deleted. On failure, it contains an `Error`
404    ///   struct indicating the reason for the deletion failure, such as the policy not existing,
405    ///   the policy being in use, or insufficient permissions.
406    fn new_delete_policy(
407        &self,
408        request: volcengine_sdk_protobuf::protobuf::iam_policy::DeletePolicyReq,
409    ) -> impl Future<
410        Output = Result<
411            volcengine_sdk_protobuf::protobuf::iam_policy::DeletePolicyResp,
412            error::Error,
413        >,
414    >;
415
416    // API interface for attaching a policy to a user
417    /// Initiates an asynchronous API call to attach a specific policy to a user.
418    ///
419    /// # Arguments
420    /// - `&self`: A reference to the current instance implementing the `IamService` trait.
421    /// - `request`: An `AttachUserPolicyReq` struct that contains the information about the user
422    ///              and the policy to be attached, such as the user ID and the policy ID.
423    ///
424    /// # Returns
425    /// - A future that resolves to a `Result`. On success, it contains an `AttachUserPolicyResp`
426    ///   struct indicating that the policy has been successfully attached to the user. On failure,
427    ///   it contains an `Error` struct indicating the reason for the attachment failure, such as
428    ///   the user or policy not existing, the policy already being attached, or insufficient permissions.
429    fn new_attach_user_policy(
430        &self,
431        request: volcengine_sdk_protobuf::protobuf::iam_policy::AttachUserPolicyReq,
432    ) -> impl Future<
433        Output = Result<
434            volcengine_sdk_protobuf::protobuf::iam_policy::AttachUserPolicyResp,
435            error::Error,
436        >,
437    >;
438
439    // API interface for listing attached policies of a user
440    /// Initiates an asynchronous API call to list all the policies attached to a specific user.
441    ///
442    /// # Arguments
443    /// - `&self`: A reference to the current instance implementing the `IamService` trait.
444    /// - `request`: A `ListAttachedUserPoliciesReq` struct that contains the information about the user
445    ///              for whom the attached policies are to be listed, such as the user ID.
446    ///
447    /// # Returns
448    /// - A future that resolves to a `Result`. On success, it contains a `ListAttachedUserPoliciesResp`
449    ///   struct that includes a list of policies attached to the user, with details like policy ID,
450    ///   policy name, etc. On failure, it contains an `Error` struct indicating the reason for the
451    ///   listing failure, such as the user not existing or insufficient permissions.
452    fn new_list_attach_user_policy(
453        &self,
454        request: volcengine_sdk_protobuf::protobuf::iam_policy::ListAttachedUserPoliciesReq,
455    ) -> impl Future<
456        Output = Result<
457            volcengine_sdk_protobuf::protobuf::iam_policy::ListAttachedUserPoliciesResp,
458            error::Error,
459        >,
460    >;
461
462    // API interface for detaching a policy from a user
463    /// Initiates an asynchronous API call to detach a specific policy from a user.
464    ///
465    /// # Arguments
466    /// - `&self`: A reference to the current instance implementing the `IamService` trait.
467    /// - `request`: A `DetachUserPolicyReq` struct that holds the necessary information to identify
468    ///              the user and the policy to be detached. This typically includes the user ID and
469    ///              the policy ID.
470    ///
471    /// # Returns
472    /// - A future that resolves to a `Result`. On success, it contains a `DetachUserPolicyResp` struct
473    ///   indicating that the policy has been successfully detached from the user. On failure, it contains
474    ///   an `Error` struct with details about the failure, such as the user or policy not existing,
475    ///   the policy not being attached to the user in the first place, or insufficient permissions.
476    fn new_detach_user_policy(
477        &self,
478        request: volcengine_sdk_protobuf::protobuf::iam_policy::DetachUserPolicyReq,
479    ) -> impl Future<
480        Output = Result<
481            volcengine_sdk_protobuf::protobuf::iam_policy::DetachUserPolicyResp,
482            error::Error,
483        >,
484    >;
485
486    // API interface for deleting a user
487    /// Initiates an asynchronous API call to delete a specific user.
488    ///
489    /// # Arguments
490    /// - `&self`: A reference to the current instance implementing the `IamService` trait.
491    /// - `request`: A `DeleteUserReq` struct that contains the information needed to identify the user
492    ///              to be deleted, usually the user ID.
493    ///
494    /// # Returns
495    /// - A future that resolves to a `Result`. On success, it contains a `DeleteUserResp` struct
496    ///   indicating that the user has been successfully deleted. On failure, it contains an `Error`
497    ///   struct explaining the reason for the deletion failure, such as the user not existing,
498    ///   the user having associated resources that prevent deletion, or insufficient permissions.
499    fn new_delete_user(
500        &self,
501        request: volcengine_sdk_protobuf::protobuf::iam_user::DeleteUserReq,
502    ) -> impl Future<
503        Output = Result<volcengine_sdk_protobuf::protobuf::iam_user::DeleteUserResp, error::Error>,
504    >;
505}
506
507// Define the Iam struct, which is used to encapsulate client - related information.
508// This struct serves as a container for the client instance, allowing for better management
509// and organization of the client - side operations related to the IAM (Identity and Access Management) service.
510// The `Debug` derive trait enables easy debugging by providing a default implementation of the `fmt::Debug` trait.
511// The `Clone` derive trait allows for creating copies of the `Iam` struct, which can be useful in scenarios
512// where multiple parts of the code need independent access to the same IAM - related client information.
513#[derive(Debug, Clone)]
514pub struct Iam {
515    // An instance of the `client::Client` struct that contains all the necessary client - side information.
516    // This may include authentication details, connection settings, and other configurations required
517    // to interact with the IAM service's APIs.
518    client: client::Client,
519}