pub struct RolesAPI { /* private fields */ }
Expand description
The Roles API is used to create and manage Datadog roles, what global permissions they grant, and which users belong to them.
Permissions related to specific account assets can be granted to roles in the Datadog application without using this API. For example, granting read access on a specific log index to a role can be done in Datadog from the Pipelines page.
Implementations§
Source§impl RolesAPI
impl RolesAPI
pub fn new() -> Self
Sourcepub fn with_config(config: Configuration) -> Self
pub fn with_config(config: Configuration) -> Self
Examples found in repository?
More examples
6async fn main() {
7 // there is a valid "role" in the system
8 let role_data_id = std::env::var("ROLE_DATA_ID").unwrap();
9 let configuration = datadog::Configuration::new();
10 let api = RolesAPI::with_config(configuration);
11 let resp = api.get_role(role_data_id.clone()).await;
12 if let Ok(value) = resp {
13 println!("{:#?}", value);
14 } else {
15 println!("{:#?}", resp.unwrap_err());
16 }
17}
6async fn main() {
7 // there is a valid "role" in the system
8 let role_data_id = std::env::var("ROLE_DATA_ID").unwrap();
9 let configuration = datadog::Configuration::new();
10 let api = RolesAPI::with_config(configuration);
11 let resp = api.delete_role(role_data_id.clone()).await;
12 if let Ok(value) = resp {
13 println!("{:#?}", value);
14 } else {
15 println!("{:#?}", resp.unwrap_err());
16 }
17}
6async fn main() {
7 // there is a valid "role" in the system
8 let role_data_id = std::env::var("ROLE_DATA_ID").unwrap();
9 let configuration = datadog::Configuration::new();
10 let api = RolesAPI::with_config(configuration);
11 let resp = api.list_role_permissions(role_data_id.clone()).await;
12 if let Ok(value) = resp {
13 println!("{:#?}", value);
14 } else {
15 println!("{:#?}", resp.unwrap_err());
16 }
17}
7async fn main() {
8 // there is a valid "role" in the system
9 let role_data_id = std::env::var("ROLE_DATA_ID").unwrap();
10 let configuration = datadog::Configuration::new();
11 let api = RolesAPI::with_config(configuration);
12 let resp = api
13 .list_role_users(role_data_id.clone(), ListRoleUsersOptionalParams::default())
14 .await;
15 if let Ok(value) = resp {
16 println!("{:#?}", value);
17 } else {
18 println!("{:#?}", resp.unwrap_err());
19 }
20}
7async fn main() {
8 // there is a valid "role" in the system
9 let role_data_attributes_name = std::env::var("ROLE_DATA_ATTRIBUTES_NAME").unwrap();
10 let configuration = datadog::Configuration::new();
11 let api = RolesAPI::with_config(configuration);
12 let resp = api
13 .list_roles(ListRolesOptionalParams::default().filter(role_data_attributes_name.clone()))
14 .await;
15 if let Ok(value) = resp {
16 println!("{:#?}", value);
17 } else {
18 println!("{:#?}", resp.unwrap_err());
19 }
20}
pub fn with_client_and_config( config: Configuration, client: ClientWithMiddleware, ) -> Self
Sourcepub async fn add_permission_to_role(
&self,
role_id: String,
body: RelationshipToPermission,
) -> Result<PermissionsResponse, Error<AddPermissionToRoleError>>
pub async fn add_permission_to_role( &self, role_id: String, body: RelationshipToPermission, ) -> Result<PermissionsResponse, Error<AddPermissionToRoleError>>
Adds a permission to a role.
Examples found in repository?
9async fn main() {
10 // there is a valid "role" in the system
11 let role_data_id = std::env::var("ROLE_DATA_ID").unwrap();
12
13 // there is a valid "permission" in the system
14 let permission_id = std::env::var("PERMISSION_ID").unwrap();
15 let body = RelationshipToPermission::new().data(
16 RelationshipToPermissionData::new()
17 .id(permission_id.clone())
18 .type_(PermissionsType::PERMISSIONS),
19 );
20 let configuration = datadog::Configuration::new();
21 let api = RolesAPI::with_config(configuration);
22 let resp = api.add_permission_to_role(role_data_id.clone(), body).await;
23 if let Ok(value) = resp {
24 println!("{:#?}", value);
25 } else {
26 println!("{:#?}", resp.unwrap_err());
27 }
28}
Sourcepub async fn add_permission_to_role_with_http_info(
&self,
role_id: String,
body: RelationshipToPermission,
) -> Result<ResponseContent<PermissionsResponse>, Error<AddPermissionToRoleError>>
pub async fn add_permission_to_role_with_http_info( &self, role_id: String, body: RelationshipToPermission, ) -> Result<ResponseContent<PermissionsResponse>, Error<AddPermissionToRoleError>>
Adds a permission to a role.
Sourcepub async fn add_user_to_role(
&self,
role_id: String,
body: RelationshipToUser,
) -> Result<UsersResponse, Error<AddUserToRoleError>>
pub async fn add_user_to_role( &self, role_id: String, body: RelationshipToUser, ) -> Result<UsersResponse, Error<AddUserToRoleError>>
Adds a user to a role.
Examples found in repository?
9async fn main() {
10 // there is a valid "role" in the system
11 let role_data_id = std::env::var("ROLE_DATA_ID").unwrap();
12
13 // there is a valid "user" in the system
14 let user_data_id = std::env::var("USER_DATA_ID").unwrap();
15 let body = RelationshipToUser::new(RelationshipToUserData::new(
16 user_data_id.clone(),
17 UsersType::USERS,
18 ));
19 let configuration = datadog::Configuration::new();
20 let api = RolesAPI::with_config(configuration);
21 let resp = api.add_user_to_role(role_data_id.clone(), body).await;
22 if let Ok(value) = resp {
23 println!("{:#?}", value);
24 } else {
25 println!("{:#?}", resp.unwrap_err());
26 }
27}
Sourcepub async fn add_user_to_role_with_http_info(
&self,
role_id: String,
body: RelationshipToUser,
) -> Result<ResponseContent<UsersResponse>, Error<AddUserToRoleError>>
pub async fn add_user_to_role_with_http_info( &self, role_id: String, body: RelationshipToUser, ) -> Result<ResponseContent<UsersResponse>, Error<AddUserToRoleError>>
Adds a user to a role.
Sourcepub async fn clone_role(
&self,
role_id: String,
body: RoleCloneRequest,
) -> Result<RoleResponse, Error<CloneRoleError>>
pub async fn clone_role( &self, role_id: String, body: RoleCloneRequest, ) -> Result<RoleResponse, Error<CloneRoleError>>
Clone an existing role
Examples found in repository?
10async fn main() {
11 // there is a valid "role" in the system
12 let role_data_id = std::env::var("ROLE_DATA_ID").unwrap();
13 let body = RoleCloneRequest::new(RoleClone::new(
14 RoleCloneAttributes::new("Example-Role clone".to_string()),
15 RolesType::ROLES,
16 ));
17 let configuration = datadog::Configuration::new();
18 let api = RolesAPI::with_config(configuration);
19 let resp = api.clone_role(role_data_id.clone(), body).await;
20 if let Ok(value) = resp {
21 println!("{:#?}", value);
22 } else {
23 println!("{:#?}", resp.unwrap_err());
24 }
25}
Sourcepub async fn clone_role_with_http_info(
&self,
role_id: String,
body: RoleCloneRequest,
) -> Result<ResponseContent<RoleResponse>, Error<CloneRoleError>>
pub async fn clone_role_with_http_info( &self, role_id: String, body: RoleCloneRequest, ) -> Result<ResponseContent<RoleResponse>, Error<CloneRoleError>>
Clone an existing role
Sourcepub async fn create_role(
&self,
body: RoleCreateRequest,
) -> Result<RoleCreateResponse, Error<CreateRoleError>>
pub async fn create_role( &self, body: RoleCreateRequest, ) -> Result<RoleCreateResponse, Error<CreateRoleError>>
Create a new role for your organization.
Examples found in repository?
14async fn main() {
15 let body = RoleCreateRequest::new(
16 RoleCreateData::new(RoleCreateAttributes::new("developers".to_string()))
17 .relationships(RoleRelationships::new().permissions(
18 RelationshipToPermissions::new().data(vec![
19 RelationshipToPermissionData::new().type_(PermissionsType::PERMISSIONS),
20 ]),
21 ))
22 .type_(RolesType::ROLES),
23 );
24 let configuration = datadog::Configuration::new();
25 let api = RolesAPI::with_config(configuration);
26 let resp = api.create_role(body).await;
27 if let Ok(value) = resp {
28 println!("{:#?}", value);
29 } else {
30 println!("{:#?}", resp.unwrap_err());
31 }
32}
More examples
14async fn main() {
15 // there is a valid "permission" in the system
16 let permission_id = std::env::var("PERMISSION_ID").unwrap();
17 let body = RoleCreateRequest::new(
18 RoleCreateData::new(RoleCreateAttributes::new("Example-Role".to_string()))
19 .relationships(RoleRelationships::new().permissions(
20 RelationshipToPermissions::new().data(vec![
21 RelationshipToPermissionData::new()
22 .id(permission_id.clone())
23 .type_(PermissionsType::PERMISSIONS)
24 ]),
25 ))
26 .type_(RolesType::ROLES),
27 );
28 let configuration = datadog::Configuration::new();
29 let api = RolesAPI::with_config(configuration);
30 let resp = api.create_role(body).await;
31 if let Ok(value) = resp {
32 println!("{:#?}", value);
33 } else {
34 println!("{:#?}", resp.unwrap_err());
35 }
36}
Sourcepub async fn create_role_with_http_info(
&self,
body: RoleCreateRequest,
) -> Result<ResponseContent<RoleCreateResponse>, Error<CreateRoleError>>
pub async fn create_role_with_http_info( &self, body: RoleCreateRequest, ) -> Result<ResponseContent<RoleCreateResponse>, Error<CreateRoleError>>
Create a new role for your organization.
Sourcepub async fn delete_role(
&self,
role_id: String,
) -> Result<(), Error<DeleteRoleError>>
pub async fn delete_role( &self, role_id: String, ) -> Result<(), Error<DeleteRoleError>>
Disables a role.
Examples found in repository?
6async fn main() {
7 // there is a valid "role" in the system
8 let role_data_id = std::env::var("ROLE_DATA_ID").unwrap();
9 let configuration = datadog::Configuration::new();
10 let api = RolesAPI::with_config(configuration);
11 let resp = api.delete_role(role_data_id.clone()).await;
12 if let Ok(value) = resp {
13 println!("{:#?}", value);
14 } else {
15 println!("{:#?}", resp.unwrap_err());
16 }
17}
Sourcepub async fn delete_role_with_http_info(
&self,
role_id: String,
) -> Result<ResponseContent<()>, Error<DeleteRoleError>>
pub async fn delete_role_with_http_info( &self, role_id: String, ) -> Result<ResponseContent<()>, Error<DeleteRoleError>>
Disables a role.
Sourcepub async fn get_role(
&self,
role_id: String,
) -> Result<RoleResponse, Error<GetRoleError>>
pub async fn get_role( &self, role_id: String, ) -> Result<RoleResponse, Error<GetRoleError>>
Get a role in the organization specified by the role’s role_id
.
Examples found in repository?
6async fn main() {
7 // there is a valid "role" in the system
8 let role_data_id = std::env::var("ROLE_DATA_ID").unwrap();
9 let configuration = datadog::Configuration::new();
10 let api = RolesAPI::with_config(configuration);
11 let resp = api.get_role(role_data_id.clone()).await;
12 if let Ok(value) = resp {
13 println!("{:#?}", value);
14 } else {
15 println!("{:#?}", resp.unwrap_err());
16 }
17}
Sourcepub async fn get_role_with_http_info(
&self,
role_id: String,
) -> Result<ResponseContent<RoleResponse>, Error<GetRoleError>>
pub async fn get_role_with_http_info( &self, role_id: String, ) -> Result<ResponseContent<RoleResponse>, Error<GetRoleError>>
Get a role in the organization specified by the role’s role_id
.
Sourcepub async fn list_permissions(
&self,
) -> Result<PermissionsResponse, Error<ListPermissionsError>>
pub async fn list_permissions( &self, ) -> Result<PermissionsResponse, Error<ListPermissionsError>>
Returns a list of all permissions, including name, description, and ID.
Sourcepub async fn list_permissions_with_http_info(
&self,
) -> Result<ResponseContent<PermissionsResponse>, Error<ListPermissionsError>>
pub async fn list_permissions_with_http_info( &self, ) -> Result<ResponseContent<PermissionsResponse>, Error<ListPermissionsError>>
Returns a list of all permissions, including name, description, and ID.
Sourcepub async fn list_role_permissions(
&self,
role_id: String,
) -> Result<PermissionsResponse, Error<ListRolePermissionsError>>
pub async fn list_role_permissions( &self, role_id: String, ) -> Result<PermissionsResponse, Error<ListRolePermissionsError>>
Returns a list of all permissions for a single role.
Examples found in repository?
6async fn main() {
7 // there is a valid "role" in the system
8 let role_data_id = std::env::var("ROLE_DATA_ID").unwrap();
9 let configuration = datadog::Configuration::new();
10 let api = RolesAPI::with_config(configuration);
11 let resp = api.list_role_permissions(role_data_id.clone()).await;
12 if let Ok(value) = resp {
13 println!("{:#?}", value);
14 } else {
15 println!("{:#?}", resp.unwrap_err());
16 }
17}
Sourcepub async fn list_role_permissions_with_http_info(
&self,
role_id: String,
) -> Result<ResponseContent<PermissionsResponse>, Error<ListRolePermissionsError>>
pub async fn list_role_permissions_with_http_info( &self, role_id: String, ) -> Result<ResponseContent<PermissionsResponse>, Error<ListRolePermissionsError>>
Returns a list of all permissions for a single role.
Sourcepub async fn list_role_users(
&self,
role_id: String,
params: ListRoleUsersOptionalParams,
) -> Result<UsersResponse, Error<ListRoleUsersError>>
pub async fn list_role_users( &self, role_id: String, params: ListRoleUsersOptionalParams, ) -> Result<UsersResponse, Error<ListRoleUsersError>>
Gets all users of a role.
Examples found in repository?
7async fn main() {
8 // there is a valid "role" in the system
9 let role_data_id = std::env::var("ROLE_DATA_ID").unwrap();
10 let configuration = datadog::Configuration::new();
11 let api = RolesAPI::with_config(configuration);
12 let resp = api
13 .list_role_users(role_data_id.clone(), ListRoleUsersOptionalParams::default())
14 .await;
15 if let Ok(value) = resp {
16 println!("{:#?}", value);
17 } else {
18 println!("{:#?}", resp.unwrap_err());
19 }
20}
Sourcepub async fn list_role_users_with_http_info(
&self,
role_id: String,
params: ListRoleUsersOptionalParams,
) -> Result<ResponseContent<UsersResponse>, Error<ListRoleUsersError>>
pub async fn list_role_users_with_http_info( &self, role_id: String, params: ListRoleUsersOptionalParams, ) -> Result<ResponseContent<UsersResponse>, Error<ListRoleUsersError>>
Gets all users of a role.
Sourcepub async fn list_roles(
&self,
params: ListRolesOptionalParams,
) -> Result<RolesResponse, Error<ListRolesError>>
pub async fn list_roles( &self, params: ListRolesOptionalParams, ) -> Result<RolesResponse, Error<ListRolesError>>
Returns all roles, including their names and their unique identifiers.
Examples found in repository?
7async fn main() {
8 // there is a valid "role" in the system
9 let role_data_attributes_name = std::env::var("ROLE_DATA_ATTRIBUTES_NAME").unwrap();
10 let configuration = datadog::Configuration::new();
11 let api = RolesAPI::with_config(configuration);
12 let resp = api
13 .list_roles(ListRolesOptionalParams::default().filter(role_data_attributes_name.clone()))
14 .await;
15 if let Ok(value) = resp {
16 println!("{:#?}", value);
17 } else {
18 println!("{:#?}", resp.unwrap_err());
19 }
20}
Sourcepub async fn list_roles_with_http_info(
&self,
params: ListRolesOptionalParams,
) -> Result<ResponseContent<RolesResponse>, Error<ListRolesError>>
pub async fn list_roles_with_http_info( &self, params: ListRolesOptionalParams, ) -> Result<ResponseContent<RolesResponse>, Error<ListRolesError>>
Returns all roles, including their names and their unique identifiers.
Sourcepub async fn remove_permission_from_role(
&self,
role_id: String,
body: RelationshipToPermission,
) -> Result<PermissionsResponse, Error<RemovePermissionFromRoleError>>
pub async fn remove_permission_from_role( &self, role_id: String, body: RelationshipToPermission, ) -> Result<PermissionsResponse, Error<RemovePermissionFromRoleError>>
Removes a permission from a role.
Examples found in repository?
9async fn main() {
10 // there is a valid "role" in the system
11 let role_data_id = std::env::var("ROLE_DATA_ID").unwrap();
12
13 // there is a valid "permission" in the system
14 let permission_id = std::env::var("PERMISSION_ID").unwrap();
15 let body = RelationshipToPermission::new().data(
16 RelationshipToPermissionData::new()
17 .id(permission_id.clone())
18 .type_(PermissionsType::PERMISSIONS),
19 );
20 let configuration = datadog::Configuration::new();
21 let api = RolesAPI::with_config(configuration);
22 let resp = api
23 .remove_permission_from_role(role_data_id.clone(), body)
24 .await;
25 if let Ok(value) = resp {
26 println!("{:#?}", value);
27 } else {
28 println!("{:#?}", resp.unwrap_err());
29 }
30}
Sourcepub async fn remove_permission_from_role_with_http_info(
&self,
role_id: String,
body: RelationshipToPermission,
) -> Result<ResponseContent<PermissionsResponse>, Error<RemovePermissionFromRoleError>>
pub async fn remove_permission_from_role_with_http_info( &self, role_id: String, body: RelationshipToPermission, ) -> Result<ResponseContent<PermissionsResponse>, Error<RemovePermissionFromRoleError>>
Removes a permission from a role.
Sourcepub async fn remove_user_from_role(
&self,
role_id: String,
body: RelationshipToUser,
) -> Result<UsersResponse, Error<RemoveUserFromRoleError>>
pub async fn remove_user_from_role( &self, role_id: String, body: RelationshipToUser, ) -> Result<UsersResponse, Error<RemoveUserFromRoleError>>
Removes a user from a role.
Examples found in repository?
9async fn main() {
10 // there is a valid "role" in the system
11 let role_data_id = std::env::var("ROLE_DATA_ID").unwrap();
12
13 // there is a valid "user" in the system
14 let user_data_id = std::env::var("USER_DATA_ID").unwrap();
15 let body = RelationshipToUser::new(RelationshipToUserData::new(
16 user_data_id.clone(),
17 UsersType::USERS,
18 ));
19 let configuration = datadog::Configuration::new();
20 let api = RolesAPI::with_config(configuration);
21 let resp = api.remove_user_from_role(role_data_id.clone(), body).await;
22 if let Ok(value) = resp {
23 println!("{:#?}", value);
24 } else {
25 println!("{:#?}", resp.unwrap_err());
26 }
27}
Sourcepub async fn remove_user_from_role_with_http_info(
&self,
role_id: String,
body: RelationshipToUser,
) -> Result<ResponseContent<UsersResponse>, Error<RemoveUserFromRoleError>>
pub async fn remove_user_from_role_with_http_info( &self, role_id: String, body: RelationshipToUser, ) -> Result<ResponseContent<UsersResponse>, Error<RemoveUserFromRoleError>>
Removes a user from a role.
Sourcepub async fn update_role(
&self,
role_id: String,
body: RoleUpdateRequest,
) -> Result<RoleUpdateResponse, Error<UpdateRoleError>>
pub async fn update_role( &self, role_id: String, body: RoleUpdateRequest, ) -> Result<RoleUpdateResponse, Error<UpdateRoleError>>
Edit a role. Can only be used with application keys belonging to administrators.
Examples found in repository?
14async fn main() {
15 // there is a valid "role" in the system
16 let role_data_id = std::env::var("ROLE_DATA_ID").unwrap();
17
18 // there is a valid "permission" in the system
19 let permission_id = std::env::var("PERMISSION_ID").unwrap();
20 let body = RoleUpdateRequest::new(
21 RoleUpdateData::new(
22 RoleUpdateAttributes::new().name("developers-updated".to_string()),
23 role_data_id.clone(),
24 RolesType::ROLES,
25 )
26 .relationships(RoleRelationships::new().permissions(
27 RelationshipToPermissions::new().data(vec![
28 RelationshipToPermissionData::new()
29 .id(permission_id.clone())
30 .type_(PermissionsType::PERMISSIONS)
31 ]),
32 )),
33 );
34 let configuration = datadog::Configuration::new();
35 let api = RolesAPI::with_config(configuration);
36 let resp = api.update_role(role_data_id.clone(), body).await;
37 if let Ok(value) = resp {
38 println!("{:#?}", value);
39 } else {
40 println!("{:#?}", resp.unwrap_err());
41 }
42}
Sourcepub async fn update_role_with_http_info(
&self,
role_id: String,
body: RoleUpdateRequest,
) -> Result<ResponseContent<RoleUpdateResponse>, Error<UpdateRoleError>>
pub async fn update_role_with_http_info( &self, role_id: String, body: RoleUpdateRequest, ) -> Result<ResponseContent<RoleUpdateResponse>, Error<UpdateRoleError>>
Edit a role. Can only be used with application keys belonging to administrators.