diff --git a/abst/__version__.py b/abst/__version__.py index f4b4df2..6b4d52b 100644 --- a/abst/__version__.py +++ b/abst/__version__.py @@ -10,7 +10,7 @@ "CLI Command making OCI Bastion and kubernetes usage simple and fast" ) -__version__ = "2.3.22" +__version__ = "2.3.23" __author__ = "Jiri Otoupal" __author_email__ = "jiri-otoupal@ips-database.eu" __license__ = "MIT" @@ -23,4 +23,6 @@ * Sharing and Pasting now works for sets too, you can use set_name/context for both\n * When pasting, it will ask if you want to change IP and for bastion name renaming\n * Removed unused packages\n +* Fixed filename .json search\n +* Abst is filtering not json files from context search\n """ diff --git a/abst/bastion_support/bastion_scheduler.py b/abst/bastion_support/bastion_scheduler.py index 2e47119..be16477 100644 --- a/abst/bastion_support/bastion_scheduler.py +++ b/abst/bastion_support/bastion_scheduler.py @@ -134,7 +134,8 @@ def run(cls, force=False, set_dir: Optional[Path] = None): t.start() rich.print(f"Started {context_name}") else: - for context_path in filter(lambda p: not str(p.name).startswith("."), set_dir.iterdir()): + for context_path in filter(lambda p: not str(p.name).startswith(".") and str(p.name).endswith(".json"), + set_dir.iterdir()): if cls.stopped: return context_name = context_path.name[:-5] @@ -149,7 +150,6 @@ def run(cls, force=False, set_dir: Optional[Path] = None): t.start() rich.print(f"Started {context_name}") - cls.__display_loop() @classmethod diff --git a/abst/cfg_func.py b/abst/cfg_func.py index c490d9b..3a34e15 100644 --- a/abst/cfg_func.py +++ b/abst/cfg_func.py @@ -29,7 +29,8 @@ def __upgrade(context_name, path, _all): for file in default_contexts_location.iterdir(): append_minimizable(file, minimize_files) - for set_folder in filter(lambda p: not str(p.name).startswith("."), default_parallel_sets_location.iterdir()): + for set_folder in filter(lambda p: not str(p.name).startswith(".") and str(p.name).endswith(".json"), + default_parallel_sets_location.iterdir()): for file in set_folder.iterdir(): if file.name.startswith(".") or not append_minimizable(file, minimize_files): continue diff --git a/abst/cli_commands/context/commands.py b/abst/cli_commands/context/commands.py index f322edb..cd1c5e6 100644 --- a/abst/cli_commands/context/commands.py +++ b/abst/cli_commands/context/commands.py @@ -47,10 +47,10 @@ def display(name, debug=False): @context.command( help="Will print context without local paths and put it in clipboard for sharing") @click.option("--debug", is_flag=True, default=False) +@click.option("--raw", is_flag=True, default=False) @click.argument("name") -def share(name: str, debug=False): +def share(name: str, debug=False, raw=False): setup_calls(debug) - rich.print("Copied context into clipboard") if "/" in name: data = get_context_set_data(name) @@ -58,12 +58,17 @@ def share(name: str, debug=False): data = get_context_data(name) if data is None: return + for key in share_excluded_keys: data.pop(key, None) data["default-name"] = "!YOUR NAME!" + + if not raw: + rich.print(f"[bold]Context '{name}' config contents:[/bold]\n") + logging.debug("Data transmitted into clipboard") + pyperclip.copy(str(data)) + rich.print("Copied context into clipboard") rich.print_json(data=data) - logging.debug("Data transmitted into clipboard") - pyperclip.copy(str(data)) @context.command(help="Will paste context from clipboard into provided context name") diff --git a/abst/cli_commands/parallel/commands.py b/abst/cli_commands/parallel/commands.py index 878b243..70567d9 100644 --- a/abst/cli_commands/parallel/commands.py +++ b/abst/cli_commands/parallel/commands.py @@ -66,7 +66,7 @@ def _list(debug): setup_calls(debug) rich.print("Sets in parallel folder") for _set in default_parallel_sets_location.iterdir(): - if _set.name.startswith("."): + if _set.name.startswith(".") and not _set.name.endswith(".json"): continue rich.print(f" {_set.name}") for ctx in _set.iterdir(): diff --git a/abst/tools.py b/abst/tools.py index 9af5e69..8a87d2e 100644 --- a/abst/tools.py +++ b/abst/tools.py @@ -39,7 +39,7 @@ def display_scheduled(set_dir: Optional[Path] = None): table.add_column("Active", justify="right", style="green", no_wrap=True) table.add_column("Status", justify="right", style="green", no_wrap=True) if set_dir: - for context_path in filter(lambda p: not str(p.name).startswith("."), + for context_path in filter(lambda p: not str(p.name).startswith(".") and str(p.name).endswith(".json"), set_dir.iterdir()): conf = Bastion.load_json(context_path) context_name = context_path.name[:-5] diff --git a/abst/utils/misc_funcs.py b/abst/utils/misc_funcs.py index 24f354c..ef1fb8b 100644 --- a/abst/utils/misc_funcs.py +++ b/abst/utils/misc_funcs.py @@ -47,10 +47,10 @@ def print_eligible(searched: str): def get_context_data(name) -> Optional[dict]: - if name in [file.name.replace(".json", "") for file in - Path(default_contexts_location).iterdir()]: - rich.print("[bold]Context config contents:[/bold]\n") - with open(Path(default_contexts_location) / (name + ".json"), "r") as f: + normalized_name = name if ".json" in name else name + ".json" + if normalized_name in [file.name for file in + Path(default_contexts_location).iterdir()]: + with open(Path(default_contexts_location) / normalized_name, "r") as f: data = json.load(f) return data else: @@ -63,13 +63,14 @@ def get_context_set_data(name) -> Optional[dict]: if len(path) != 2: rich.print(f"[red]Invalid path '{name}'[/red]") - if path[0] in [file.name for file in - Path(default_parallel_sets_location).iterdir()]: - if path[1] in [file.name.replace(".json", "") for file in - Path(default_parallel_sets_location / path[0]).iterdir()]: - rich.print(f"[bold]Context '{name}' config contents:[/bold]\n") + set_dir_name = path[0] + if set_dir_name in [file.name for file in + Path(default_parallel_sets_location).iterdir()]: + normalized_name = path[1] if ".json" in path[1] else path[1] + ".json" + if normalized_name in [file.name for file in + Path(default_parallel_sets_location / set_dir_name).iterdir()]: with open( - Path(default_parallel_sets_location) / path[0] / (path[1] + ".json"), + Path(default_parallel_sets_location) / set_dir_name / normalized_name, "r") as f: data = json.load(f) return data