From 970d6c12da3e14700f456161bffbd49b48985642 Mon Sep 17 00:00:00 2001
From: Rafael Guterres Jeffman <rjeffman@redhat.com>
Date: Thu, 30 Sep 2021 21:18:32 -0300
Subject: [PATCH] selfservice: Use IPAAnsibleModule method to validate
 arguments.

Use the IPAAnsibleModule.params_fail_if_used method to validate
arguments provided by user.
---
 plugins/modules/ipaselfservice.py | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/plugins/modules/ipaselfservice.py b/plugins/modules/ipaselfservice.py
index 53bd5b3b..7bd26aff 100644
--- a/plugins/modules/ipaselfservice.py
+++ b/plugins/modules/ipaselfservice.py
@@ -158,6 +158,7 @@ def main():
     state = ansible_module.params_get("state")
 
     # Check parameters
+    invalid = []
 
     if state == "present":
         if len(names) != 1:
@@ -165,11 +166,6 @@ def main():
                 msg="Only one selfservice be added at a time.")
         if action == "member":
             invalid = ["permission"]
-            for x in invalid:
-                if vars()[x] is not None:
-                    ansible_module.fail_json(
-                        msg="Argument '%s' can not be used with action "
-                        "'%s' and state '%s'" % (x, action, state))
 
     if state == "absent":
         if len(names) < 1:
@@ -177,11 +173,8 @@ def main():
         invalid = ["permission"]
         if action == "selfservice":
             invalid.append("attribute")
-        for x in invalid:
-            if vars()[x] is not None:
-                ansible_module.fail_json(
-                    msg="Argument '%s' can not be used with action "
-                    "'%s' and state '%s'" % (x, action, state))
+
+    ansible_module.params_fail_used_invalid(invalid, state, action)
 
     if permission is not None:
         perm = [p for p in permission if p not in ("read", "write")]
-- 
GitLab