mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Add a replace option to ipa-ldap-updater.
We have no way to say "replace value X with Y". This would be useful for us to replace a default value only if the user hasn't already updated it. related to ticket 930
This commit is contained in:
parent
5341a22ba2
commit
77e1ef2f80
@ -218,7 +218,7 @@ class LDAPUpdate:
|
|||||||
def parse_update_file(self, data, all_updates, dn_list):
|
def parse_update_file(self, data, all_updates, dn_list):
|
||||||
"""Parse the update file into a dictonary of lists and apply the update
|
"""Parse the update file into a dictonary of lists and apply the update
|
||||||
for each DN in the file."""
|
for each DN in the file."""
|
||||||
valid_keywords = ["default", "add", "remove", "only", "deleteentry"]
|
valid_keywords = ["default", "add", "remove", "only", "deleteentry", "replace"]
|
||||||
update = {}
|
update = {}
|
||||||
d = ""
|
d = ""
|
||||||
index = ""
|
index = ""
|
||||||
@ -441,6 +441,19 @@ class LDAPUpdate:
|
|||||||
elif utype == 'deleteentry':
|
elif utype == 'deleteentry':
|
||||||
# skip this update type, it occurs in __delete_entries()
|
# skip this update type, it occurs in __delete_entries()
|
||||||
return None
|
return None
|
||||||
|
elif utype == 'replace':
|
||||||
|
# v has the format "old: new"
|
||||||
|
try:
|
||||||
|
(old, new) = v.split(':', 1)
|
||||||
|
except ValueError:
|
||||||
|
raise BadSyntax, "bad syntax in replace, needs to be in the format old: new in %s" % new_entry.dn
|
||||||
|
try:
|
||||||
|
e.remove(old)
|
||||||
|
e.append(new)
|
||||||
|
logging.debug('replace: updated value %s', e)
|
||||||
|
entry.setValues(k, e)
|
||||||
|
except ValueError:
|
||||||
|
logging.debug('replace: %s not found, skipping', old)
|
||||||
|
|
||||||
self.print_entity(entry)
|
self.print_entity(entry)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user