parent
ba305a0ccb
commit
aa3f84095f
@ -0,0 +1,342 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
# Copyright: ...
|
||||||
|
# ...
|
||||||
|
|
||||||
|
DOCUMENTATION = r'''
|
||||||
|
---
|
||||||
|
module: decort_user_info
|
||||||
|
|
||||||
|
version_added: "2.16"
|
||||||
|
|
||||||
|
description: See L(Module Documentation,https://repository.basistech.ru/BASIS/decort-ansible/wiki/Home).
|
||||||
|
'''
|
||||||
|
|
||||||
|
# EXAMPLES = r'''
|
||||||
|
# '''
|
||||||
|
|
||||||
|
# RETURN = r'''
|
||||||
|
# '''
|
||||||
|
|
||||||
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
from ansible.module_utils.decort_utils import DecortController
|
||||||
|
|
||||||
|
|
||||||
|
class DecortUserInfo(DecortController):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(AnsibleModule(**self.amodule_init_args))
|
||||||
|
self.check_amodule_args()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def amodule_init_args(self) -> dict:
|
||||||
|
return self.pack_amodule_init_args(
|
||||||
|
argument_spec=dict(
|
||||||
|
accounts=dict(
|
||||||
|
type='dict',
|
||||||
|
options=dict(
|
||||||
|
deleted=dict(
|
||||||
|
type='bool',
|
||||||
|
default=False,
|
||||||
|
),
|
||||||
|
filter=dict(
|
||||||
|
type='dict',
|
||||||
|
options=dict(
|
||||||
|
rights=dict(
|
||||||
|
type='str',
|
||||||
|
choices=[
|
||||||
|
e.value
|
||||||
|
for e in self.AccountUserRights
|
||||||
|
],
|
||||||
|
),
|
||||||
|
id=dict(
|
||||||
|
type='int',
|
||||||
|
),
|
||||||
|
name=dict(
|
||||||
|
type='str',
|
||||||
|
),
|
||||||
|
status=dict(
|
||||||
|
type='str',
|
||||||
|
choices=[
|
||||||
|
e.value for e in self.AccountStatus
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
pagination=dict(
|
||||||
|
type='dict',
|
||||||
|
options=dict(
|
||||||
|
number=dict(
|
||||||
|
type='int',
|
||||||
|
default=1,
|
||||||
|
),
|
||||||
|
size=dict(
|
||||||
|
type='int',
|
||||||
|
required=True,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
resource_consumption=dict(
|
||||||
|
type='bool',
|
||||||
|
default=False,
|
||||||
|
),
|
||||||
|
sorting=dict(
|
||||||
|
type='dict',
|
||||||
|
options=dict(
|
||||||
|
asc=dict(
|
||||||
|
type='bool',
|
||||||
|
default=True,
|
||||||
|
),
|
||||||
|
field=dict(
|
||||||
|
type='str',
|
||||||
|
choices=[
|
||||||
|
e.value
|
||||||
|
for e in self.AccountSortableField
|
||||||
|
],
|
||||||
|
required=True,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
api_methods=dict(
|
||||||
|
type='bool',
|
||||||
|
default=False,
|
||||||
|
),
|
||||||
|
audits=dict(
|
||||||
|
type='dict',
|
||||||
|
options=dict(
|
||||||
|
filter=dict(
|
||||||
|
type='dict',
|
||||||
|
options=dict(
|
||||||
|
api_method=dict(
|
||||||
|
type='str',
|
||||||
|
),
|
||||||
|
status_code=dict(
|
||||||
|
type='str',
|
||||||
|
),
|
||||||
|
time=dict(
|
||||||
|
type='dict',
|
||||||
|
options=dict(
|
||||||
|
start=dict(
|
||||||
|
type='dict',
|
||||||
|
options=dict(
|
||||||
|
unix=dict(
|
||||||
|
type='int',
|
||||||
|
),
|
||||||
|
date_time=dict(
|
||||||
|
type='str',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
mutually_exclusive=[
|
||||||
|
('unix', 'date_time'),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
end=dict(
|
||||||
|
type='dict',
|
||||||
|
options=dict(
|
||||||
|
unix=dict(
|
||||||
|
type='int',
|
||||||
|
),
|
||||||
|
date_time=dict(
|
||||||
|
type='str',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
mutually_exclusive=[
|
||||||
|
('unix', 'date_time'),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
pagination=dict(
|
||||||
|
type='dict',
|
||||||
|
options=dict(
|
||||||
|
number=dict(
|
||||||
|
type='int',
|
||||||
|
default=1,
|
||||||
|
),
|
||||||
|
size=dict(
|
||||||
|
type='int',
|
||||||
|
required=True,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
objects_search=dict(
|
||||||
|
type='str',
|
||||||
|
),
|
||||||
|
resource_consumption=dict(
|
||||||
|
type='bool',
|
||||||
|
default=False,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
supports_check_mode=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
def check_amodule_args(self):
|
||||||
|
"""
|
||||||
|
Additional validation of Ansible Module arguments.
|
||||||
|
This validation cannot be implemented using
|
||||||
|
Ansible Argument spec.
|
||||||
|
"""
|
||||||
|
|
||||||
|
check_error = False
|
||||||
|
|
||||||
|
match self.aparams['audits']:
|
||||||
|
case {'filter': {'time':
|
||||||
|
{'start': {'date_time': str() as dt_str}}
|
||||||
|
}
|
||||||
|
}:
|
||||||
|
if self.dt_str_to_sec(dt_str=dt_str) is None:
|
||||||
|
self.message(self.MESSAGES.str_not_parsed(string=dt_str))
|
||||||
|
check_error = True
|
||||||
|
match self.aparams['audits']:
|
||||||
|
case {'filter': {'time':
|
||||||
|
{'end': {'date_time': str() as dt_str}}
|
||||||
|
}
|
||||||
|
}:
|
||||||
|
if self.dt_str_to_sec(dt_str=dt_str) is None:
|
||||||
|
self.message(self.MESSAGES.str_not_parsed(string=dt_str))
|
||||||
|
check_error = True
|
||||||
|
|
||||||
|
if check_error:
|
||||||
|
self.exit(fail=True)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def mapped_accounts_args(self) -> None | dict:
|
||||||
|
"""
|
||||||
|
Map the module argument `accounts` to
|
||||||
|
arguments dictionary for the method
|
||||||
|
`DecortController.user_accounts`.
|
||||||
|
"""
|
||||||
|
|
||||||
|
input_args = self.aparams['accounts']
|
||||||
|
if not input_args:
|
||||||
|
return input_args
|
||||||
|
|
||||||
|
mapped_args = {}
|
||||||
|
|
||||||
|
mapped_args['deleted'] = input_args['deleted']
|
||||||
|
|
||||||
|
mapped_args['resource_consumption'] = (
|
||||||
|
input_args['resource_consumption']
|
||||||
|
)
|
||||||
|
|
||||||
|
input_args_filter = input_args['filter']
|
||||||
|
if input_args_filter:
|
||||||
|
input_args_filter_rights = input_args_filter['rights']
|
||||||
|
if input_args_filter_rights:
|
||||||
|
mapped_args['account_user_rights'] = (
|
||||||
|
self.AccountUserRights(input_args_filter_rights)
|
||||||
|
)
|
||||||
|
|
||||||
|
mapped_args['account_id'] = input_args_filter['id']
|
||||||
|
|
||||||
|
mapped_args['account_name'] = input_args_filter['name']
|
||||||
|
|
||||||
|
input_args_filter_status = input_args_filter['status']
|
||||||
|
if input_args_filter_status:
|
||||||
|
mapped_args['account_status'] = (
|
||||||
|
self.AccountStatus(input_args_filter_status)
|
||||||
|
)
|
||||||
|
|
||||||
|
input_args_pagination = input_args['pagination']
|
||||||
|
if input_args_pagination:
|
||||||
|
mapped_args['page_number'] = input_args_pagination['number']
|
||||||
|
mapped_args['page_size'] = input_args_pagination['size']
|
||||||
|
|
||||||
|
input_args_sorting = input_args['sorting']
|
||||||
|
if input_args_sorting:
|
||||||
|
mapped_args['sort_by_asc'] = input_args_sorting['asc']
|
||||||
|
|
||||||
|
input_args_sorting_field = input_args_sorting['field']
|
||||||
|
if input_args_sorting_field:
|
||||||
|
mapped_args['sort_by_field'] = (
|
||||||
|
self.AccountSortableField(input_args_sorting_field)
|
||||||
|
)
|
||||||
|
|
||||||
|
return mapped_args
|
||||||
|
|
||||||
|
@property
|
||||||
|
def mapped_audits_args(self):
|
||||||
|
"""
|
||||||
|
Map the module argument `audits` to
|
||||||
|
arguments dictionary for the method
|
||||||
|
`DecortController.user_audits`.
|
||||||
|
"""
|
||||||
|
|
||||||
|
input_args = self.aparams['audits']
|
||||||
|
if not input_args:
|
||||||
|
return input_args
|
||||||
|
|
||||||
|
mapped_args = {}
|
||||||
|
|
||||||
|
input_args_filter = input_args['filter']
|
||||||
|
if input_args_filter:
|
||||||
|
mapped_args['api_method'] = input_args_filter['api_method']
|
||||||
|
mapped_args['http_status_code'] = input_args_filter['status_code']
|
||||||
|
|
||||||
|
match input_args_filter['time']:
|
||||||
|
case {'start': {'unix': int() as start_unix_time}}:
|
||||||
|
mapped_args['start_unix_time'] = start_unix_time
|
||||||
|
case {'start': {'date_time': str() as start_dt_str}}:
|
||||||
|
mapped_args['start_unix_time'] = self.dt_str_to_sec(
|
||||||
|
dt_str=start_dt_str
|
||||||
|
)
|
||||||
|
match input_args_filter['time']:
|
||||||
|
case {'end': {'unix': int() as end_unix_time}}:
|
||||||
|
mapped_args['end_unix_time'] = end_unix_time
|
||||||
|
case {'end': {'date_time': str() as end_dt_str}}:
|
||||||
|
mapped_args['end_unix_time'] = self.dt_str_to_sec(
|
||||||
|
dt_str=end_dt_str
|
||||||
|
)
|
||||||
|
|
||||||
|
input_args_pagination = input_args['pagination']
|
||||||
|
if input_args_pagination:
|
||||||
|
mapped_args['page_number'] = input_args_pagination['number']
|
||||||
|
mapped_args['page_size'] = input_args_pagination['size']
|
||||||
|
|
||||||
|
return mapped_args
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
self.get_info()
|
||||||
|
self.exit()
|
||||||
|
|
||||||
|
def get_info(self):
|
||||||
|
self.facts = self.user_whoami()
|
||||||
|
self.id = self.facts['name']
|
||||||
|
|
||||||
|
user_get = self.user_get(id=self.id)
|
||||||
|
for key in ['emailaddresses', 'data']:
|
||||||
|
self.facts[key] = user_get[key]
|
||||||
|
|
||||||
|
if self.aparams['accounts']:
|
||||||
|
self.facts['accounts'] = self.user_accounts(
|
||||||
|
**self.mapped_accounts_args,
|
||||||
|
)
|
||||||
|
|
||||||
|
if self.aparams['resource_consumption']:
|
||||||
|
self.facts.update(self.user_resource_consumption())
|
||||||
|
|
||||||
|
if self.aparams['audits']:
|
||||||
|
self.facts['audits'] = self.user_audits(**self.mapped_audits_args)
|
||||||
|
|
||||||
|
if self.aparams['api_methods']:
|
||||||
|
self.facts['api_methods'] = self.user_api_methods(id=self.id)
|
||||||
|
|
||||||
|
|
||||||
|
search_string = self.aparams['objects_search']
|
||||||
|
if search_string:
|
||||||
|
self.facts['objects_search'] = self.user_objects_search(
|
||||||
|
search_string=search_string,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
DecortUserInfo().run()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,6 @@
|
|||||||
## Документация:
|
## Документация:
|
||||||
|
|
||||||
|
- [Модули Ansible версии 5.6.0](./5.6.0/Home.md)
|
||||||
- [Модули Ansible версии 5.5.0](./5.5.0/Home.md)
|
- [Модули Ansible версии 5.5.0](./5.5.0/Home.md)
|
||||||
- [Модули Ansible версии 5.4.0](./5.4.0/Home.md)
|
- [Модули Ansible версии 5.4.0](./5.4.0/Home.md)
|
||||||
- [Модули Ansible версии 5.3.0](./5.3.0/Home.md)
|
- [Модули Ansible версии 5.3.0](./5.3.0/Home.md)
|
||||||
|
Loading…
Reference in new issue