Skip to content

Commit

Permalink
Support company_name to azure_rm_aduser (#1504)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fred-sun authored Mar 22, 2024
1 parent 8bae823 commit c7f7dd8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
31 changes: 26 additions & 5 deletions plugins/modules/azure_rm_aduser.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@
- Filter that can be used to specify a user to update or delete.
- Mutually exclusive with I(object_id), I(attribute_name), and I(user_principal_name).
type: str
company_name:
description:
- The name of the company that the user is associated with.
- This property can be useful for describing the company that an external user comes from.
- The maximum length is 64 characters.Returned only on $select.
- Supports $filter (eq, ne, not, ge, le, in, startsWith, and eq on null values).
type: str
extends_documentation_fragment:
- azure.azcollection.azure
Expand All @@ -135,6 +142,7 @@
user_type: "Member"
usage_location: "US"
mail: "{{ user_principal_name }}@contoso.com"
company_name: 'Test Company'
- name: Update user with new value for account_enabled
azure_rm_aduser:
Expand Down Expand Up @@ -191,6 +199,12 @@
returned: always
type: str
sample: Member
company_name:
description:
- The name of the company that the user is associated with.
type: str
returned: always
sample: 'Test Company'
'''

from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common_ext import AzureRMModuleBase
Expand Down Expand Up @@ -225,6 +239,7 @@ def __init__(self):
surname=dict(type='str'),
user_type=dict(type='str'),
mail=dict(type='str'),
company_name=dict(type='str')
)

self.user_principal_name = None
Expand All @@ -243,6 +258,7 @@ def __init__(self):
self.surname = None
self.user_type = None
self.mail = None
self.company_name = None
self.log_path = None
self.log_mode = None

Expand Down Expand Up @@ -303,6 +319,8 @@ def exec_module(self, **kwargs):
should_update = True
if should_update or self.mail_nickname and ad_user.mail_nickname != self.mail_nickname:
should_update = True
if should_update or self.company_name and ad_user.company_name != self.company_name:
should_update = True

if should_update:
asyncio.get_event_loop().run_until_complete(self.update_user(ad_user, password))
Expand Down Expand Up @@ -381,7 +399,8 @@ def to_dict(self, object):
mail_nickname=object.mail_nickname,
mail=object.mail,
account_enabled=object.account_enabled,
user_type=object.user_type
user_type=object.user_type,
company_name=object.company_name
)

async def update_user(self, ad_user, password):
Expand All @@ -395,7 +414,8 @@ async def update_user(self, ad_user, password):
display_name=self.display_name,
password_profile=password,
user_principal_name=self.user_principal_name,
mail_nickname=self.mail_nickname
mail_nickname=self.mail_nickname,
company_name=self.company_name
)
return await self._client.users.by_user_id(ad_user.id).patch(body=request_body)

Expand All @@ -414,7 +434,8 @@ async def create_user(self):
given_name=self.given_name,
surname=self.surname,
user_type=self.user_type,
mail=self.mail
mail=self.mail,
company_name=self.company_name
)
return await self._client.users.post(body=request_body)

Expand All @@ -425,7 +446,7 @@ async def get_user(self, object):
request_configuration = UsersRequestBuilder.UsersRequestBuilderGetRequestConfiguration(
query_parameters=UsersRequestBuilder.UsersRequestBuilderGetQueryParameters(
select=["accountEnabled", "displayName", "mail", "mailNickname", "id", "userPrincipalName", "userType",
"onPremisesImmutableId", "usageLocation", "givenName", "surname"]
"onPremisesImmutableId", "usageLocation", "givenName", "surname", "companyName"]
),
)
return await self._client.users.by_user_id(object).get(request_configuration=request_configuration)
Expand All @@ -436,7 +457,7 @@ async def get_users_by_filter(self, filter):
query_parameters=UsersRequestBuilder.UsersRequestBuilderGetQueryParameters(
filter=filter,
select=["accountEnabled", "displayName", "mail", "mailNickname", "id", "userPrincipalName",
"userType", "onPremisesImmutableId", "usageLocation", "givenName", "surname"],
"userType", "onPremisesImmutableId", "usageLocation", "givenName", "surname", "companyName"],
count=True
),
headers={'ConsistencyLevel': "eventual", }
Expand Down
15 changes: 11 additions & 4 deletions plugins/modules/azure_rm_aduser_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@
returned: always
type: str
sample: Member
company_name:
description:
- The name of the company that the user is associated with.
type: str
returned: always
sample: "Test Company"
'''

from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common_ext import AzureRMModuleBase
Expand Down Expand Up @@ -234,21 +240,22 @@ def to_dict(self, object):
mail_nickname=object.mail_nickname,
mail=object.mail,
account_enabled=object.account_enabled,
user_type=object.user_type
user_type=object.user_type,
company_name=object.company_name
)

async def get_user(self, object):
request_configuration = UsersRequestBuilder.UsersRequestBuilderGetRequestConfiguration(
query_parameters=UsersRequestBuilder.UsersRequestBuilderGetQueryParameters(
select=["accountEnabled", "displayName", "mail", "mailNickname", "id", "userPrincipalName", "userType"]
select=["accountEnabled", "displayName", "mail", "mailNickname", "id", "userPrincipalName", "userType", "companyName"]
),
)
return await self._client.users.by_user_id(object).get(request_configuration=request_configuration)

async def get_users(self):
request_configuration = UsersRequestBuilder.UsersRequestBuilderGetRequestConfiguration(
query_parameters=UsersRequestBuilder.UsersRequestBuilderGetQueryParameters(
select=["accountEnabled", "displayName", "mail", "mailNickname", "id", "userPrincipalName", "userType"]
select=["accountEnabled", "displayName", "mail", "mailNickname", "id", "userPrincipalName", "userType", "companyName"]
),
)
users = []
Expand All @@ -269,7 +276,7 @@ async def get_users_by_filter(self, filter):
query_parameters=UsersRequestBuilder.UsersRequestBuilderGetQueryParameters(
filter=filter,
select=["accountEnabled", "displayName", "mail", "mailNickname", "id", "userPrincipalName",
"userType"],
"userType", "companyName"],
count=True
),
))
Expand Down

0 comments on commit c7f7dd8

Please sign in to comment.