Skip to content

Commit

Permalink
add login command
Browse files Browse the repository at this point in the history
  • Loading branch information
SK1Y101 committed Jul 8, 2024
1 parent 0ca79d8 commit b2168ce
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
5 changes: 4 additions & 1 deletion anvil-python/anvil/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
)
from anvil.provider.local.commands import LocalProvider
from anvil.provider.local.deployment import LocalDeployment
from anvil.utils import CatchGroup
from anvil.utils import CatchGroup, juju_login

# Update the help options to allow -h in addition to --help for
# triggering the help for various commands
Expand Down Expand Up @@ -71,6 +71,9 @@ def main() -> None:
manifest.add_command(manifest_commands.show)
manifest.add_command(manifest_commands.generate)

# Miscellania
cli.add_command(juju_login)

cli(obj=deployment)


Expand Down
4 changes: 3 additions & 1 deletion anvil-python/anvil/provider/local/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,9 @@ def _print_output(token: str) -> None:


@click.command()
@click.option("-a", "--accept-defaults", help="Accept all defaults.", is_flag=True)
@click.option(
"-a", "--accept-defaults", help="Accept all defaults.", is_flag=True
)
@click.option("--token", type=str, help="Join token")
@click.option(
"--role",
Expand Down
23 changes: 23 additions & 0 deletions anvil-python/anvil/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@
import sys

import click
from rich.console import Console
from sunbeam.commands.juju import JujuLoginStep
from sunbeam.jobs.common import run_plan, run_preflight_checks
from sunbeam.plugins.interface.v1.base import PluginError

from anvil.jobs.checks import VerifyBootstrappedCheck
import anvil.provider
from anvil.provider.local.deployment import LocalDeployment

LOG = logging.getLogger(__name__)
LOCAL_ACCESS = "local"
REMOTE_ACCESS = "remote"
Expand All @@ -43,3 +50,19 @@ def __call__(self, *args, **kwargs): # type: ignore[no-untyped-def]
LOG.warn(message)
LOG.error("Error: %s", e)
sys.exit(1)


@click.command()
@click.pass_context
def juju_login(ctx: click.Context) -> None:
"""Login to the anvil controller."""
deployment: LocalDeployment = ctx.obj()
client = deployment.get_client()
console = Console()

preflight_checks = [VerifyBootstrappedCheck(client)]
run_preflight_checks(preflight_checks, console)

run_plan([JujuLoginStep(deployment.juju_account)], console)

console.print("Juju login complete.")

0 comments on commit b2168ce

Please sign in to comment.