From 7eedeb94d3e27524dc3a6fd4319bda1b88e23916 Mon Sep 17 00:00:00 2001 From: Moul <moul@moul.re> Date: Sun, 5 Jun 2022 16:42:50 +0200 Subject: [PATCH] [mypy] #163: Add type annotation on revocation --- silkaj/revocation.py | 27 +++++++++++---------------- tests/test_revocation.py | 3 +-- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/silkaj/revocation.py b/silkaj/revocation.py index 9ec1fe3d..f26422d6 100644 --- a/silkaj/revocation.py +++ b/silkaj/revocation.py @@ -16,6 +16,7 @@ import sys from pathlib import Path +from typing import Dict import click from duniterpy.api import bma @@ -42,7 +43,7 @@ REVOCATION_LOCAL_PATH = "revocation.txt" default=REVOCATION_LOCAL_PATH, ) @click.pass_context -def save(ctx: click.core.Context, file: str): +def save(ctx: click.Context, file: str) -> None: currency = get_currency() key = auth.auth_method() @@ -53,7 +54,6 @@ def save(ctx: click.core.Context, file: str): if ctx.obj["DRY_RUN"]: click.echo(rev_doc.signed_raw()) - return SUCCESS_EXIT_STATUS idty_table = idty_tools.display_identity(rev_doc.identity) click.echo(idty_table.draw()) @@ -65,7 +65,6 @@ def save(ctx: click.core.Context, file: str): save_doc(file, rev_doc.signed_raw(), key.pubkey) else: click.echo("Ok, goodbye!") - return SUCCESS_EXIT_STATUS @click.command( @@ -73,7 +72,7 @@ def save(ctx: click.core.Context, file: str): help="Create and publish revocation document. Will revoke the identity immediately.", ) @click.pass_context -def revoke_now(ctx: click.core.Context): +def revoke_now(ctx: click.Context) -> None: currency = get_currency() warn_before_dry_run_or_display(ctx) @@ -86,7 +85,6 @@ def revoke_now(ctx: click.core.Context): if ctx.obj["DRY_RUN"]: click.echo(rev_doc.signed_raw()) - return SUCCESS_EXIT_STATUS idty_table = idty_tools.display_identity(rev_doc.identity) click.echo(idty_table.draw()) @@ -107,12 +105,11 @@ Optionnaly takes the document filename.", default=REVOCATION_LOCAL_PATH, ) @click.pass_context -def verify(ctx: click.core.Context, file: str): +def verify(ctx: click.Context, file: str) -> None: rev_doc = verify_document(file) if ctx.obj["DRY_RUN"]: click.echo(rev_doc.signed_raw()) - return SUCCESS_EXIT_STATUS idty_table = idty_tools.display_identity(rev_doc.identity) click.echo(idty_table.draw()) @@ -120,7 +117,6 @@ def verify(ctx: click.core.Context, file: str): click.echo(rev_doc.signed_raw()) click.echo("Revocation document is valid.") - return SUCCESS_EXIT_STATUS @click.command( @@ -133,13 +129,13 @@ Optionnaly takes the document filename.", default=REVOCATION_LOCAL_PATH, ) @click.pass_context -def publish(ctx: click.core.Context, file: str): +def publish(ctx: click.Context, file: str) -> None: + warn_before_dry_run_or_display(ctx) rev_doc = verify_document(file) if ctx.obj["DRY_RUN"]: click.echo(rev_doc.signed_raw()) - return SUCCESS_EXIT_STATUS idty_table = idty_tools.display_identity(rev_doc.identity) click.echo(idty_table.draw()) @@ -150,12 +146,12 @@ def publish(ctx: click.core.Context, file: str): send_document(bma.wot.revoke, rev_doc) -def warn_before_dry_run_or_display(ctx): +def warn_before_dry_run_or_display(ctx: click.Context) -> None: if ctx.obj["DRY_RUN"]: click.echo("WARNING: the document will only be displayed and will not be sent.") -def warn_before_sending_document(): +def warn_before_sending_document() -> None: click.secho("/!\\WARNING/!\\", blink=True, fg="red") click.echo( "This identity will be revoked.\n\ @@ -165,7 +161,7 @@ All currently sent certifications will remain valid until they expire." tui.send_doc_confirmation("revocation document immediately") -def create_revocation_doc(id, pubkey: str, currency: str): +def create_revocation_doc(id: Dict, pubkey: str, currency: str) -> Revocation: """ Creates an unsigned revocation document. id is the dict object containing id infos from request wot.requirements @@ -183,7 +179,7 @@ def create_revocation_doc(id, pubkey: str, currency: str): ) -def save_doc(path: str, content: str, pubkey: str): +def save_doc(path: str, content: str, pubkey: str) -> None: pubkey_cksum = tui.gen_pubkey_checksum(pubkey) rev_path = Path(path) # Ask confirmation if the file exists @@ -202,10 +198,9 @@ generated revocation document corresponding to {pubkey_cksum} public key?" click.echo( f"Revocation document file stored into `{path}` for following public key: {pubkey_cksum}" ) - return SUCCESS_EXIT_STATUS -def verify_document(doc: str): +def verify_document(doc: str) -> Revocation: """ This checks that: - that the revocation signature is valid. diff --git a/tests/test_revocation.py b/tests/test_revocation.py index 956a5d7a..9056f962 100644 --- a/tests/test_revocation.py +++ b/tests/test_revocation.py @@ -367,10 +367,9 @@ def test_revocation_cli_save(display, dry_run, file, user_input, expected, monke "", [ "Version: 10", - ], - [ "Revocation document is valid.\n", ], + [], ), ( False, -- GitLab