def role(vcr_cassette, client, unique):
    """There is a valid role in the system."""
    from datadog_api_client.v2.exceptions import ApiException
    from datadog_api_client.v2.model import role_create_request
    from datadog_api_client.v2.model import role_create_data
    from datadog_api_client.v2.model import role_create_attributes
    from datadog_api_client.v2.model import roles_type
    from datadog_api_client.v2.api.roles_api import RolesApi

    api = RolesApi(client)
    body = role_create_request.RoleCreateRequest(
        data=role_create_data.RoleCreateData(
            type=roles_type.RolesType(value="roles"),
            attributes=role_create_attributes.RoleCreateAttributes(
                name=str(unique), ),
        ), )
    response = api.create_role(body=body)
    yield response
    if vcr_cassette.record_mode != "none":
        number_of_interactions = len(vcr_cassette.data)
        try:
            api.delete_role(response.data.id)
        except ApiException as e:
            warnings.warn(str(e))
        vcr_cassette.data = vcr_cassette.data[:number_of_interactions]
def granted_permission(client, role, permission):
    """The permission is granted to the role."""
    from datadog_api_client.v2.model import relationship_to_permission
    from datadog_api_client.v2.model import relationship_to_permission_data
    from datadog_api_client.v2.api.roles_api import RolesApi

    api = RolesApi(client)
    body = relationship_to_permission.RelationshipToPermission(
        data=relationship_to_permission_data.RelationshipToPermissionData(
            id=permission.id,
            type=permission.type,
        ))
    return api.add_permission_to_role(role.data.id, body=body)
def user_has_role(vcr_cassette, client, user, role):
    """The user has the role."""
    from datadog_api_client.v2.exceptions import ApiException
    from datadog_api_client.v2.model import relationship_to_user
    from datadog_api_client.v2.model import relationship_to_user_data
    from datadog_api_client.v2.api.roles_api import RolesApi

    api = RolesApi(client)
    body = relationship_to_user.RelationshipToUser(
        data=relationship_to_user_data.RelationshipToUserData(
            id=user.data.id,
            type=user.data.type,
        ))
    yield api.add_user_to_role(role.data.id, body=body)
    if vcr_cassette.record_mode != "none":
        number_of_interactions = len(vcr_cassette.data)
        try:
            api.remove_user_from_role(role.data.id, body=body)
        except ApiException as e:
            warnings.warn(str(e))
        vcr_cassette.data = vcr_cassette.data[:number_of_interactions]
def permission(client):
    """There is a valid permission in the system."""
    from datadog_api_client.v2.api.roles_api import RolesApi

    return RolesApi(client).list_permissions().data[0]
Ejemplo n.º 5
0
 def setUp(self):
     self.api = RolesApi()  # noqa: E501