Skip to content

Commit

Permalink
Removed method create_object_from_template() and added optional argum…
Browse files Browse the repository at this point in the history
…ent template_dn to create_object()
  • Loading branch information
tobiasbp committed Oct 16, 2020
1 parent d1c874f commit f6a7563
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions fusiondirectory_api/fusiondirectory_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ def delete_object(self, object_type, object_dn):
Returns:
True on success
"""
data = {"method": "delete", "params": [self._session_id, object_type, object_dn]}
data = {
"method": "delete",
"params": [self._session_id, object_type, object_dn],
}
r = self._post(data)
# Api returns nothing on success, so anything is an error
if r:
Expand Down Expand Up @@ -158,7 +161,10 @@ def get_tabs(self, object_type, object_dn=None):
A dictionary with tabs as keys and a dictionary with
tab name (str) and active (Bool)
"""
data = {"method": "listTabs", "params": [self._session_id, object_type, object_dn]}
data = {
"method": "listTabs",
"params": [self._session_id, object_type, object_dn],
}
return self._post(data)

def get_info(self, object_type):
Expand Down Expand Up @@ -255,7 +261,10 @@ def get_template(self, object_type, template_dn):
Returns:
dict: FusionDirectory attributes organized as tabs
"""
data = {"method": "gettemplate", "params": [self._session_id, object_type, template_dn]}
data = {
"method": "gettemplate",
"params": [self._session_id, object_type, template_dn],
}
return self._post(data)

def delete_tab(self, object_type, object_dn, tab):
Expand Down Expand Up @@ -296,19 +305,23 @@ def _set_fields(self, object_type, object_dn, values):
}
return self._post(data)

def create_object(self, object_type, values):
def create_object(self, object_type, values, template_dn=None):
"""
Create a new object
Create a new object. Optionally from a template.
Args:
object_type (str): The type of object to create
values (dict): The values to use for the new object.
template_dn (str): Optional template for object creation
Outher keys are tabs, then fields with values
Returns:
The DN of the created object (str)
"""
return self._set_fields(object_type, None, values)
if template_dn:
return self._create_object_from_template(object_type, template_dn, values)
else:
return self._set_fields(object_type, None, values)

def update_object(self, object_type, object_dn, values):
"""
Expand Down Expand Up @@ -356,7 +369,7 @@ def unlock_user(self, user_dn):
self._post(data)
return True

def create_object_from_template(self, object_type, template_dn, values):
def _create_object_from_template(self, object_type, template_dn, values):
"""
Create an object from a template
Expand Down

0 comments on commit f6a7563

Please sign in to comment.