Completed
Push — master ( e5d674...60635b )
by Matěj
12s queued 11s
created

NextCloud.Requester.get()   A

Complexity

Conditions 1

Size

Total Lines 4
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nop 3
1
import enum
2
import requests
3
4
PUBLIC_API_NAME_CLASS_MAP = dict()
5
6
7
class Requester(object):
8
    def __init__(self, endpoint, user, passwd, js=False):
9
        self.query_components = []
10
11
        self.to_json = js
12
13
        self.base_url = endpoint
14
        # GroupFolders.url = endpoint + "/ocs/v2.php/apps/groupfolders/folders"
15
16
        self.h_get = {"OCS-APIRequest": "true"}
17
        self.h_post = {"OCS-APIRequest": "true",
18
                       "Content-Type": "application/x-www-form-urlencoded"}
19
        self.auth_pk = (user, passwd)
20
        self.API_URL = None
21
22
    def rtn(self, resp):
23
        if self.to_json:
24
            return resp.json()
25
        else:
26
            return resp.content.decode("UTF-8")
27
28
    def get(self, url="", params=None):
29
        url = self.get_full_url(url)
30
        res = requests.get(url, auth=self.auth_pk, headers=self.h_get, params=params)
31
        return self.rtn(res)
32
33
    def post(self, url="", data=None):
34
        url = self.get_full_url(url)
35
        res = requests.post(url, auth=self.auth_pk, data=data, headers=self.h_post)
36
        return self.rtn(res)
37
38
    def put(self, url="", data=None):
39
        url = self.get_full_url(url)
40
        res = requests.put(url, auth=self.auth_pk, data=data, headers=self.h_post)
41
        return self.rtn(res)
42
43
    def delete(self, url="", data=None):
44
        url = self.get_full_url(url)
45
        res = requests.delete(url, auth=self.auth_pk, data=data, headers=self.h_post)
46
        return self.rtn(res)
47
48
    def get_full_url(self, additional_url=""):
49
        """
50
        Build full url for request to NextCloud api
51
52
        Construct url from self.base_url, self.API_URL, additional_url (if given), add format=json param if self.json
53
54
        :param additional_url: str
55
            add to url after api_url
56
        :return: str
57
        """
58
        if additional_url and not str(additional_url).startswith("/"):
59
            additional_url = "/{}".format(additional_url)
60
61
        if self.to_json:
62
            self.query_components.append("format=json")
63
64
        ret = "{base_url}{api_url}{additional_url}".format(
65
            base_url=self.base_url, api_url=self.API_URL, additional_url=additional_url)
66
67
        if self.to_json:
68
            ret += "?format=json"
69
        return ret
70
71
72
def nextcloud_method(method_to_wrap):
73
    class_name = method_to_wrap.__qualname__.split(".", 1)[0]
74
    PUBLIC_API_NAME_CLASS_MAP[method_to_wrap.__name__] = class_name
75
    return method_to_wrap
76
77
78
class NextCloud(object):
79
80
    def __init__(self, endpoint, user, password, js=False):
81
        self.query_components = []
82
83
        requester = Requester(endpoint, user, password, js)
84
85
        self.functionality = {
86
            "Apps": Apps(requester),
87
            "Group": Group(requester),
88
            "GroupFolders": GroupFolders(requester),
89
            "Share": Share(requester),
90
            "User": User(requester),
91
            "FederatedCloudShare": FederatedCloudShare(requester),
92
            "Activity": Activity(requester),
93
            "Notifications": Notifications(requester),
94
            "UserLDAP": UserLDAP(requester),
95
        }
96
        for name, location in PUBLIC_API_NAME_CLASS_MAP.items():
97
            setattr(self, name, getattr(self.functionality[location], name))
98
99
100
class WithRequester(object):
101
102
    API_URL = NotImplementedError
103
104
    def __init__(self, requester):
105
        self._requester = requester
106
107
    @property
108
    def requester(self):
109
        """ Get requester instance """
110
        # dynamically set API_URL for requester
111
        self._requester.API_URL = self.API_URL
112
        return self._requester
113
114
115
class GroupFolders(WithRequester):
116
    API_URL = "/apps/groupfolders/folders"
117
118
    @nextcloud_method
119
    def get_group_folders(self):
120
        """
121
        Return a list of call configured folders and their settings
122
123
        Returns:
124
125
        """
126
        return self.requester.get()
127
128
    @nextcloud_method
129
    def get_group_folder(self, fid):
130
        """
131
        Return a specific configured folder and it's settings
132
133
        Args:
134
            fid (int/str): group folder id
135
136
        Returns:
137
138
        """
139
        return self.requester.get(fid)
140
141
    @nextcloud_method
142
    def create_group_folder(self, mountpoint):
143
        """
144
        Create a new group folder
145
146
        Args:
147
            mountpoint (str): name for the new folder
148
149
        Returns:
150
151
        """
152
        return self.requester.post(data={"mountpoint": mountpoint})
153
154
    @nextcloud_method
155
    def delete_group_folder(self, fid):
156
        """
157
        Delete a group folder
158
159
        Args:
160
            fid (int/str): group folder id
161
162
        Returns:
163
164
        """
165
        return self.requester.delete(fid)
166
167
    @nextcloud_method
168
    def grant_access_to_group_folder(self, fid, gid):
169
        """
170
        Give a group access to a folder
171
172
        Args:
173
            fid (int/str): group folder id
174
            gid (str): group to share with id
175
176
        Returns:
177
178
        """
179
        url = "/".join([str(fid), "groups"])
180
        return self.requester.post(url, data={"group": gid})
181
182
    @nextcloud_method
183
    def revoke_access_to_group_folder(self, fid, gid):
184
        """
185
        Remove access from a group to a folder
186
187
        Args:
188
            fid (int/str): group folder id
189
            gid (str): group id
190
191
        Returns:
192
193
        """
194
        url = "/".join([str(fid), "groups", gid])
195
        return self.requester.delete(url)
196
197
    @nextcloud_method
198
    def set_permissions_to_group_folder(self, fid, gid, permissions):
199
        """
200
        Set the permissions a group has in a folder
201
202
        Args:
203
            fid (int/str): group folder id
204
            gid (str): group id
205
            permissions (int): The new permissions for the group as attribute of Permission class
206
207
        Returns:
208
209
        """
210
        url = "/".join([str(fid), "groups", gid])
211
        return self.requester.post(url=url, data={"permissions": permissions})
212
213
    @nextcloud_method
214
    def set_quota_of_group_folder(self, fid, quota):
215
        """
216
        Set the quota for a folder in bytes
217
218
        Args:
219
            fid (int/str): group folder id
220
            quota (int/str): The new quota for the folder in bytes, user -3 for unlimited
221
222
        Returns:
223
224
        """
225
        url = "/".join([str(fid), "quota"])
226
        return self.requester.post(url, {"quota": quota})
227
228
    @nextcloud_method
229
    def rename_group_folder(self, fid, mountpoint):
230
        """
231
        Change the name of a folder
232
233
        Args:
234
            fid (int/str): group folder id
235
            mountpoint (str): The new name for the folder
236
237
        Returns:
238
239
        """
240
        url = "/".join([str(fid), "mountpoint"])
241
        return self.requester.post(url=url, data={"mountpoint": mountpoint})
242
243
244
class Share(WithRequester):
245
    API_URL = "/ocs/v2.php/apps/files_sharing/api/v1"
246
    LOCAL = "shares"
247
248
    def get_local_url(self, additional_url=""):
249
        if additional_url:
250
            return "/".join([self.LOCAL, additional_url])
251
        return self.LOCAL
252
253
    @staticmethod
254
    def validate_share_parameters(path, share_type, share_with):
255
        """
256
        Check if share parameters make sense
257
258
        Args:
259
            path (str): path to the file/folder which should be shared
260
            share_type (int): ShareType attribute
261
            share_with (str): user/group id with which the file should be shared
262
263
        Returns:
264
            bool: True if parameters make sense together, False otherwise
265
        """
266
        if (path is None or not isinstance(share_type, int)) \
267
                or (share_type in [ShareType.GROUP, ShareType.USER, ShareType.FEDERATED_CLOUD_SHARE]
268
                    and share_with is None):
269
            return False
270
        return True
271
272
    @nextcloud_method
273
    def get_shares(self):
274
        """ Get all shares from the user """
275
        return self.requester.get(self.get_local_url())
276
277
    @nextcloud_method
278
    def get_shares_from_path(self, path, reshares=None, subfiles=None):
279
        """
280
        Get all shares from a given file/folder
281
282
        Args:
283
            path (str): path to file/folder
284
            reshares (bool): (optional) return not only the shares from the current user but all shares from the given file
285
            subfiles (bool): (optional) return all shares within a folder, given that path defines a folder
286
287
        Returns:
288
289
        """
290
        url = self.get_local_url()
291
        params = {
292
            "path": path,
293
            "reshares": None if reshares is None else str(bool(reshares)).lower(),  # TODO: test reshares, subfiles
294
            "subfiles": None if subfiles is None else str(bool(subfiles)).lower(),
295
        }
296
        return self.requester.get(url, params=params)
297
298
    @nextcloud_method
299
    def get_share_info(self, sid):
300
        """
301
        Get information about a given share
302
303
        Args:
304
            sid (int): share id
305
306
        Returns:
307
        """
308
        return self.requester.get(self.get_local_url(sid))
309
310
    @nextcloud_method
311
    def create_share(
312
            self, path, share_type, share_with=None, public_upload=None,
313
            password=None, permissions=None):
314
        """
315
        Share a file/folder with a user/group or as public link
316
317
        Mandatory fields: share_type, path and share_with for share_type USER (0) or GROUP (1).
318
319
        Args:
320
            path (str): path to the file/folder which should be shared
321
            share_type (int): ShareType attribute
322
            share_with (str): user/group id with which the file should be shared
323
            public_upload (bool): bool, allow public upload to a public shared folder (true/false)
324
            password (str): password to protect public link Share with
325
            permissions (int): sum of selected Permission attributes
326
327
        Returns:
328
329
        """
330
        if not self.validate_share_parameters(path, share_type, share_with):
331
            return False
332
333
        url = self.get_local_url()
334
        if public_upload:
335
            public_upload = "true"
336
337
        data = {"path": path, "shareType": share_type}
338
        if share_type in [ShareType.GROUP, ShareType.USER, ShareType.FEDERATED_CLOUD_SHARE]:
339
            data["shareWith"] = share_with
340
        if public_upload:
341
            data["publicUpload"] = public_upload
342
        if share_type == ShareType.PUBLIC_LINK and password is not None:
343
            data["password"] = str(password)
344
        if permissions is not None:
345
            data["permissions"] = permissions
346
        return self.requester.post(url, data)
347
348
    @nextcloud_method
349
    def delete_share(self, sid):
350
        """
351
        Remove the given share
352
353
        Args:
354
            sid (str): share id
355
356
        Returns:
357
358
        """
359
        return self.requester.delete(self.get_local_url(sid))
360
361
    @nextcloud_method
362
    def update_share(self, sid, permissions=None, password=None, public_upload=None, expire_date=""):
363
        """
364
        Update a given share, only one value can be updated per request
365
366
        Args:
367
            sid (str): share id
368
            permissions (int): sum of selected Permission attributes
369
            password (str): password to protect public link Share with
370
            public_upload (bool): bool, allow public upload to a public shared folder (true/false)
371
            expire_date (str): set an expire date for public link shares. Format: ‘YYYY-MM-DD’
372
373
        Returns:
374
375
        """
376
        params = dict(
377
            permissions=permissions,
378
            password=password,
379
            expireDate=expire_date
380
        )
381
        if public_upload:
382
            params["publicUpload"] = "true"
383
        if public_upload is False:
384
            params["publicUpload"] = "false"
385
386
        # check if only one param specified
387
        specified_params_count = sum([int(bool(each)) for each in params.values()])
388
        if specified_params_count > 1:
389
            raise ValueError("Only one parameter for update can be specified per request")
390
391
        url = self.get_local_url(sid)
392
        return self.requester.put(url, data=params)
393
394
395
class FederatedCloudShare(WithRequester):
396
    API_URL = "/ocs/v2.php/apps/files_sharing/api/v1"
397
    FEDERATED = "remote_shares"
398
399
    def get_federated_url(self, additional_url=""):
400
        if additional_url:
401
            return "/".join([self.FEDERATED, additional_url])
402
        return self.FEDERATED
403
404
    @nextcloud_method
405
    def list_accepted_federated_cloudshares(self):
406
        url = self.get_federated_url()
407
        return self.requester.get(url)
408
409
    @nextcloud_method
410
    def get_known_federated_cloudshare(self, sid):
411
        url = self.get_federated_url(sid)
412
        return self.requester.get(url)
413
414
    @nextcloud_method
415
    def delete_accepted_federated_cloudshare(self, sid):
416
        url = self.get_federated_url(sid)
417
        return self.requester.delete(url)
418
419
    @nextcloud_method
420
    def list_pending_federated_cloudshares(self, sid):
421
        url = self.get_federated_url("pending")
422
        return self.requester.get(url)
423
424
    @nextcloud_method
425
    def accept_pending_federated_cloudshare(self, sid):
426
        url = self.get_federated_url("pending/{sid}".format(sid=sid))
427
        return self.requester.post(url)
428
429
    @nextcloud_method
430
    def decline_pending_federated_cloudshare(self, sid):
431
        url = self.get_federated_url("pending/{sid}".format(sid=sid))
432
        return self.requester.delete(url)
433
434
435
class Apps(WithRequester):
436
    API_URL = "/ocs/v1.php/cloud/apps"
437
438
    @nextcloud_method
439
    def get_apps(self, filter=None):
440
        """
441
        Get a list of apps installed on the Nextcloud server
442
443
        :param filter: str, optional "enabled" or "disabled"
444
        :return:
445
        """
446
        params = {
447
            "filter": filter
448
        }
449
        return self.requester.get(params=params)
450
451
    @nextcloud_method
452
    def get_app(self, app_id):
453
        """
454
        Provide information on a specific application
455
456
        :param app_id: str, app id
457
        :return:
458
        """
459
        return self.requester.get(app_id)
460
461
    @nextcloud_method
462
    def enable_app(self, app_id):
463
        """
464
        Enable an app
465
466
        :param app_id: str, app id
467
        :return:
468
        """
469
        return self.requester.post(app_id)
470
471
    @nextcloud_method
472
    def disable_app(self, app_id):
473
        """
474
        Disable the specified app
475
476
        :param app_id: str, app id
477
        :return:
478
        """
479
        return self.requester.delete(app_id)
480
481
482
class Group(WithRequester):
483
    API_URL = "/ocs/v1.php/cloud/groups"
484
485
    @nextcloud_method
486
    def get_groups(self, search=None, limit=None, offset=None):
487
        """
488
        Retrieve a list of groups from the Nextcloud server
489
490
        :param search: string, optional search string
491
        :param limit: int, optional limit value
492
        :param offset: int, optional offset value
493
        :return:
494
        """
495
        params = {
496
            'search': search,
497
            'limit': limit,
498
            'offset': offset
499
        }
500
        return self.requester.get(params=params)
501
502
    @nextcloud_method
503
    def add_group(self, gid):
504
        """
505
        Add a new group
506
507
        :param gid: str, group name
508
        :return:
509
        """
510
        msg = {"groupid": gid}
511
        return self.requester.post("", msg)
512
513
    @nextcloud_method
514
    def get_group(self, gid):
515
        """
516
        Retrieve a list of group members
517
518
        :param gid: str, group name
519
        :return:
520
        """
521
        return self.requester.get("{gid}".format(gid=gid))
522
523
    @nextcloud_method
524
    def get_subadmins(self, gid):
525
        """
526
        List subadmins of the group
527
528
        :param gid: str, group name
529
        :return:
530
        """
531
        return self.requester.get("{gid}/subadmins".format(gid=gid))
532
533
    @nextcloud_method
534
    def delete_group(self, gid):
535
        """
536
        Remove a group
537
538
        :param gid: str, group name
539
        :return:
540
        """
541
        return self.requester.delete("{gid}".format(gid=gid))
542
543
544
class User(WithRequester):
545
    API_URL = "/ocs/v1.php/cloud/users"
546
547
    @nextcloud_method
548
    def add_user(self, uid, passwd):
549
        """
550
        Create a new user on the Nextcloud server
551
552
        :param uid: str, uid of new user
553
        :param passwd: str, password of new user
554
        :return:
555
        """
556
        msg = {'userid': uid, 'password': passwd}
557
        return self.requester.post("", msg)
558
559
    @nextcloud_method
560
    def get_users(self, search=None, limit=None, offset=None):
561
        """
562
        Retrieve a list of users from the Nextcloud server
563
564
        :param search: string, optional search string
565
        :param limit: int, optional limit value
566
        :param offset: int, optional offset value
567
        :return:
568
        """
569
        params = {
570
            'search': search,
571
            'limit': limit,
572
            'offset': offset
573
        }
574
        return self.requester.get(params=params)
575
576
    @nextcloud_method
577
    def get_user(self, uid):
578
        """
579
        Retrieve information about a single user
580
581
        :param uid: str, uid of user
582
        :return:
583
        """
584
        return self.requester.get("{uid}".format(uid=uid))
585
586
    @nextcloud_method
587
    def edit_user(self, uid, what, value):
588
        """
589
        Edit attributes related to a user
590
591
        Users are able to edit email, displayname and password; admins can also edit the quota value
592
593
        :param uid: str, uid of user
594
        :param what: str, the field to edit
595
        :param value: str, the new value for the field
596
        :return:
597
        """
598
        what_to_key_map = dict(
599
            email="email", quota="quote", phone="phone", address="address", website="website",
600
            twitter="twitter", displayname="displayname", password="password",
601
        )
602
        assert what in what_to_key_map, (
603
            "You have chosen to edit user's '{what}', but you can choose only from: {choices}"
604
            .format(what=what, choices=", ".join(what_to_key_map.keys()))
605
        )
606
607
        url = "{uid}".format(uid=uid)
608
        msg = dict(
609
            key=what_to_key_map[what],
610
            value=value,
611
        )
612
        return self.requester.put(url, msg)
613
614
    @nextcloud_method
615
    def disable_user(self, uid):
616
        """
617
        Disable a user on the Nextcloud server so that the user cannot login anymore
618
619
        :param uid: str, uid of user
620
        :return:
621
        """
622
        return self.requester.put("{uid}/disable".format(uid=uid))
623
624
    @nextcloud_method
625
    def enable_user(self, uid):
626
        """
627
        Enable a user on the Nextcloud server so that the user can login again
628
629
        :param uid: str, uid of user
630
        :return:
631
        """
632
        return self.requester.put("{uid}/enable".format(uid=uid))
633
634
    @nextcloud_method
635
    def delete_user(self, uid):
636
        """
637
        Delete a user from the Nextcloud server
638
639
        :param uid: str, uid of user
640
        :return:
641
        """
642
        return self.requester.delete("{uid}".format(uid=uid))
643
644
    @nextcloud_method
645
    def add_to_group(self, uid, gid):
646
        """
647
        Add the specified user to the specified group
648
649
        :param uid: str, uid of user
650
        :param gid: str, name of group
651
        :return:
652
        """
653
        url = "{uid}/groups".format(uid=uid)
654
        msg = {'groupid': gid}
655
        return self.requester.post(url, msg)
656
657
    @nextcloud_method
658
    def remove_from_group(self, uid, gid):
659
        """
660
        Remove the specified user from the specified group
661
662
        :param uid: str, uid of user
663
        :param gid: str, name of group
664
        :return:
665
        """
666
        url = "{uid}/groups".format(uid=uid)
667
        msg = {'groupid': gid}
668
        return self.requester.delete(url, msg)
669
670
    @nextcloud_method
671
    def create_subadmin(self, uid, gid):
672
        """
673
        Make a user the subadmin of a group
674
675
        :param uid: str, uid of user
676
        :param gid: str, name of group
677
        :return:
678
        """
679
        url = "{uid}/subadmins".format(uid=uid)
680
        msg = {'groupid': gid}
681
        return self.requester.post(url, msg)
682
683
    @nextcloud_method
684
    def remove_subadmin(self, uid, gid):
685
        """
686
        Remove the subadmin rights for the user specified from the group specified
687
688
        :param uid: str, uid of user
689
        :param gid: str, name of group
690
        :return:
691
        """
692
        url = "{uid}/subadmins".format(uid=uid)
693
        msg = {'groupid': gid}
694
        return self.requester.delete(url, msg)
695
696
    @nextcloud_method
697
    def get_subadmin_groups(self, uid):
698
        """
699
        Get the groups in which the user is a subadmin
700
701
        :param uid: str, uid of user
702
        :return:
703
        """
704
        url = "{uid}/subadmins".format(uid=uid)
705
        return self.requester.get(url)
706
707
    @nextcloud_method
708
    def resend_welcome_mail(self, uid):
709
        """
710
        Trigger the welcome email for this user again
711
712
        :param uid: str, uid of user
713
        :return:
714
        """
715
        url = "{uid}/welcome".format(uid=uid)
716
        return self.requester.post(url)
717
718
719
class Activity(WithRequester):
720
    API_URL = "/ocs/v2.php/apps/activity/api/v2/activity"
721
722
    @nextcloud_method
723
    def get_activities(self, since=None, limit=None, object_type=None, object_id=None, sort=None):
724
        """
725
        Get an activity feed showing your file changes and other interesting things going on in your Nextcloud
726
727
        All args are optional
728
729
        Args:
730
            since (int): ID of the last activity that you’ve seen
731
            limit (int): How many activities should be returned (default: 50)
732
            object_type (string): Filter the activities to a given object. May only appear together with object_id
733
            object_id (string): Filter the activities to a given object. May only appear together with object_type
734
            sort (str, "asc" or "desc"): Sort activities ascending or descending (from the since) (Default: desc)
735
736
        Returns:
737
738
        """
739
        params = dict(
740
            since=since,
741
            limit=limit,
742
            object_type=object_type,
743
            object_id=object_id,
744
            sort=sort
745
        )
746
        if params['object_type'] and params['object_id']:
747
            return self.requester.get(url="filter", params=params)
748
        return self.requester.get(params=params)
749
750
751
class Notifications(WithRequester):
752
    API_URL = "/ocs/v2.php/apps/notifications/api/v2/notifications"
753
754
    @nextcloud_method
755
    def get_notifications(self):
756
        """ Get list of notifications for a logged in user """
757
        return self.requester.get()
758
759
    @nextcloud_method
760
    def get_notification(self, notification_id):
761
        """
762
        Get single notification by id for a user
763
764
        Args:
765
            notification_id (int): Notification id
766
767
        Returns:
768
769
        """
770
        return self.requester.get(url=notification_id)
771
772
    @nextcloud_method
773
    def delete_notification(self, notification_id):
774
        """
775
        Delete single notification by id for a user
776
777
        Args:
778
            notification_id (int): Notification id
779
780
        Returns:
781
782
        """
783
        return self.requester.delete(url=notification_id)
784
785
    @nextcloud_method
786
    def delete_all_notifications(self):
787
        """ Delete all notification for a logged in user
788
789
        Notes:
790
            This endpoint was added for Nextcloud 14
791
        """
792
        return self.requester.delete()
793
794
795
class UserLDAP(WithRequester):
796
    API_URL = "/ocs/v2.php/apps/user_ldap/api/v1/config"
797
798
    @nextcloud_method
799
    def create_ldap_config(self):
800
        """ Create a new and empty LDAP configuration """
801
        return self.requester.post()
802
803
    @nextcloud_method
804
    def get_ldap_config(self, config_id, show_password=None):
805
        """
806
        Get all keys and values of the specified LDAP configuration
807
808
        Args:
809
            config_id (str): User LDAP config id
810
            show_password (int): 0 or 1 whether to return the password in clear text (default 0)
811
812
        Returns:
813
814
        """
815
        params = dict(showPassword=show_password)
816
        return self.requester.get(config_id, params=params)
817
818
    @nextcloud_method
819
    def edit_ldap_config(self, config_id, data):
820
        """
821
        Update a configuration with the provided values
822
823
        You can find list of all config keys in get_ldap_config method response or in Nextcloud docs
824
825
        Args:
826
            config_id (str): User LDAP config id
827
            data (dict): config values to update
828
829
        Returns:
830
831
        """
832
        # TODO: refactor to provide methods for configuration s.a. edit_ldap_password and get_ldap_password
833
        prepared_data = {'configData[{}]'.format(key): value for key, value in data.items()}
834
        return self.requester.put(config_id, data=prepared_data)
835
836
    @nextcloud_method
837
    def delete_ldap_config(self, config_id):
838
        """
839
        Delete a given LDAP configuration
840
841
        Args:
842
            config_id (str): User LDAP config id
843
844
        Returns:
845
846
        """
847
        return self.requester.delete(config_id)
848
849
850
class OCSCode(enum.IntEnum):
851
    OK = 100
852
    SERVER_ERROR = 996
853
    NOT_AUTHORIZED = 997
854
    NOT_FOUND = 998
855
    UNKNOWN_ERROR = 999
856
857
858
class ShareType(enum.IntEnum):
859
    USER = 0
860
    GROUP = 1
861
    PUBLIC_LINK = 3
862
    FEDERATED_CLOUD_SHARE = 6
863
864
865
class Permission(enum.IntEnum):
866
    """ Permission for Share have to be sum of selected permissions """
867
    READ = 1
868
    UPDATE = 2
869
    CREATE = 4
870
    DELETE = 8
871
    SHARE = 16
872
    ALL = 31
873
874
875
QUOTA_UNLIMITED = -3
876
877
878
def datetime_to_expire_date(date):
879
    return date.strftime("%Y-%m-%d")
880