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

CLI to disable matrix msgs #227

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 11 additions & 1 deletion oda_api/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,11 @@ def inspect(obj):

@tokencli.command()
@click.option("--disable-email", default=False, is_flag=True)
@click.option("--disable-matrix", default=False, is_flag=True)
@click.option("--matrix-room-id", default=None)
@click.option("--new-validity-hours", default=None, type=float)
@click.pass_obj
def modify(obj, disable_email, new_validity_hours):
def modify(obj, disable_email, disable_matrix, matrix_room_id, new_validity_hours):
token = obj['token']
decoded_token = obj['decoded_token']

Expand All @@ -140,6 +142,14 @@ def mutate_token_payload(payload):
# TODO: think if need this
# new_payload['msfail'] = False

if disable_matrix:
logger.info("disabling matrix submission")
new_payload['mxsub'] = False
new_payload['mxdone'] = False

if matrix_room_id is not None:
logger.info("setting matrix room id")
new_payload['mxroomid'] = matrix_room_id

if new_validity_hours is not None:
new_payload['exp'] = time.time() + new_validity_hours * 3600
Expand Down
13 changes: 8 additions & 5 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def test_token_inspect(token_placement, default_token, monkeypatch, caplog, tmpd
monkeypatch.setenv('ODA_TOKEN', '')

if token_placement == 'env':
monkeypatch.setenv('ODA_TOKEN', default_token)
monkeypatch.setenv('ODA_TOKEN', default_token)

elif token_placement == 'cwddotfile':
with open(oda_token_cwd_fn, "w") as f:
f.write(default_token)
Expand Down Expand Up @@ -57,15 +57,18 @@ def test_token_modify(default_token, secret_key, monkeypatch, caplog):
assert '"msdone": false' not in caplog.text

runner = CliRunner()
result = runner.invoke(cli.tokencli, ['-s', secret_key, 'modify', "--disable-email", "--new-validity-hours", "100"], obj={})
result = runner.invoke(cli.tokencli, ['-s', secret_key, 'modify', "--disable-email", "--new-validity-hours", "100", "--disable-matrix", "--matrix-room-id", "test_room_id:matrix.org"], obj={})
assert result.exit_code == 0

assert '"sub": "[email protected]"' in caplog.text
assert 'your current token payload:' in caplog.text
assert 'your new token payload:' in caplog.text
assert '"msdone": false' in caplog.text
assert '"mssub": false' in caplog.text

assert '"mssub": false' in caplog.text
assert '"mxdone": false' in caplog.text
assert '"mxsub": false' in caplog.text
assert '"mxroomid": "test_room_id:matrix.org"' in caplog.text

def test_get(dispatcher_live_fixture, caplog, monkeypatch, tmpdir):
runner = CliRunner()
result = runner.invoke(cli.cli, ['-u', dispatcher_live_fixture, 'get'], obj={})
Expand Down
Loading