mirror of
https://github.com/famedly/ansible-collection-matrix
synced 2024-11-10 05:34:16 +00:00
fix: check-mode in modules behaves properly
This commit is contained in:
parent
bf7f2328e9
commit
61d5e59cb8
5 changed files with 30 additions and 8 deletions
|
@ -199,10 +199,6 @@ async def run_module():
|
|||
await module.fail_json(msg=missing_required_lib("matrix-nio"))
|
||||
|
||||
await module.matrix_login()
|
||||
|
||||
if module.check_mode:
|
||||
return result
|
||||
|
||||
action = module.params["state"]
|
||||
room_id = module.params["room_id"]
|
||||
user_ids = module.params["user_ids"]
|
||||
|
@ -211,6 +207,11 @@ async def run_module():
|
|||
if module.params["exclusive"] and action != "member":
|
||||
await module.fail_json(msg="exclusive=True can only be used with state=member")
|
||||
|
||||
# Handle ansible check mode
|
||||
if module.check_mode:
|
||||
result["members"] = user_ids
|
||||
await module.exit_json(**result)
|
||||
|
||||
# Create client object
|
||||
client = module.client
|
||||
|
||||
|
|
|
@ -116,7 +116,8 @@ async def run_module():
|
|||
await module.fail_json(msg=missing_required_lib("matrix-nio"))
|
||||
|
||||
if module.check_mode:
|
||||
return result
|
||||
result["changed"] = True
|
||||
await module.exit_json(**result)
|
||||
|
||||
await module.matrix_login()
|
||||
client = module.client
|
||||
|
@ -134,6 +135,8 @@ async def run_module():
|
|||
)
|
||||
if isinstance(response, RoomSendError):
|
||||
await module.fail_json(**result)
|
||||
else:
|
||||
result["changed"] = True
|
||||
|
||||
await module.exit_json(**result)
|
||||
|
||||
|
|
|
@ -111,6 +111,11 @@ async def run_module():
|
|||
await module.matrix_login()
|
||||
client = module.client
|
||||
|
||||
if module.check_mode:
|
||||
result["changed"] = True
|
||||
result["room_id"] = "!fakeRoomId:localhost"
|
||||
await module.exit_json(**result)
|
||||
|
||||
# Try to look up room_id
|
||||
room_id_resp = await client.room_resolve_alias(module.params["alias"])
|
||||
|
||||
|
|
|
@ -131,8 +131,11 @@ async def run_module():
|
|||
client = module.client
|
||||
|
||||
if module.check_mode:
|
||||
# TODO: Do proper check
|
||||
return result
|
||||
# TODO: Attempt to check if the state event is already present
|
||||
# Implementation note: this might not be possible as a previous check-moded
|
||||
# login token might be invalid / not provided
|
||||
result["changed"] = True
|
||||
await module.exit_json(**result)
|
||||
|
||||
failed = False
|
||||
|
||||
|
|
|
@ -124,7 +124,10 @@ async def run_module():
|
|||
await module.fail_json(msg=missing_required_lib("matrix-nio"))
|
||||
|
||||
if module.check_mode:
|
||||
return result
|
||||
result["changed"] = True
|
||||
result["device_id"] = "FAKEDEVICE"
|
||||
result["token"] = "syt_fake_token"
|
||||
await module.exit_json(**result)
|
||||
|
||||
failed = False
|
||||
|
||||
|
@ -137,6 +140,13 @@ async def run_module():
|
|||
if key is None:
|
||||
await module.fail_json(msg="A key has to be provided")
|
||||
|
||||
# Move check-mode handling after check for missing key
|
||||
if module.check_mode:
|
||||
result["changed"] = True
|
||||
result["device_id"] = "FAKEDEVICE"
|
||||
result["token"] = "syt_fake_token"
|
||||
await module.exit_json(**result)
|
||||
|
||||
admin = module.params["admin"]
|
||||
|
||||
method, path, data = Api.login(
|
||||
|
|
Loading…
Reference in a new issue