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

Update azure_rm_adapplication to return all AD Applications. Enhancement to search for application by app_display_name #1420

Merged
merged 3 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
41 changes: 34 additions & 7 deletions plugins/modules/azure_rm_adapplication_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@
type: str
object_id:
description:
- It's application's object ID.
- The application's object ID.
type: str
identifier_uri:
description:
- It's identifier_uri's object ID.
- The identifier_uri's object ID.
type: str
app_display_name:
description:
- The applications' Name.
type: str

extends_documentation_fragment:
Expand All @@ -55,6 +59,10 @@
- name: get ad app info ---- by identifier uri
azure_rm_adapplication_info:
identifier_uri: "{{ identifier_uri }}"

- name: get ad app info ---- by display name
azure_rm_adapplication_info:
app_display_name: "{{ display_name }}"
'''

RETURN = '''
Expand Down Expand Up @@ -119,9 +127,11 @@ def __init__(self):
self.module_arg_spec = dict(
app_id=dict(type='str'),
object_id=dict(type='str'),
identifier_uri=dict(type='str')
identifier_uri=dict(type='str'),
app_display_name=dict(type='str')
)
self.app_id = None
self.app_display_name = None
self.object_id = None
self.identifier_uri = None
self.results = dict(changed=False)
Expand All @@ -147,9 +157,10 @@ def exec_module(self, **kwargs):
sub_filters.append("identifierUris/any(s:s eq '{0}')".format(self.identifier_uri))
if self.app_id:
sub_filters.append("appId eq '{0}'".format(self.app_id))

if self.app_display_name:
sub_filters.append("displayName eq '{0}'".format(self.app_display_name))
apps = asyncio.get_event_loop().run_until_complete(self.get_applications(sub_filters))
applications = list(apps.value)
applications = list(apps)
self.results['applications'] = [self.to_dict(app) for app in applications]
except APIError as e:
if e.response_status_code != 404:
Expand Down Expand Up @@ -179,9 +190,25 @@ async def get_applications(self, sub_filters):
filter=(' and '.join(sub_filters)),
),
)
return await self._client.applications.get(request_configuration=request_configuration)
applications = await self._client.applications.get(request_configuration=request_configuration)
return applications.value
else:
return await self._client.applications.get()
applications_list = []
applications = await self._client.applications.get()
for app in applications.value:
applications_list.append(app)

kmj251 marked this conversation as resolved.
Show resolved Hide resolved
if applications.odata_next_link:
next_link = applications.odata_next_link
else:
next_link = None

while next_link:
applications = await self._client.applications.with_url(next_link).get()
next_link = applications.odata_next_link
for app in applications.value:
applications_list.append(app)
return applications_list


def main():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
app_id: "{{ create_output.app_id }}"
register: output

- name: Get ad app info by display name
azure_rm_adapplication_info:
object_id: "{{ create_output.app_display_name }}"
register: output

- name: Assert the application facts
ansible.builtin.assert:
that:
Expand Down