Skip to content

Commit

Permalink
Merge pull request #6 from octo-technology/fix_get_group
Browse files Browse the repository at this point in the history
Fix default values and get_group method
  • Loading branch information
rrey authored Mar 27, 2020
2 parents bea4a93 + 4c275e9 commit bbdac52
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace: octo
name: azuread

# The version of the collection. Must be compatible with semantic versioning
version: 0.1.0
version: 0.2.0

# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
readme: README.md
Expand Down
35 changes: 18 additions & 17 deletions plugins/modules/azuread_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@
group_types:
description:
- Specifies the group type and its membership.
default: "Unified"
default: []
required: false
type: list
elements: str
choices: ["Unified","DynamicMembership"]
mail_enabled:
description:
- Specifies whether the group is mail-enabled.
default: true
default: false
type: bool
mail_nickname:
description:
Expand Down Expand Up @@ -336,10 +336,12 @@ def _send_request(self, url, data=None, headers=None, method="GET"):
status_code = info["status"]
if status_code == 404:
return None
elif status_code == 400:
self._module.fail_json(msg=json.loads(info["body"]).get("error"))
elif status_code == 401:
self._module.fail_json(failed=True, msg="Unauthorized to perform action '%s' on '%s'" % (method, full_url))
self._module.fail_json(msg="Unauthorized to perform action '%s' on '%s'" % (method, full_url))
elif status_code == 403:
self._module.fail_json(failed=True, msg="Permission Denied")
self._module.fail_json(msg="Permission Denied")
elif 200 <= status_code < 299:
body = resp.read()
if body:
Expand Down Expand Up @@ -372,16 +374,15 @@ def create_group(self, group):
response = self._send_request(url, data=group, headers=self.headers, method="POST")
return response

def get_groups(self):
url = "/groups"
response = self._send_request(url, headers=self.headers, method="GET")
return response.get("value")

def get_group(self, name):
groups = self.get_groups()
for group in groups:
if group.get("displayName") == name:
return group
url = "/groups?$filter=startswith(displayName,'%s')" % name
response = self._send_request(url, headers=self.headers, method="GET")
groups = response.get("value")
if len(groups) > 1:
self.module.fail_json(msg="Expected 1 group matching query, found %d" % len(groups))
elif len(groups) == 0:
return None
return groups[0]

def update_group(self, group_id, group):
url = "/groups/{group_id}".format(group_id=group_id)
Expand Down Expand Up @@ -477,9 +478,9 @@ def build_group_from_params(params):
"mail_nickname", "security_enabled", "owners", "members"]
group = {}
for param in GROUP_PARAMS:
if not params[param]:
continue
group[param] = params[param]
if group["members"] == []:
group.pop("members")
return snake_dict_to_camel_dict(group)


Expand All @@ -491,8 +492,8 @@ def build_group_from_params(params):
tenant_id=dict(type='str', required=True),
display_name=dict(type='str', required=True, aliases=["name"]),
description=dict(type='str', required=True),
group_types=dict(type='list', elements='str', default="Unified", choices=["Unified", "DynamicMembership"]),
mail_enabled=dict(type='bool', default=True),
group_types=dict(type='list', elements='str', default=[], choices=["Unified", "DynamicMembership"]),
mail_enabled=dict(type='bool', default=False),
mail_nickname=dict(type='str', required=True),
security_enabled=dict(type='bool', default=True),
owners=dict(type='list', elements='str', required=True),
Expand Down

0 comments on commit bbdac52

Please sign in to comment.