Skip to content

Commit

Permalink
merged config to context group
Browse files Browse the repository at this point in the history
  • Loading branch information
jiri_otoupal authored and jiri_otoupal committed Mar 6, 2024
1 parent 929d0a6 commit b0ca896
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 112 deletions.
5 changes: 3 additions & 2 deletions abst/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@
"CLI Command making OCI Bastion and kubernetes usage simple and fast"
)

__version__ = "2.3.24"
__version__ = "2.3.25"
__author__ = "Jiri Otoupal"
__author_email__ = "jiri-otoupal@ips-database.eu"
__license__ = "MIT"
__url__ = "https://github.com/jiri-otoupal/abst"
__pypi_repo__ = "https://pypi.org/project/abst/"

__version_name__ = "Formatted Giraffe"
__version_name__ = "Formatted-Merged Giraffe"
__change_log__ = """
* Added new option to context config so user can input custom ssh arguments to 'ssh-custom-arguments' key in context\n
* Listing context will show last usage time\n
* Changed formatting of 'abst context list' and 'abst parallel list'\n
* Merged Config to Context group
"""
Empty file.
108 changes: 0 additions & 108 deletions abst/cli_commands/config_cli/commands.py

This file was deleted.

99 changes: 99 additions & 0 deletions abst/cli_commands/context/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from rich.tree import Tree

from abst.bastion_support.oci_bastion import Bastion
from abst.cfg_func import __upgrade
from abst.config import default_contexts_location, share_excluded_keys
from abst.tools import get_context_path
from abst.utils.misc_funcs import get_context_data, setup_calls, get_context_set_data
Expand Down Expand Up @@ -115,7 +116,105 @@ def paste(name, debug=False):
rich.print(f"Wrote config into '{path}'")


@context.command("generate", help="Will generate sample json and overwrite changes")
@click.option("--debug", is_flag=True, default=False)
@click.argument("context-name", default=None, required=False)
def generate(debug, context_name):
setup_calls(debug)

path = get_context_path(context_name)

Bastion.create_default_locations()
td = Bastion.generate_sample_dict()
creds_path = Bastion.write_creds_json(td, path)
print(
f"Sample credentials generated, please fill 'creds.json' in {creds_path} with "
f"your credentials for this to work, you can use 'abst json fill "
f"{context_name if context_name else ''}'"
)


@context.command(
"fill", help="Fills Json config with credentials you enter interactively"
)
@click.option("--debug", is_flag=True, default=False)
@click.argument("context-name", default=None, required=False)
def fill(debug, context_name):
setup_calls(debug)

path = get_context_path(context_name)

if not path.exists():
rich.print("Generating sample Creds file")
Bastion.create_default_locations()
td = Bastion.generate_sample_dict()
Bastion.write_creds_json(td, path)

if not default_contexts_location.exists():
rich.print("Generating contexts location")
Bastion.create_default_locations()

rich.print(f"[green]Filling {str(path)}")
rich.print("Please fill field one by one as displayed")
n_dict = dict()

creds_json_ro = Bastion.load_json(path)

for key, value in creds_json_ro.items():
n_dict[key] = inquirer.text(
message=f"{key.capitalize()}:", default=value
).execute()
rich.print("\n[red]New json looks like this:[/red]")
rich.print_json(data=n_dict)
if inquirer.confirm(message="Write New Json ?", default=False).execute():
Bastion.write_creds_json(n_dict, path)
rich.print("[green]Wrote changes[/green]")
else:
rich.print("[red]Fill interrupted, nothing changed[/red]")


@context.command(
"locate", help="Locates Json config with credentials you enter interactively"
)
@click.option("--debug", is_flag=True, default=False)
@click.argument("context-name", default=None, required=False)
def locate(debug, context_name):
setup_calls(debug)

path = get_context_path(context_name)

if path.exists():
rich.print(f"[green]Config file location: {path.absolute()}[/green]")
else:
rich.print(
f"[red]Config does not exist yet, future location"
f" {path.absolute()}[/red]"
)


@context.command(
"upgrade", help="Upgrades Json config with credentials you enter interactively"
)
@click.option("--debug", is_flag=True, default=False)
@click.option("--all", is_flag=True, default=False)
@click.argument("context-name", default=None, required=False)
def upgrade(debug, context_name, all):
setup_calls(debug)

path = get_context_path(context_name)

if not path.exists():
rich.print("[green]No config to upgrade[/green]")
return

__upgrade(context_name, path, all)


ctx.add_command(_list, "list")
ctx.add_command(display, "display")
ctx.add_command(share, "share")
ctx.add_command(paste, "paste")
ctx.add_command(generate, "generate")
ctx.add_command(fill, "fill")
ctx.add_command(locate, "locate")
ctx.add_command(upgrade)
2 changes: 0 additions & 2 deletions abst/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from abst.__version__ import __version_name__, __version__, __change_log__
from abst.bastion_support.bastion_scheduler import BastionScheduler
from abst.bastion_support.oci_bastion import Bastion
from abst.cli_commands.config_cli.commands import config
from abst.cli_commands.context.commands import context, ctx
from abst.cli_commands.cp_cli.commands import cp
from abst.cli_commands.create_cli.commands import create
Expand Down Expand Up @@ -118,7 +117,6 @@ def print_changelog(_config):
signal.signal(signal.SIGABRT, BastionScheduler.kill_all)

cli.add_command(parallel)
cli.add_command(config)
cli.add_command(context)
cli.add_command(ctx)
cli.add_command(helm)
Expand Down

0 comments on commit b0ca896

Please sign in to comment.