# Path: tenable_io/api/base.py
# class BaseApi(object):
# 
#     def __init__(self, client):
#         self._client = client
# 
# class BaseRequest(object):
# 
#     def as_payload(self, filter_=None):
#         return payload_filter(self.__dict__, filter_)
# 
# Path: tenable_io/api/models.py
# class CredentialList(BaseModel):
# 
#     def __init__(
#             self,
#             credentials=None,
#             pagination=None
#     ):
#         self._credentials = None
#         self._pagination = None
#         self.credentials = credentials
#         self.pagination = pagination
# 
#     @property
#     def credentials(self):
#         return self._credentials
# 
#     @credentials.setter
#     @BaseModel._model_list(Credential)
#     def credentials(self, credentials):
#         self._credentials = credentials
# 
#     @property
#     def pagination(self):
#         return self._pagination
# 
#     @pagination.setter
#     @BaseModel._model(FilterPagination)
#     def pagination(self, pagination):
#         self._pagination = pagination
# 
# class CredentialDetails(BaseModel):
# 
#     def __init__(
#             self,
#             uuid=None,
#             name=None,
#             description=None,
#             category=None,
#             type=None,
#             permission=None,
#             user_permissions=None,
#             settings=None,
#             ad_hoc=None,
#     ):
#         self._category = None
#         self._type = None
#         self._permissions = None
#         self._settings = None
# 
#         self.uuid = uuid
#         self.name = name
#         self.description = description
#         self.category = category
#         self.type = type
#         self.permission = permission
#         self.user_permissions = user_permissions
#         self.settings = settings
#         self.ad_hoc = ad_hoc
# 
#     @property
#     def category(self):
#         return self._category
# 
#     @category.setter
#     @BaseModel._model(CredentialCategory)
#     def category(self, category):
#         self._category = category
# 
#     @property
#     def type(self):
#         return self._type
# 
#     @type.setter
#     @BaseModel._model(CredentialType)
#     def type(self, type):
#         self._type = type
# 
#     @property
#     def settings(self):
#         return self._settings
# 
#     @settings.setter
#     @BaseModel._model(CredentialSettings)
#     def settings(self, settings):
#         self._settings = settings
# 
#     @property
#     def permissions(self):
#         return self._permissions
# 
#     @permissions.setter
#     @BaseModel._model_list(CredentialPermission)
#     def permissions(self, permissions):
#         self._permissions = permissions
# 
# class CredentialPermission(BaseModel):
# 
#     USER_TYPE = u'user'
#     GROUP_TYPE = u'group'
# 
#     CAN_USE = 32
#     CAN_EDIT = 64
# 
#     def __init__(
#             self,
#             grantee_uuid=None,
#             type=None,
#             permissions=None,
#             name=None,
#             isPending=None
#     ):
#         self.grantee_uuid = grantee_uuid
#         self.type = type
#         self.permissions = permissions
#         self.name = name
#         self.isPending = isPending
# 
# class CredentialPrimitiveType(BaseModel):
# 
#     def __init__(
#             self,
#             id=None,
#             category=None,
#             default_expand=None,
#             types=None,
#     ):
#         self._types = None
# 
#         self.id = id
#         self.category = category
#         self.default_expand = default_expand
#         self.types = types
# 
#     @property
#     def types(self):
#         return self._types
# 
#     @types.setter
#     @BaseModel._model_list(CredentialTypes)
#     def types(self, types):
#         self._types = types


from json import loads
from tenable_io.api.base import BaseApi, BaseRequest
from tenable_io.api.models import CredentialList, CredentialDetails, CredentialPermission, CredentialPrimitiveType



class CredentialsApi(BaseApi):

    def list(self, f=None, ft='and', limit=None, offset=0, sort=None, referrer_owner_uuid=None):
        """Return a list of Managed Credentials.

        :param f: A list of :class:`tenable_io.api.models.CredentialFilter` instances.
        :param ft: The action to apply if multiple 'f' parameters are provided. Supported values are **and** and **or**.
        :param limit: The maximum number of records to be retrieved.
        :param offset: The offset from request.
        :param sort: A list of fields on which the results are sorted.
        :param referrer_owner_uuid: The UUID of a scan owner. This parameter limits the returned data to managed
               credentials assigned to scans owned by the specified user..
        :raise TenableIOApiException:  When API error is encountered.
        :return: An instance of :class:`tenable_io.api.models.CredentialList`.
        """
        fgen = (i.field + ':' + i.operator + ':' + i.value for i in f) if f is not None else None
        response = self._client.get('credentials',
                                    params={'f': '&'.join(fgen) if fgen is not None else None,
                                            'ft': ft,
                                            'limit': limit, 'offset': offset,
                                            'sort': ','.join(sort) if sort is not None else None,
                                            'referrer_owner_uuid': referrer_owner_uuid
                                            if referrer_owner_uuid is not None else None})

# Path: tenable_io/api/base.py
# class BaseApi(object):
# 
#     def __init__(self, client):
#         self._client = client
# 
# class BaseRequest(object):
# 
#     def as_payload(self, filter_=None):
#         return payload_filter(self.__dict__, filter_)
# 
# Path: tenable_io/api/models.py
# class CredentialList(BaseModel):
# 
#     def __init__(
#             self,
#             credentials=None,
#             pagination=None
#     ):
#         self._credentials = None
#         self._pagination = None
#         self.credentials = credentials
#         self.pagination = pagination
# 
#     @property
#     def credentials(self):
#         return self._credentials
# 
#     @credentials.setter
#     @BaseModel._model_list(Credential)
#     def credentials(self, credentials):
#         self._credentials = credentials
# 
#     @property
#     def pagination(self):
#         return self._pagination
# 
#     @pagination.setter
#     @BaseModel._model(FilterPagination)
#     def pagination(self, pagination):
#         self._pagination = pagination
# 
# class CredentialDetails(BaseModel):
# 
#     def __init__(
#             self,
#             uuid=None,
#             name=None,
#             description=None,
#             category=None,
#             type=None,
#             permission=None,
#             user_permissions=None,
#             settings=None,
#             ad_hoc=None,
#     ):
#         self._category = None
#         self._type = None
#         self._permissions = None
#         self._settings = None
# 
#         self.uuid = uuid
#         self.name = name
#         self.description = description
#         self.category = category
#         self.type = type
#         self.permission = permission
#         self.user_permissions = user_permissions
#         self.settings = settings
#         self.ad_hoc = ad_hoc
# 
#     @property
#     def category(self):
#         return self._category
# 
#     @category.setter
#     @BaseModel._model(CredentialCategory)
#     def category(self, category):
#         self._category = category
# 
#     @property
#     def type(self):
#         return self._type
# 
#     @type.setter
#     @BaseModel._model(CredentialType)
#     def type(self, type):
#         self._type = type
# 
#     @property
#     def settings(self):
#         return self._settings
# 
#     @settings.setter
#     @BaseModel._model(CredentialSettings)
#     def settings(self, settings):
#         self._settings = settings
# 
#     @property
#     def permissions(self):
#         return self._permissions
# 
#     @permissions.setter
#     @BaseModel._model_list(CredentialPermission)
#     def permissions(self, permissions):
#         self._permissions = permissions
# 
# class CredentialPermission(BaseModel):
# 
#     USER_TYPE = u'user'
#     GROUP_TYPE = u'group'
# 
#     CAN_USE = 32
#     CAN_EDIT = 64
# 
#     def __init__(
#             self,
#             grantee_uuid=None,
#             type=None,
#             permissions=None,
#             name=None,
#             isPending=None
#     ):
#         self.grantee_uuid = grantee_uuid
#         self.type = type
#         self.permissions = permissions
#         self.name = name
#         self.isPending = isPending
# 
# class CredentialPrimitiveType(BaseModel):
# 
#     def __init__(
#             self,
#             id=None,
#             category=None,
#             default_expand=None,
#             types=None,
#     ):
#         self._types = None
# 
#         self.id = id
#         self.category = category
#         self.default_expand = default_expand
#         self.types = types
# 
#     @property
#     def types(self):
#         return self._types
# 
#     @types.setter
#     @BaseModel._model_list(CredentialTypes)
#     def types(self, types):
#         self._types = types


# Path: tenable_io/api/credentials.py
from json import loads
from tenable_io.api.base import BaseApi, BaseRequest
from tenable_io.api.models import CredentialList, CredentialDetails, CredentialPermission, CredentialPrimitiveType




class CredentialsApi(BaseApi):

    def list(self, f=None, ft='and', limit=None, offset=0, sort=None, referrer_owner_uuid=None):
        """Return a list of Managed Credentials.

        :param f: A list of :class:`tenable_io.api.models.CredentialFilter` instances.
        :param ft: The action to apply if multiple 'f' parameters are provided. Supported values are **and** and **or**.
        :param limit: The maximum number of records to be retrieved.
        :param offset: The offset from request.
        :param sort: A list of fields on which the results are sorted.
        :param referrer_owner_uuid: The UUID of a scan owner. This parameter limits the returned data to managed
               credentials assigned to scans owned by the specified user..
        :raise TenableIOApiException:  When API error is encountered.
        :return: An instance of :class:`tenable_io.api.models.CredentialList`.
        """
        fgen = (i.field + ':' + i.operator + ':' + i.value for i in f) if f is not None else None
        response = self._client.get('credentials',
                                    params={'f': '&'.join(fgen) if fgen is not None else None,
                                            'ft': ft,
                                            'limit': limit, 'offset': offset,
                                            'sort': ','.join(sort) if sort is not None else None,
                                            'referrer_owner_uuid': referrer_owner_uuid
                                            if referrer_owner_uuid is not None else None})

        return CredentialList.from_json(response.text)