# coding: utf-8

"""
    UUDEXApi

    uudex api  # noqa: E501

    OpenAPI spec version: 1.0
    Contact: jeff.welsh@pnnl.gov
    Generated by: https://github.com/swagger-api/swagger-codegen.git
"""

from __future__ import absolute_import

import re  # noqa: F401

# python 2 and python 3 compatibility library
import six

from uudex_client.api_client import ApiClient


class PermissionApi(object):
    """NOTE: This class is auto generated by the swagger code generator program.

    Do not edit the class manually.
    Ref: https://github.com/swagger-api/swagger-codegen
    """

    def __init__(self, api_client=None):
        if api_client is None:
            api_client = ApiClient()
        self.api_client = api_client

    def auth_get_permissions(self, object_uuid, object_type, **kwargs):  # noqa: E501
        """Returns a collection of all explicit and implicit permissions granted to an object  # noqa: E501

        1. For object_uuid of type Subject the invoker must have the ParticipantAdmin role or the SubjectAdmin role.  2. For object_uuid of type Group the invoker must be a Group Manager for the group.  3. For object_uuid of type Role the invoker must have the RoleAdmin role.  4. For object_uuid of type Endpoint or type Participant the invoker must have the ParticipantAdmin role   5. A UUDEX Admin may invoke this call without restrictions.   # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.auth_get_permissions(object_uuid, object_type, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str object_uuid: The UUID of either an Endpoint, a Participant, a Group , a Role or a Subject. (required)
        :param str object_type: The object type of the object_uuid param.  This code can be s, r, g, e or p, which represents Subject, Role, Group, Endpoint or Participant, respectively (required)
        :return: list[Permission]
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.auth_get_permissions_with_http_info(object_uuid, object_type, **kwargs)  # noqa: E501
        else:
            (data) = self.auth_get_permissions_with_http_info(object_uuid, object_type, **kwargs)  # noqa: E501
            return data

    def auth_get_permissions_with_http_info(self, object_uuid, object_type, **kwargs):  # noqa: E501
        """Returns a collection of all explicit and implicit permissions granted to an object  # noqa: E501

        1. For object_uuid of type Subject the invoker must have the ParticipantAdmin role or the SubjectAdmin role.  2. For object_uuid of type Group the invoker must be a Group Manager for the group.  3. For object_uuid of type Role the invoker must have the RoleAdmin role.  4. For object_uuid of type Endpoint or type Participant the invoker must have the ParticipantAdmin role   5. A UUDEX Admin may invoke this call without restrictions.   # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.auth_get_permissions_with_http_info(object_uuid, object_type, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str object_uuid: The UUID of either an Endpoint, a Participant, a Group , a Role or a Subject. (required)
        :param str object_type: The object type of the object_uuid param.  This code can be s, r, g, e or p, which represents Subject, Role, Group, Endpoint or Participant, respectively (required)
        :return: list[Permission]
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['object_uuid', 'object_type']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in six.iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method auth_get_permissions" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'object_uuid' is set
        if ('object_uuid' not in params or
                params['object_uuid'] is None):
            raise ValueError("Missing the required parameter `object_uuid` when calling `auth_get_permissions`")  # noqa: E501
        # verify the required parameter 'object_type' is set
        if ('object_type' not in params or
                params['object_type'] is None):
            raise ValueError("Missing the required parameter `object_type` when calling `auth_get_permissions`")  # noqa: E501

        collection_formats = {}

        path_params = {}
        if 'object_uuid' in params:
            path_params['object_uuid'] = params['object_uuid']  # noqa: E501

        query_params = []
        if 'object_type' in params:
            query_params.append(('object_type', params['object_type']))  # noqa: E501

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # Authentication setting
        auth_settings = []  # noqa: E501

        return self.api_client.call_api(
            '/auth/permissions/{object_uuid}', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='list[Permission]',  # noqa: E501
            auth_settings=auth_settings,
            async_req=params.get('async_req'),
            _return_http_data_only=params.get('_return_http_data_only'),
            _preload_content=params.get('_preload_content', True),
            _request_timeout=params.get('_request_timeout'),
            collection_formats=collection_formats)

    def auth_grant_permission(self, **kwargs):  # noqa: E501
        """Creates a permission by granting a privilege on a Subject to an object  # noqa: E501

        The privilege may be either 'SUBSCRIBE', 'PUBLISH', 'MANAGE', or 'DISCOVER'  The target of the privilege grant (i.e., the object) can be either a role, a group, an endpoint or a participant.    The invoker must have either the ParticipantAdmin role or the SubjectAdmin role.  A UUDEX Admin may invoke this call without restrictions.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.auth_grant_permission(async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param Permission body:
        :return: Permission
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.auth_grant_permission_with_http_info(**kwargs)  # noqa: E501
        else:
            (data) = self.auth_grant_permission_with_http_info(**kwargs)  # noqa: E501
            return data

    def auth_grant_permission_with_http_info(self, **kwargs):  # noqa: E501
        """Creates a permission by granting a privilege on a Subject to an object  # noqa: E501

        The privilege may be either 'SUBSCRIBE', 'PUBLISH', 'MANAGE', or 'DISCOVER'  The target of the privilege grant (i.e., the object) can be either a role, a group, an endpoint or a participant.    The invoker must have either the ParticipantAdmin role or the SubjectAdmin role.  A UUDEX Admin may invoke this call without restrictions.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.auth_grant_permission_with_http_info(async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param Permission body:
        :return: Permission
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['body']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in six.iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method auth_grant_permission" % key
                )
            params[key] = val
        del params['kwargs']

        collection_formats = {}

        path_params = {}

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        if 'body' in params:
            body_params = params['body']
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.select_header_content_type(  # noqa: E501
            ['application/json'])  # noqa: E501

        # Authentication setting
        auth_settings = []  # noqa: E501

        return self.api_client.call_api(
            '/auth/permissions', 'POST',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='Permission',  # noqa: E501
            auth_settings=auth_settings,
            async_req=params.get('async_req'),
            _return_http_data_only=params.get('_return_http_data_only'),
            _preload_content=params.get('_preload_content', True),
            _request_timeout=params.get('_request_timeout'),
            collection_formats=collection_formats)

    def auth_revoke_permission(self, privilege, subject_uuid, object_uuid, object_type, except_modifier_override, **kwargs):  # noqa: E501
        """Remove a permission by revoking a privilege on a Subject from an object  # noqa: E501

        The invoker must have the ParticipantAdmin role or the SubjectAdmin role.  A UUDEX Admin may invoke this call without restrictions.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.auth_revoke_permission(privilege, subject_uuid, object_uuid, object_type, except_modifier_override, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str privilege: The privilege to revoke (required)
        :param str subject_uuid: The Subject to revoke the privilege from (required)
        :param str object_uuid: The target object that the privilege will be revoked from (required)
        :param str object_type: The object type of the object_uuid param.  This code can be r, g, e or p, which represents Role, Group, Endpoint or Participant, respectively (required)
        :param str except_modifier_override: Specifies if the allow_except modifier applies to this permission.  Essentially inverts the permission rule and allows everyone (ie, public group) the applicable privilege EXCEPT the target of this grant.  See the UUDEX security design documents for details. (required)
        :return: None
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.auth_revoke_permission_with_http_info(privilege, subject_uuid, object_uuid, object_type, except_modifier_override, **kwargs)  # noqa: E501
        else:
            (data) = self.auth_revoke_permission_with_http_info(privilege, subject_uuid, object_uuid, object_type, except_modifier_override, **kwargs)  # noqa: E501
            return data

    def auth_revoke_permission_with_http_info(self, privilege, subject_uuid, object_uuid, object_type, except_modifier_override, **kwargs):  # noqa: E501
        """Remove a permission by revoking a privilege on a Subject from an object  # noqa: E501

        The invoker must have the ParticipantAdmin role or the SubjectAdmin role.  A UUDEX Admin may invoke this call without restrictions.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.auth_revoke_permission_with_http_info(privilege, subject_uuid, object_uuid, object_type, except_modifier_override, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str privilege: The privilege to revoke (required)
        :param str subject_uuid: The Subject to revoke the privilege from (required)
        :param str object_uuid: The target object that the privilege will be revoked from (required)
        :param str object_type: The object type of the object_uuid param.  This code can be r, g, e or p, which represents Role, Group, Endpoint or Participant, respectively (required)
        :param str except_modifier_override: Specifies if the allow_except modifier applies to this permission.  Essentially inverts the permission rule and allows everyone (ie, public group) the applicable privilege EXCEPT the target of this grant.  See the UUDEX security design documents for details. (required)
        :return: None
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['privilege', 'subject_uuid', 'object_uuid', 'object_type', 'except_modifier_override']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in six.iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method auth_revoke_permission" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'privilege' is set
        if ('privilege' not in params or
                params['privilege'] is None):
            raise ValueError("Missing the required parameter `privilege` when calling `auth_revoke_permission`")  # noqa: E501
        # verify the required parameter 'subject_uuid' is set
        if ('subject_uuid' not in params or
                params['subject_uuid'] is None):
            raise ValueError("Missing the required parameter `subject_uuid` when calling `auth_revoke_permission`")  # noqa: E501
        # verify the required parameter 'object_uuid' is set
        if ('object_uuid' not in params or
                params['object_uuid'] is None):
            raise ValueError("Missing the required parameter `object_uuid` when calling `auth_revoke_permission`")  # noqa: E501
        # verify the required parameter 'object_type' is set
        if ('object_type' not in params or
                params['object_type'] is None):
            raise ValueError("Missing the required parameter `object_type` when calling `auth_revoke_permission`")  # noqa: E501
        # verify the required parameter 'except_modifier_override' is set
        if ('except_modifier_override' not in params or
                params['except_modifier_override'] is None):
            raise ValueError("Missing the required parameter `except_modifier_override` when calling `auth_revoke_permission`")  # noqa: E501

        collection_formats = {}

        path_params = {}
        if 'privilege' in params:
            path_params['privilege'] = params['privilege']  # noqa: E501
        if 'subject_uuid' in params:
            path_params['subject_uuid'] = params['subject_uuid']  # noqa: E501
        if 'object_uuid' in params:
            path_params['object_uuid'] = params['object_uuid']  # noqa: E501

        query_params = []
        if 'object_type' in params:
            query_params.append(('object_type', params['object_type']))  # noqa: E501
        if 'except_modifier_override' in params:
            query_params.append(('except_modifier_override', params['except_modifier_override']))  # noqa: E501

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        # Authentication setting
        auth_settings = []  # noqa: E501

        return self.api_client.call_api(
            '/auth/permissions/{privilege}/subject/{subject_uuid}/target/{object_uuid}', 'DELETE',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type=None,  # noqa: E501
            auth_settings=auth_settings,
            async_req=params.get('async_req'),
            _return_http_data_only=params.get('_return_http_data_only'),
            _preload_content=params.get('_preload_content', True),
            _request_timeout=params.get('_request_timeout'),
            collection_formats=collection_formats)
