Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Ansible FreeIPA
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirror
Ansible FreeIPA
Commits
0a1f289f
Unverified
Commit
0a1f289f
authored
Jul 13, 2021
by
Rafael Guterres Jeffman
Committed by
GitHub
Jul 13, 2021
Browse files
Options
Downloads
Plain Diff
Merge pull request #596 from freeipa/automember_verify_condition_keys
automember: Verify condition keys
parents
949ad28b
382ee6ff
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
plugins/modules/ipaautomember.py
+31
-0
31 additions, 0 deletions
plugins/modules/ipaautomember.py
tests/automember/test_automember.yml
+57
-0
57 additions, 0 deletions
tests/automember/test_automember.yml
with
88 additions
and
0 deletions
plugins/modules/ipaautomember.py
+
31
−
0
View file @
0a1f289f
...
@@ -185,6 +185,15 @@ def transform_conditions(conditions):
...
@@ -185,6 +185,15 @@ def transform_conditions(conditions):
return
transformed
return
transformed
def
check_condition_keys
(
ansible_module
,
conditions
,
aciattrs
):
if
conditions
is
None
:
return
for
condition
in
conditions
:
if
condition
[
"
key
"
]
not
in
aciattrs
:
ansible_module
.
fail_json
(
msg
=
"
Invalid automember condition key
'
%s
'"
%
condition
[
"
key
"
])
def
main
():
def
main
():
ansible_module
=
AnsibleModule
(
ansible_module
=
AnsibleModule
(
argument_spec
=
dict
(
argument_spec
=
dict
(
...
@@ -274,6 +283,28 @@ def main():
...
@@ -274,6 +283,28 @@ def main():
# Make sure automember rule exists
# Make sure automember rule exists
res_find
=
find_automember
(
ansible_module
,
name
,
automember_type
)
res_find
=
find_automember
(
ansible_module
,
name
,
automember_type
)
# Check inclusive and exclusive conditions
if
inclusive
is
not
None
or
exclusive
is
not
None
:
# automember_type is either "group" or "hostgorup"
if
automember_type
==
"
group
"
:
_type
=
"
user
"
elif
automember_type
==
"
hostgroup
"
:
_type
=
"
host
"
else
:
ansible_module
.
fail_json
(
msg
=
"
Bad automember type
'
%s
'"
%
automember_type
)
try
:
aciattrs
=
api_command
(
ansible_module
,
"
json_metadata
"
,
to_text
(
_type
),
{}
)[
'
objects
'
][
_type
][
'
aciattrs
'
]
except
Exception
as
ex
:
ansible_module
.
fail_json
(
msg
=
"
%s: %s: %s
"
%
(
"
json_metadata
"
,
_type
,
str
(
ex
)))
check_condition_keys
(
ansible_module
,
inclusive
,
aciattrs
)
check_condition_keys
(
ansible_module
,
exclusive
,
aciattrs
)
# Create command
# Create command
if
state
==
'
present
'
:
if
state
==
'
present
'
:
args
=
gen_args
(
description
,
automember_type
)
args
=
gen_args
(
description
,
automember_type
)
...
...
This diff is collapsed.
Click to expand it.
tests/automember/test_automember.yml
+
57
−
0
View file @
0a1f289f
...
@@ -164,6 +164,34 @@
...
@@ -164,6 +164,34 @@
register
:
result
register
:
result
failed_when
:
result.changed or result.failed
failed_when
:
result.changed or result.failed
-
name
:
Ensure testgroup group automember conditions fails on invalid inclusive key
ipaautomember
:
ipaadmin_principal
:
admin
ipaadmin_password
:
SomeADMINpassword
name
:
testgroup
automember_type
:
group
inclusive
:
-
key
:
cns
expression
:
'
foo'
action
:
member
register
:
result
failed_when
:
result.changed or not result.failed or
"Invalid automember condition key 'cns'" not in result.msg
-
name
:
Ensure testgroup group automember conditions fails on invalid exlusive key
ipaautomember
:
ipaadmin_principal
:
admin
ipaadmin_password
:
SomeADMINpassword
name
:
testgroup
automember_type
:
group
exclusive
:
-
key
:
cns
expression
:
'
foo'
action
:
member
register
:
result
failed_when
:
result.changed or not result.failed or
"Invalid automember condition key 'cns'" not in result.msg
-
name
:
Ensure testhostgroup hostgroup automember rule is present
-
name
:
Ensure testhostgroup hostgroup automember rule is present
ipaautomember
:
ipaautomember
:
ipaadmin_password
:
SomeADMINpassword
ipaadmin_password
:
SomeADMINpassword
...
@@ -282,6 +310,35 @@
...
@@ -282,6 +310,35 @@
register
:
result
register
:
result
failed_when
:
result.changed or result.failed
failed_when
:
result.changed or result.failed
-
name
:
Ensure testhostgroup hostgroup automember conditions fails on invalid inclusive key
ipaautomember
:
ipaadmin_principal
:
admin
ipaadmin_password
:
SomeADMINpassword
name
:
testhostgroup
automember_type
:
hostgroup
inclusive
:
-
key
:
cns
expression
:
'
foo'
action
:
member
register
:
result
failed_when
:
result.changed or not result.failed or
"Invalid automember condition key 'cns'" not in result.msg
-
name
:
Ensure testhostgroup hostgroup automember conditions fails on invalid exlusive key
ipaautomember
:
ipaadmin_principal
:
admin
ipaadmin_password
:
SomeADMINpassword
name
:
testhostgroup
automember_type
:
hostgroup
exclusive
:
-
key
:
cns
expression
:
'
foo'
action
:
member
register
:
result
failed_when
:
result.changed or not result.failed or
"Invalid automember condition key 'cns'" not in result.msg
# CLEANUP TEST ITEMS
# CLEANUP TEST ITEMS
-
name
:
Ensure group testgroup is absent
-
name
:
Ensure group testgroup is absent
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment