Completed
Push — master ( e847a5...5b0cc0 )
by Matěj
25s queued 10s
created

UserLDAP.delete_ldap_config()   A

Complexity

Conditions 1

Size

Total Lines 11
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 2
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
from NextCloud.base import WithRequester
2
3
4
class UserLDAP(WithRequester):
5
    API_URL = "/ocs/v2.php/apps/user_ldap/api/v1/config"
6
7
    def create_ldap_config(self):
8
        """ Create a new and empty LDAP configuration """
9
        return self.requester.post()
10
11
    def get_ldap_config(self, config_id, show_password=None):
12
        """
13
        Get all keys and values of the specified LDAP configuration
14
15
        Args:
16
            config_id (str): User LDAP config id
17
            show_password (int): 0 or 1 whether to return the password in clear text (default 0)
18
19
        Returns:
20
21
        """
22
        params = dict(showPassword=show_password)
23
        return self.requester.get(config_id, params=params)
24
25
    def edit_ldap_config(self, config_id, data):
26
        """
27
        Update a configuration with the provided values
28
29
        You can find list of all config keys in get_ldap_config method response or in Nextcloud docs
30
31
        Args:
32
            config_id (str): User LDAP config id
33
            data (dict): config values to update
34
35
        Returns:
36
37
        """
38
        # TODO: refactor to provide methods for configuration s.a. edit_ldap_password and get_ldap_password
39
        prepared_data = {'configData[{}]'.format(key): value for key, value in data.items()}
40
        return self.requester.put(config_id, data=prepared_data)
41
42
    def delete_ldap_config(self, config_id):
43
        """
44
        Delete a given LDAP configuration
45
46
        Args:
47
            config_id (str): User LDAP config id
48
49
        Returns:
50
51
        """
52
        return self.requester.delete(config_id)
53