Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed check funtion in mgmtroot directory #300

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
21 changes: 19 additions & 2 deletions ibmsecurity/isam/aac/mapping_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ def set(isamAppliance, name, category, filename=None, content=None, upload_filen
"""

if _check(isamAppliance, name=name) is False:
# Force the add - we already know connection does not exist
# Force the add - we already know Mapping Rule does not exist
if upload_filename is not None:
# Check if another Mapping Rule with the same js exists
another_name = _get_name_by_jsname(isamAppliance,upload_filename)
if another_name is not None:
#Another Mapping rule with the same js exists -> delete existing rule before adding
delete(isamAppliance,another_name)
return add(isamAppliance, name=name, filename=filename, content=content, category=category, upload_filename=upload_filename,
check_mode=check_mode, force=True)
else:
Expand Down Expand Up @@ -261,12 +267,23 @@ def _check(isamAppliance, name):
"""
ret_obj = get_all(isamAppliance)

for obj in ret_obj['data']:
for obj in ret_obj['data']:
if obj['name'] == name:
return True

return False

def _get_name_by_jsname(isamAppliance, js_name):
"""
Check if Mapping Rules with given filename already exists
Return Mapping Rule name if found
"""
js_name = _extract_filename(js_name)
ret_obj = get_all(isamAppliance)
for obj in ret_obj['data']:
if obj['fileName'] == js_name:
return obj['name']
return None

def compare(isamAppliance1, isamAppliance2):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get(isamAppliance, instance_id, dir_name='', recursive='yes', check_mode=Fal
def _check(isamAppliance, instance_id, id, name):
ret_obj = get(isamAppliance, instance_id)

dir_name = os.path.join(id, name)
dir_name = id +"/" + name

return _parse_id(ret_obj['data'], dir_name)

Expand Down