Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions cterasdk/asynchronous/core/files/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,9 @@ async def permalink(self, path):
:param str path: Path.
"""
p = self.normalize(path)
contents = [e async for e in await io.listdir(self._core,
p.parent, 1, False, p.name, 1)] # pylint: disable=unnecessary-comprehension
if contents and contents[0].name == p.name:
return contents[0].permalink
async for e in await io.listdir(self._core, p.parent, 1, False, p.name, 1):
if e.name == p.name:
return e.permalink
raise FileNotFoundError('File not found.', path)

def normalize(self, entries):
Expand Down
1 change: 1 addition & 0 deletions cterasdk/asynchronous/core/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def __init__( # pylint: disable=redefined-builtin, too-many-arguments
self, type, guid, deleted, name, folder_id=None, modified=None,
file_timestamp=None, size=None, id=None, acl=None, gvsn=None,
parent_guid=None, portal_modified_date=None, virtual_portal_id=None):
super().__init__()
self.type = type
self.guid = guid
self.folder_id = folder_id
Expand Down
7 changes: 7 additions & 0 deletions cterasdk/audit/postman.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Collection(Object):
__instance = None

def __init__(self):
super().__init__()
self.info = Info()
self.item = []
Collection.__instance = self
Expand All @@ -36,13 +37,15 @@ def serialize(self):
class Info(Object):

def __init__(self):
super().__init__()
self.name = f'{str(uuid.uuid4())}'
self.schema = "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"


class Command(Object):

def __init__(self, name, request):
super().__init__()
self.name = name
self.request = request
self.response = []
Expand All @@ -51,6 +54,7 @@ def __init__(self, name, request):
class Request(Object):

def __init__(self, method, url):
super().__init__()
self.method = method
self.header = None
self.url = url
Expand All @@ -65,6 +69,7 @@ def request_body(self, data):
class Header(Object):

def __init__(self, key, value):
super().__init__()
self.key = key
self.value = value
self.type = 'text'
Expand Down Expand Up @@ -159,6 +164,7 @@ class Body(Object):
"""Request Body"""

def __init__(self, mode):
super().__init__()
self.mode = mode


Expand Down Expand Up @@ -217,6 +223,7 @@ def json(body):
class URL(Object):

def __init__(self, raw, protocol, host, port, path, query):
super().__init__()
self.raw = raw
self.protocol = protocol
self.host = host
Expand Down
4 changes: 4 additions & 0 deletions cterasdk/cio/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def instance(src, dest=None):
return SrcDstParam.__instance

def __init__(self, src, dest=None):
super().__init__()
self._classname = self.__class__.__name__
self.src = src
self.dest = dest
Expand All @@ -97,6 +98,7 @@ def instance():
return ActionResourcesParam.__instance

def __init__(self):
super().__init__()
self._classname = self.__class__.__name__
self.urls = []
ActionResourcesParam.__instance = self # pylint: disable=unused-private-member
Expand All @@ -115,6 +117,7 @@ def instance(path, access, expire_on):
return CreateShareParam.__instance

def __init__(self, path, access, expire_on):
super().__init__()
self._classname = self.__class__.__name__
self.url = path
self.share = Object()
Expand All @@ -131,6 +134,7 @@ def __init__(self, path, access, expire_on):
class FetchResourcesParam(Object):

def __init__(self):
super().__init__()
self._classname = 'FetchResourcesParam'
self.start = 0
self.limit = 100
Expand Down
7 changes: 7 additions & 0 deletions cterasdk/clients/async_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ def __init__(self, url, **kwargs):
super().__init__('DELETE', url, **kwargs)


class PropfindRequest(BaseRequest):
"""PROPFIND"""

def __init__(self, url, **kwargs):
super().__init__('PROPFIND', url, **kwargs)


class MkcolRequest(BaseRequest):
"""MKCOL"""

Expand Down
2 changes: 1 addition & 1 deletion cterasdk/clients/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(self, builder=None, session=None, settings=None, authenticator=None

default_settings = ClientSessionSettings()
if settings:
default_settings.update(**settings.kwargs)
default_settings.update(**settings)

self._session = session if session else async_requests.Session(default_settings, TraceSettings())

Expand Down
16 changes: 16 additions & 0 deletions cterasdk/clients/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ class AsyncWebDAV(AsyncClient):
async def download(self, path, **kwargs):
return await super().get(path, **kwargs)

async def propfind(self, path):
request = async_requests.PropfindRequest(self._builder(path))
response = await self.async_request(request)
return await response.dav()

async def mkcol(self, path):
request = async_requests.MkcolRequest(self._builder(path))
response = await self.async_request(request)
Expand Down Expand Up @@ -175,6 +180,9 @@ async def json(self):
async def xml(self):
return Deserializers.XML(await self._response.read())

async def dav(self):
return Deserializers.DAV(await self._response.read())

@async_requests.decorate_stream_error
async def read(self, n=-1):
return await self._response.content.read(n)
Expand Down Expand Up @@ -251,6 +259,11 @@ class WebDAV(Client):
def download(self, path, **kwargs):
return super().handle(path, **kwargs)

def propfind(self, path):
request = async_requests.PropfindRequest(self._builder(path))
response = self.request(request)
return response.dav()

def mkcol(self, path):
request = async_requests.MkcolRequest(self._builder(path))
response = self.request(request)
Expand Down Expand Up @@ -403,6 +416,9 @@ def json(self): # pylint: disable=invalid-overridden-method
def xml(self): # pylint: disable=invalid-overridden-method
return execute(super().xml)

def dav(self): # pylint: disable=invalid-overridden-method
return execute(super().dav)

@staticmethod
def new():
async def new_response(response):
Expand Down
3 changes: 2 additions & 1 deletion cterasdk/clients/common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from . import async_requests
from ..convert import tojsonstr, toxmlstr, fromjsonstr, fromxmlstr
from ..convert import tojsonstr, toxmlstr, fromjsonstr, fromxmlstr, fromdavxmlstr


class Serializers:
Expand All @@ -11,6 +11,7 @@ class Serializers:
class Deserializers:
JSON = fromjsonstr
XML = fromxmlstr
DAV = fromdavxmlstr


class MultipartForm:
Expand Down
1 change: 1 addition & 0 deletions cterasdk/clients/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class ClientError(Object):

def __init__(self, exception, message):
super().__init__()
self.request = Object()
self.request.method = exception.request_info.method
self.request.url = str(exception.request_info.real_url)
Expand Down
25 changes: 21 additions & 4 deletions cterasdk/common/object.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
import re
import json
import logging
from collections.abc import MutableMapping


class Object: # pylint: disable=too-many-instance-attributes
class Object(MutableMapping): # pylint: disable=too-many-instance-attributes

@property
def kwargs(self):
return json.loads(str(self))
def __init__(self, **kwargs):
for k, v in kwargs.items():
setattr(self, k, v)

def __getitem__(self, key):
return getattr(self, key)

def __setitem__(self, key, value):
setattr(self, key, value)

def __delitem__(self, key):
delattr(self, key)

def __iter__(self):
return iter(self.__dict__)

def __len__(self):
return len(self.__dict__)

def __str__(self):
return json.dumps(self, default=lambda o: o.__dict__, indent=5)
Expand All @@ -19,6 +35,7 @@ def __repr__(self):
class Device(Object):

def __init__(self, uid, version, firmware):
super().__init__()
self.namespace = 'http://www.w3.org/2001/XMLSchema-instance'
self.location = '../../db/resources/db.xsd'
self.id = uid
Expand Down
7 changes: 7 additions & 0 deletions cterasdk/common/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def convert(rule, classname, property_name, assignment=None):
class Operator(Object):

def __init__(self, right):
super().__init__()
self._classname = self.__class__.__name__ # pylint: disable=protected-access
self.right = right

Expand Down Expand Up @@ -75,6 +76,7 @@ class AfterOperator(Operator):
class AdvancedFilterRule(Object):

def __init__(self, classname, field, operator):
super().__init__()
self._classname = self.__class__.__name__ # pylint: disable=protected-access
self.className = classname
self.fieldName = field
Expand Down Expand Up @@ -283,6 +285,7 @@ def root(included):
class FileEntry(Object):

def __init__(self, name, display_name=None, included=None):
super().__init__()
self._classname = self.__class__.__name__ # pylint: disable=protected-access
self.name = name
self.displayName = display_name
Expand All @@ -300,6 +303,7 @@ class BackupSet(Object):

def __init__(self, name, directory_tree=None, filter_rules=None, defaults_dirs=None,
template_dirs=None, enabled=True, boolean_function=None, comment=None):
super().__init__()
self._classname = self.__class__.__name__ # pylint: disable=protected-access
self.name = name
self.isEnabled = enabled
Expand Down Expand Up @@ -334,6 +338,7 @@ def __init__(self, apps):
class TaskSchedule(Object):

def __init__(self):
super().__init__()
self._classname = 'TaskSchedule' # pylint: disable=protected-access
self.mode = None

Expand Down Expand Up @@ -447,6 +452,7 @@ class ADDomainIDMapping(Object):
:param int end: The maximum id to use for mapping
"""
def __init__(self, domain, start, end):
super().__init__()
self._classname = 'ADDomainIDMapping'
self.domainFlatName = domain
self.minID = start
Expand Down Expand Up @@ -499,6 +505,7 @@ def build(self):
class SoftwareUpdatesTopic(Object):

def __init__(self, enabled, reboot_after_update, reboot_when):
super().__init__()
self._classname = "SoftwareUpdatesSettings"
self.enabled = enabled if enabled else None
self.rebootAfterUpdate = reboot_after_update if reboot_after_update else None
Expand Down
1 change: 1 addition & 0 deletions cterasdk/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def __init__(self, uid, tenant=None, classname=None, name=None, more=None):
:param str,optional name: Base object name
:param str,optional more: Base object more info
"""
super().__init__()
self.uid = uid
self.tenant = tenant
self.classname = classname
Expand Down
2 changes: 1 addition & 1 deletion cterasdk/convert/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .deserializers import fromjsonstr, fromxmlstr # noqa: E402, F401
from .deserializers import fromjsonstr, fromxmlstr, fromdavxmlstr # noqa: E402, F401
from .serializers import tojsonstr, toxmlstr # noqa: E402, F401
4 changes: 4 additions & 0 deletions cterasdk/convert/deserializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ def fromjsonstr(fromstr):
return root.value


def fromdavxmlstr(string):
return fromstring(string)


def fromxmlstr(string): # pylint: disable=too-many-branches,too-many-statements

if not string:
Expand Down
6 changes: 3 additions & 3 deletions cterasdk/core/files/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ def permalink(self, path):
:param str path: Path.
"""
p = self.normalize(path)
contents = [e for e in io.listdir(self._core, p.parent, 1, False, p.name, 1)] # pylint: disable=unnecessary-comprehension
if contents and contents[0].name == p.name:
return contents[0].permalink
for e in io.listdir(self._core, p.parent, 1, False, p.name, 1):
if e.name == p.name:
return e.permalink
raise FileNotFoundError('File not found.', path)

def normalize(self, entries):
Expand Down
3 changes: 3 additions & 0 deletions cterasdk/core/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,14 @@ def fromValue(value, ref):
class Filter(Object):

def __init__(self, field):
super().__init__()
self.field = field


class FilterBuilder(Object):

def __init__(self, name, reference=False):
super().__init__()
self.filter = Filter(name)
self.reference = reference

Expand Down Expand Up @@ -145,6 +147,7 @@ def setValue(self, value):
class QueryParams(Object):

def __init__(self):
super().__init__()
self.startFrom = 0
self.countLimit = 50

Expand Down
4 changes: 4 additions & 0 deletions cterasdk/core/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ def secondary(self):
class AccessControlRule(Object):

def __init__(self, group, role):
super().__init__()
self._classname = 'AccessControlRule'
self.group = group
self.role = role
Expand Down Expand Up @@ -610,6 +611,7 @@ def build(self):
class Task(Object):

def __init__(self, task_id, name):
super().__init__()
self.id = task_id
self.name = name

Expand Down Expand Up @@ -701,6 +703,7 @@ def build(self):
class ExtendedAttribute(Object):

def __init__(self, name, supported):
super().__init__()
self._classname = 'ExtendedAttributesInfo' # pylint: disable=protected-access
self.name = name
self.supported = supported
Expand Down Expand Up @@ -758,6 +761,7 @@ class RoleSettings(Object): # pylint: disable=too-many-instance-attributes
def __init__(self, name, sudo, enable_remote_wipe, enable_sso, enable_seeding_export, enable_seeding_import, access_end_user_folders,
update_settings, update_roles, update_account_emails, update_account_password, manage_cloud_drives, manage_plans,
manage_users, manage_logs, allow_folders_files_permanent_delete, can_manage_legal_holds, can_manage_compliance_settings):
super().__init__()
self.name = name
self.sudo = sudo
self.enable_remote_wipe = enable_remote_wipe
Expand Down
Loading