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] New CLI tool for node operators #268

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

odesenfans
Copy link
Contributor

We now provide a CLI tool that integrates all the operations
commonly performed by node operators. Currently, this CLI
allows to:

  • generate private keys for the node, replacing a functionality
    that was implemented in the CCN main app directly.
  • run migrations, replacing the config updater script.

@odesenfans
Copy link
Contributor Author

After discussion with @hoh regarding the garbage collector, we decided to do garbage collection differently from what is proposed in #250. The idea is that the GC will be invoked manually for the time being. To make this easier for node operators, we decided to introduce a new CLI tool that will implement useful commands for node operators. This PR is the initial work for this, before the introduction of the GC.

To do / To discuss:

  • update the documentation
  • put the CLI in a different Python module? (requires to split the CCN in several modules)
  • A better name for the tool?
$ ccn_cli --help
Usage: ccn_cli [OPTIONS] COMMAND [ARGS]...

  Aleph Core Channel Node CLI for operators.

Options:
  --config PATH                   Path to the configuration file of the CCN.
                                  Defaults to <cwd>/config.yml.
  --key-dir PATH                  Path to the key directory. Defaults to
                                  <cwd>/keys/.
  --verbose / --no-verbose        Show more information.  [default: no-
                                  verbose]
  --install-completion [bash|zsh|fish|powershell|pwsh]
                                  Install completion for the specified shell.
  --show-completion [bash|zsh|fish|powershell|pwsh]
                                  Show completion for the specified shell, to
                                  copy it or customize the installation.
  --help                          Show this message and exit.

Commands:
  keys        Operations on private keys.
  migrations  Run DB migrations.
Usage: ccn_cli keys [OPTIONS] COMMAND [ARGS]...

  Operations on private keys.

Options:
  --help  Show this message and exit.

Commands:
  generate  Generates a new set of private/public keys for the Core...
  show      Prints the private key of the node.
Usage: ccn_cli migrations [OPTIONS] COMMAND [ARGS]...

  Run DB migrations.

Options:
  --help  Show this message and exit.

Commands:
  downgrade
  upgrade

@odesenfans odesenfans marked this pull request as ready for review May 17, 2022 08:37
@odesenfans odesenfans requested a review from hoh May 17, 2022 08:37
@odesenfans odesenfans changed the base branch from dev to master July 2, 2022 16:09
odesenfans and others added 2 commits September 26, 2022 14:20
Problem: web wallets do not allow signing raw messages. Instead,
they require binary payloads in a specific format.

Solution: support Micheline-style signatures, i.e. signatures
supported by wallets like Beacon.

Users can now use Micheline or raw signatures by specifying
the `signature.signingType` field to "micheline" or "raw".
By default, "raw" is assumed.

Co-authored-by: Mike Hukiewitz <[email protected]>
We now provide a CLI tool that integrates all the operations
commonly performed by node operators. Currently, this CLI
allows to:

* generate private keys for the node, replacing a functionality
  that was implemented in the CCN main app directly.
* run migrations, replacing the config updater script.
@odesenfans odesenfans changed the base branch from master to dev October 2, 2022 23:19
Copy link
Member

@hoh hoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments, looks good overall 👍

class CliConfig:
config_file_path: Path
key_dir: Path
verbose: bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No default ?

from typing import cast
from aleph.ccn_cli.services.keys import generate_keypair, save_keys

keys_ns = typer.Typer()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This naming does not seem clear to me. The habit in Typer is app = typer.Typer(), so I would base the naming on that.

Suggested change
keys_ns = typer.Typer()
app = typer.Typer()

The keys will be created in the key directory. You can modify the destination
by using the --key-dir option.
"""
cli_config = cast(CliConfig, ctx.obj)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This casting is not obvious. Would it be worth adding a comment to explain it ?

by using the --key-dir option.
"""
cli_config = cast(CliConfig, ctx.obj)
print(cli_config)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this print ?



@keys_ns.command()
def generate(ctx: typer.Context):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace generate with the simpler create term ?

Suggested change
def generate(ctx: typer.Context):
def create(ctx: typer.Context):

except Exception as e:
typer.echo(f"{command} failed: {e}.", err=True)
if cli_config.verbose:
typer.echo(format_exc())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want to only display the exception in verbose mode ? I am wondering if it would not make it easier that any user can copy paste the traceback of an error without running the command again 🤔

return config


def import_module_from_path(path: str) -> ModuleType:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def import_module_from_path(path: str) -> ModuleType:
def import_module_from_path(path: Path) -> ModuleType:

import typer

from .cli_config import CliConfig
from .commands.keys import keys_ns
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If using the app naming convention in the module, this could become:

Suggested change
from .commands.keys import keys_ns
import .commands.keys.app as keys_app

else:

Suggested change
from .commands.keys import keys_ns
import . import commands.keys
...
app.add_typer(commands.keys.app, name="keys", help="Operations on private keys.")

return key_pair


def save_keys(key_pair: KeyPair, key_dir: str) -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use pathlib.Path ?

Comment on lines +9 to +14
def generate_keypair() -> KeyPair:
"""
Generates a new key pair for the node.
"""
key_pair = create_new_key_pair()
return key_pair
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this proxy function ?

Suggested change
def generate_keypair() -> KeyPair:
"""
Generates a new key pair for the node.
"""
key_pair = create_new_key_pair()
return key_pair
generate_keypair = create_new_key_pair

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants