Refactor DecortAccountInfo class (`MODULE_ARGS` attribute -> `module_args` property)

main
Dmitriy Smirnov 7 months ago
parent f00055e009
commit 77a2b6a182

@ -23,65 +23,8 @@ from ansible.module_utils.decort_utils import DecortController
class DecortAccountInfo(DecortController):
MODULE_ARGS = dict(
argument_spec=dict(
app_id=dict(
type='str',
fallback=(env_fallback, ['DECORT_APP_ID'])
),
app_secret=dict(
type='str',
fallback=(env_fallback, ['DECORT_APP_SECRET']),
no_log=True
),
authenticator=dict(
type='str',
required=True,
choices=['oauth2', 'jwt']
),
controller_url=dict(
type='str',
required=True
),
id=dict(
type='int',
),
jwt=dict(
type='str',
fallback=(env_fallback, ['DECORT_JWT']),
no_log=True
),
name=dict(
type='str',
),
oauth2_url=dict(
type='str',
fallback=(env_fallback, ['DECORT_OAUTH2_URL'])
),
resource_consumption=dict(
type='bool',
default=False
),
verify_ssl=dict(
type='bool',
default=True
),
),
mutually_exclusive=[
('id', 'name')
],
required_one_of=[
('id', 'name')
],
required_if=[
('authenticator', 'oauth2',
('oauth2_url', 'app_id', 'app_secret')),
('authenticator', 'jwt', ('jwt',))
]
)
def __init__(self):
amodule = AnsibleModule(**self.MODULE_ARGS, supports_check_mode=True)
amodule = AnsibleModule(**self.module_args, supports_check_mode=True)
super().__init__(amodule)
@ -92,6 +35,65 @@ class DecortAccountInfo(DecortController):
fail_if_not_found=True
)
@property
def module_args(self) -> dict:
return dict(
argument_spec=dict(
app_id=dict(
type='str',
fallback=(env_fallback, ['DECORT_APP_ID'])
),
app_secret=dict(
type='str',
fallback=(env_fallback, ['DECORT_APP_SECRET']),
no_log=True
),
authenticator=dict(
type='str',
required=True,
choices=['oauth2', 'jwt']
),
controller_url=dict(
type='str',
required=True
),
id=dict(
type='int',
),
jwt=dict(
type='str',
fallback=(env_fallback, ['DECORT_JWT']),
no_log=True
),
name=dict(
type='str',
),
oauth2_url=dict(
type='str',
fallback=(env_fallback, ['DECORT_OAUTH2_URL'])
),
resource_consumption=dict(
type='bool',
default=False
),
verify_ssl=dict(
type='bool',
default=True
),
),
mutually_exclusive=[
('id', 'name')
],
required_one_of=[
('id', 'name')
],
required_if=[
('authenticator', 'oauth2',
('oauth2_url', 'app_id', 'app_secret')),
('authenticator', 'jwt', ('jwt',))
]
)
def exit(self):
self.result['facts'] = self.facts
self.amodule.exit_json(**self.result)

Loading…
Cancel
Save