opensearchcli 0.1.0__tar.gz → 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- opensearchcli-0.1.1/PKG-INFO +8 -0
- {opensearchcli-0.1.0 → opensearchcli-0.1.1}/pyproject.toml +4 -3
- {opensearchcli-0.1.0 → opensearchcli-0.1.1}/src/opensearchcli/cli.py +3 -0
- opensearchcli-0.1.1/src/opensearchcli/commands/config.py +174 -0
- {opensearchcli-0.1.0 → opensearchcli-0.1.1}/src/opensearchcli/commands/helpers.py +4 -1
- opensearchcli-0.1.1/src/opensearchcli.egg-info/PKG-INFO +8 -0
- opensearchcli-0.1.1/src/opensearchcli.egg-info/requires.txt +3 -0
- opensearchcli-0.1.0/PKG-INFO +0 -7
- opensearchcli-0.1.0/src/opensearchcli/commands/config.py +0 -59
- opensearchcli-0.1.0/src/opensearchcli.egg-info/PKG-INFO +0 -7
- opensearchcli-0.1.0/src/opensearchcli.egg-info/requires.txt +0 -2
- {opensearchcli-0.1.0 → opensearchcli-0.1.1}/README.md +0 -0
- {opensearchcli-0.1.0 → opensearchcli-0.1.1}/setup.cfg +0 -0
- {opensearchcli-0.1.0 → opensearchcli-0.1.1}/src/opensearchcli/__init__.py +0 -0
- {opensearchcli-0.1.0 → opensearchcli-0.1.1}/src/opensearchcli/commands/__init__.py +0 -0
- {opensearchcli-0.1.0 → opensearchcli-0.1.1}/src/opensearchcli/commands/cluster.py +0 -0
- {opensearchcli-0.1.0 → opensearchcli-0.1.1}/src/opensearchcli/commands/cluster_settings.py +0 -0
- {opensearchcli-0.1.0 → opensearchcli-0.1.1}/src/opensearchcli/commands/commands.py +0 -0
- {opensearchcli-0.1.0 → opensearchcli-0.1.1}/src/opensearchcli/commands/exceptions.py +0 -0
- {opensearchcli-0.1.0 → opensearchcli-0.1.1}/src/opensearchcli/commands/index.py +0 -0
- {opensearchcli-0.1.0 → opensearchcli-0.1.1}/src/opensearchcli/commands/index_settings.py +0 -0
- {opensearchcli-0.1.0 → opensearchcli-0.1.1}/src/opensearchcli/commands/raw.py +0 -0
- {opensearchcli-0.1.0 → opensearchcli-0.1.1}/src/opensearchcli/commands/snapshot.py +0 -0
- {opensearchcli-0.1.0 → opensearchcli-0.1.1}/src/opensearchcli.egg-info/SOURCES.txt +0 -0
- {opensearchcli-0.1.0 → opensearchcli-0.1.1}/src/opensearchcli.egg-info/dependency_links.txt +0 -0
- {opensearchcli-0.1.0 → opensearchcli-0.1.1}/src/opensearchcli.egg-info/entry_points.txt +0 -0
- {opensearchcli-0.1.0 → opensearchcli-0.1.1}/src/opensearchcli.egg-info/top_level.txt +0 -0
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "opensearchcli"
|
|
3
3
|
description = "A CLI tool for OpenSearch"
|
|
4
|
-
version = "0.1.
|
|
5
|
-
requires-python = "
|
|
4
|
+
version = "0.1.1"
|
|
5
|
+
requires-python = " <4,>=3.10"
|
|
6
6
|
dependencies = [
|
|
7
|
-
"opensearch-py>=3.1.0",
|
|
8
7
|
"typer>=0.20.0",
|
|
8
|
+
"opensearch-py (>=3.1.0,<4.0.0)",
|
|
9
|
+
"tomlkit>=0.13.3",
|
|
9
10
|
]
|
|
10
11
|
|
|
11
12
|
[project.scripts]
|
|
@@ -25,6 +25,9 @@ app.add_typer(
|
|
|
25
25
|
help="OpenSearch snapshot api commands",
|
|
26
26
|
)
|
|
27
27
|
app.add_typer(typer_instance=raw.app, name="raw", help="Make raw OpenSearch API calls")
|
|
28
|
+
app.add_typer(
|
|
29
|
+
typer_instance=config.app, name="config", help="Manage configuration profiles"
|
|
30
|
+
)
|
|
28
31
|
|
|
29
32
|
|
|
30
33
|
class OpenSearchCli:
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import tomlkit
|
|
3
|
+
from typing import Annotated, Sequence
|
|
4
|
+
|
|
5
|
+
import typer
|
|
6
|
+
from rich.console import Console
|
|
7
|
+
from rich.table import Table
|
|
8
|
+
|
|
9
|
+
app = typer.Typer(
|
|
10
|
+
rich_markup_mode="rich",
|
|
11
|
+
no_args_is_help=True,
|
|
12
|
+
help="Introspect available CLI commands",
|
|
13
|
+
)
|
|
14
|
+
console = Console()
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class ConfigProfile:
|
|
18
|
+
def __init__(self, profile_name: str, data: dict) -> None:
|
|
19
|
+
self.profile_name = profile_name
|
|
20
|
+
self._data = data
|
|
21
|
+
|
|
22
|
+
@property
|
|
23
|
+
def domain(self) -> str:
|
|
24
|
+
return self._data.get("domain", "")
|
|
25
|
+
|
|
26
|
+
@property
|
|
27
|
+
def username(self) -> str:
|
|
28
|
+
return self._data.get("username", "")
|
|
29
|
+
|
|
30
|
+
@property
|
|
31
|
+
def password(self) -> str:
|
|
32
|
+
return self._data.get("password", "")
|
|
33
|
+
|
|
34
|
+
def __str__(self) -> str:
|
|
35
|
+
return (
|
|
36
|
+
f"Profile Name: {self.profile_name}\n"
|
|
37
|
+
f"\tDomain: {self.domain}\n"
|
|
38
|
+
f"\tUsername: {self.username}\n"
|
|
39
|
+
f"\tPassword: {'*' * len(self.password) if self.password else ''}"
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
def to_toml(self):
|
|
43
|
+
return (
|
|
44
|
+
tomlkit.table()
|
|
45
|
+
.add("domain", self.domain)
|
|
46
|
+
.add("username", self.username)
|
|
47
|
+
.add("password", self.password)
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class Config:
|
|
52
|
+
def __init__(self, file_loc: str, profiles: list[ConfigProfile]) -> None:
|
|
53
|
+
self.file = file_loc
|
|
54
|
+
self.profiles = profiles
|
|
55
|
+
|
|
56
|
+
def find_profile_by_name(self, profile_name: str) -> ConfigProfile:
|
|
57
|
+
for profile in self.profiles:
|
|
58
|
+
if profile.profile_name == profile_name:
|
|
59
|
+
return profile
|
|
60
|
+
return ConfigProfile(profile_name="", data={})
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def read_config(config_file: str) -> Config:
|
|
64
|
+
if not os.path.isfile(path=config_file):
|
|
65
|
+
return Config(file_loc="", profiles=[ConfigProfile(profile_name="", data={})])
|
|
66
|
+
|
|
67
|
+
try:
|
|
68
|
+
with open(file=config_file, mode="rb") as _file:
|
|
69
|
+
data = tomlkit.load(_file)
|
|
70
|
+
except ValueError as error:
|
|
71
|
+
data = {}
|
|
72
|
+
print(f"invalid toml: {error}")
|
|
73
|
+
return Config(
|
|
74
|
+
file_loc=config_file,
|
|
75
|
+
profiles=[
|
|
76
|
+
ConfigProfile(profile_name=profile_name, data=data[profile_name])
|
|
77
|
+
for profile_name in data.keys()
|
|
78
|
+
],
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _get_profiles_table(profiles: Sequence[ConfigProfile]) -> Table:
|
|
83
|
+
table = Table(show_header=True, header_style="cyan")
|
|
84
|
+
table.add_column(header="Profile Name")
|
|
85
|
+
table.add_column(header="Domain")
|
|
86
|
+
table.add_column(header="Username")
|
|
87
|
+
table.add_column(header="Password")
|
|
88
|
+
for profile in profiles:
|
|
89
|
+
table.add_row(
|
|
90
|
+
f"{profile.profile_name}",
|
|
91
|
+
f"{profile.domain}",
|
|
92
|
+
f"{profile.username}",
|
|
93
|
+
f"{profile.password}",
|
|
94
|
+
)
|
|
95
|
+
return table
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
@app.command(name="list")
|
|
99
|
+
def list_profiles(ctx: typer.Context) -> None:
|
|
100
|
+
"""List all configuration profiles.
|
|
101
|
+
|
|
102
|
+
Display a table showing all configured profiles with their details.
|
|
103
|
+
"""
|
|
104
|
+
console.print(_get_profiles_table(profiles=ctx.obj.config.profiles))
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
@app.command(
|
|
108
|
+
name="show",
|
|
109
|
+
context_settings={"allow_extra_args": True, "ignore_unknown_options": True},
|
|
110
|
+
)
|
|
111
|
+
def show_profile(ctx: typer.Context, profile_name: str = "default") -> None:
|
|
112
|
+
"""Show details for a specific configuration profile.
|
|
113
|
+
|
|
114
|
+
Display the profile information for the given profile name.
|
|
115
|
+
|
|
116
|
+
Args:
|
|
117
|
+
profile_name: Name of the profile to display (default: "default")
|
|
118
|
+
"""
|
|
119
|
+
_profile = ctx.obj.config.find_profile_by_name(profile_name)
|
|
120
|
+
if not _profile:
|
|
121
|
+
typer.echo(message=f"No profile found for: {profile_name}")
|
|
122
|
+
return None
|
|
123
|
+
console.print(_get_profiles_table(profiles=[_profile]))
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _create_config_data(
|
|
127
|
+
domain: str, username: str, password: str
|
|
128
|
+
) -> tomlkit.TOMLDocument:
|
|
129
|
+
return (
|
|
130
|
+
tomlkit.table()
|
|
131
|
+
.add("domain", domain)
|
|
132
|
+
.add("username", username)
|
|
133
|
+
.add("password", password)
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
@app.command(name="add-profile")
|
|
138
|
+
def add_profile(
|
|
139
|
+
ctx: typer.Context,
|
|
140
|
+
password: Annotated[str, typer.Option(prompt=True, hide_input=True)],
|
|
141
|
+
profile_name: Annotated[str, typer.Option()],
|
|
142
|
+
domain: Annotated[str, typer.Option()],
|
|
143
|
+
username: Annotated[str, typer.Option()],
|
|
144
|
+
overwrite: Annotated[bool, typer.Option()] = False,
|
|
145
|
+
) -> None:
|
|
146
|
+
"""Create a new configuration file with default profile.
|
|
147
|
+
|
|
148
|
+
This command will prompt for domain, username, and password, then create
|
|
149
|
+
a configuration file at the specified location.
|
|
150
|
+
"""
|
|
151
|
+
config_file = ctx.obj.config_file_path
|
|
152
|
+
|
|
153
|
+
config_profiles = tomlkit.document()
|
|
154
|
+
if os.path.isfile(path=config_file):
|
|
155
|
+
with open(file=config_file, mode="rb") as _file:
|
|
156
|
+
config_profiles = tomlkit.load(_file)
|
|
157
|
+
|
|
158
|
+
if profile_name in config_profiles and not overwrite:
|
|
159
|
+
console.print(
|
|
160
|
+
f"[red]Profile '{profile_name}' already exists in {config_file}. Use --overwrite to replace it.[/red]"
|
|
161
|
+
)
|
|
162
|
+
raise typer.Exit(code=1)
|
|
163
|
+
|
|
164
|
+
config_profiles[profile_name] = _create_config_data(
|
|
165
|
+
domain=domain, username=username, password=password
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
os.makedirs(name=os.path.dirname(config_file), exist_ok=True)
|
|
169
|
+
with open(file=config_file, mode="w") as _file:
|
|
170
|
+
tomlkit.dump(config_profiles, _file)
|
|
171
|
+
|
|
172
|
+
console.print(
|
|
173
|
+
f"[green]✓ Configuration created successfully at {config_file}[/green]"
|
|
174
|
+
)
|
|
@@ -4,7 +4,9 @@ from typing import List
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
def body_dict_from_flags(body: List[str]) -> dict:
|
|
7
|
-
nested_dict
|
|
7
|
+
def nested_dict():
|
|
8
|
+
return defaultdict(nested_dict)
|
|
9
|
+
|
|
8
10
|
body_dict = nested_dict()
|
|
9
11
|
|
|
10
12
|
for part in body:
|
|
@@ -14,6 +16,7 @@ def body_dict_from_flags(body: List[str]) -> dict:
|
|
|
14
16
|
|
|
15
17
|
return dict(body_dict)
|
|
16
18
|
|
|
19
|
+
|
|
17
20
|
def parse_params(params: List[str]) -> dict:
|
|
18
21
|
params_dict = {}
|
|
19
22
|
for part in params:
|
opensearchcli-0.1.0/PKG-INFO
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import tomllib
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
class ConfigProfile:
|
|
6
|
-
def __init__(self, profile_name: str, data: dict) -> None:
|
|
7
|
-
self.profile_name = profile_name
|
|
8
|
-
self._data = data
|
|
9
|
-
|
|
10
|
-
@property
|
|
11
|
-
def domain(self) -> str:
|
|
12
|
-
return self._data.get("domain", "")
|
|
13
|
-
|
|
14
|
-
@property
|
|
15
|
-
def username(self) -> str:
|
|
16
|
-
return self._data.get("username", "")
|
|
17
|
-
|
|
18
|
-
@property
|
|
19
|
-
def password(self) -> str:
|
|
20
|
-
return self._data.get("password", "")
|
|
21
|
-
|
|
22
|
-
def __str__(self) -> str:
|
|
23
|
-
return (
|
|
24
|
-
f"Profile Name: {self.profile_name}\n"
|
|
25
|
-
f"\tDomain: {self.domain}\n"
|
|
26
|
-
f"\tUsername: {self.username}\n"
|
|
27
|
-
f"\tPassword: {'*' * len(self.password) if self.password else ''}"
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
class Config:
|
|
32
|
-
def __init__(self, file_loc: str, profiles: list[ConfigProfile]) -> None:
|
|
33
|
-
self.file = file_loc
|
|
34
|
-
self.profiles = profiles
|
|
35
|
-
|
|
36
|
-
def find_profile_by_name(self, profile_name: str) -> ConfigProfile:
|
|
37
|
-
for profile in self.profiles:
|
|
38
|
-
if profile.profile_name == profile_name:
|
|
39
|
-
return profile
|
|
40
|
-
return ConfigProfile(profile_name="", data={})
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
def read_config(config_file: str) -> Config:
|
|
44
|
-
if not os.path.isfile(path=config_file):
|
|
45
|
-
return Config(file_loc="", profiles=[ConfigProfile(profile_name="", data={})])
|
|
46
|
-
|
|
47
|
-
try:
|
|
48
|
-
with open(file=config_file, mode="rb") as _file:
|
|
49
|
-
data = tomllib.load(_file)
|
|
50
|
-
except ValueError as error:
|
|
51
|
-
data = {}
|
|
52
|
-
print(f"invalid toml: {error}")
|
|
53
|
-
return Config(
|
|
54
|
-
file_loc=config_file,
|
|
55
|
-
profiles=[
|
|
56
|
-
ConfigProfile(profile_name=profile_name, data=data[profile_name])
|
|
57
|
-
for profile_name in data.keys()
|
|
58
|
-
],
|
|
59
|
-
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|