proxy-platform 0.3.0__py3-none-any.whl
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.
Potentially problematic release.
This version of proxy-platform might be problematic. Click here for more details.
- proxy_platform/__init__.py +3 -0
- proxy_platform/client.py +324 -0
- proxy_platform/commands/__init__.py +1 -0
- proxy_platform/commands/auth.py +151 -0
- proxy_platform/commands/clusters.py +472 -0
- proxy_platform/commands/deployments.py +124 -0
- proxy_platform/commands/feedback.py +603 -0
- proxy_platform/commands/firewalls.py +894 -0
- proxy_platform/commands/orders.py +509 -0
- proxy_platform/commands/products.py +143 -0
- proxy_platform/commands/support.py +323 -0
- proxy_platform/commands/users.py +221 -0
- proxy_platform/config.py +224 -0
- proxy_platform/main.py +155 -0
- proxy_platform/main_public.py +135 -0
- proxy_platform-0.3.0.dist-info/METADATA +400 -0
- proxy_platform-0.3.0.dist-info/RECORD +20 -0
- proxy_platform-0.3.0.dist-info/WHEEL +5 -0
- proxy_platform-0.3.0.dist-info/entry_points.txt +2 -0
- proxy_platform-0.3.0.dist-info/top_level.txt +1 -0
proxy_platform/config.py
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"""Configuration and token management for PBD CLI."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
CONFIG_DIR = Path.home() / ".pbd-cli"
|
|
10
|
+
TOKEN_FILE = CONFIG_DIR / "tokens.json"
|
|
11
|
+
CONFIG_FILE = CONFIG_DIR / "config.json"
|
|
12
|
+
|
|
13
|
+
ENVIRONMENTS = {
|
|
14
|
+
"development": {
|
|
15
|
+
"admin_api": "http://localhost:8001",
|
|
16
|
+
"user_api": "http://localhost:8002",
|
|
17
|
+
},
|
|
18
|
+
"test": {
|
|
19
|
+
"admin_api": "https://admin-api.tst.pbd.proxy.nl",
|
|
20
|
+
"user_api": "https://api.tst.pbd.proxy.nl",
|
|
21
|
+
},
|
|
22
|
+
"acceptance": {
|
|
23
|
+
"admin_api": "https://admin-api.acc.pbd.proxy.nl",
|
|
24
|
+
"user_api": "https://api.acc.pbd.proxy.nl",
|
|
25
|
+
},
|
|
26
|
+
"production": {
|
|
27
|
+
"admin_api": "https://admin-api.prd.pbd.proxy.nl",
|
|
28
|
+
"user_api": "https://api.platform.proxy.nl",
|
|
29
|
+
},
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def ensure_config_dir() -> None:
|
|
34
|
+
"""Ensure the config directory exists."""
|
|
35
|
+
CONFIG_DIR.mkdir(parents=True, exist_ok=True)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def get_current_environment() -> str:
|
|
39
|
+
"""Get the currently selected environment."""
|
|
40
|
+
ensure_config_dir()
|
|
41
|
+
if not CONFIG_FILE.exists():
|
|
42
|
+
return "development"
|
|
43
|
+
|
|
44
|
+
try:
|
|
45
|
+
with open(CONFIG_FILE) as f:
|
|
46
|
+
config: dict[str, Any] = json.load(f)
|
|
47
|
+
result: str = config.get("environment", "development")
|
|
48
|
+
return result
|
|
49
|
+
except (OSError, json.JSONDecodeError):
|
|
50
|
+
return "development"
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def set_environment(env: str) -> None:
|
|
54
|
+
"""Set the current environment."""
|
|
55
|
+
ensure_config_dir()
|
|
56
|
+
config: dict[str, Any] = {}
|
|
57
|
+
if CONFIG_FILE.exists():
|
|
58
|
+
try:
|
|
59
|
+
with open(CONFIG_FILE) as f:
|
|
60
|
+
config = json.load(f)
|
|
61
|
+
except (OSError, json.JSONDecodeError):
|
|
62
|
+
pass
|
|
63
|
+
|
|
64
|
+
config["environment"] = env
|
|
65
|
+
with open(CONFIG_FILE, "w") as f:
|
|
66
|
+
json.dump(config, f, indent=2)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def get_api_urls() -> dict:
|
|
70
|
+
"""Get API URLs for the current environment.
|
|
71
|
+
|
|
72
|
+
Checks environment variables first (ADMIN_API_URL, USER_API_URL),
|
|
73
|
+
then falls back to configured environment URLs.
|
|
74
|
+
"""
|
|
75
|
+
# Check for environment variable overrides (for container environments)
|
|
76
|
+
admin_api_override = os.environ.get("ADMIN_API_URL")
|
|
77
|
+
user_api_override = os.environ.get("USER_API_URL")
|
|
78
|
+
|
|
79
|
+
if admin_api_override or user_api_override:
|
|
80
|
+
# If either override is set, use them (fall back to configured URLs if only one is set)
|
|
81
|
+
env = get_current_environment()
|
|
82
|
+
default_urls = ENVIRONMENTS.get(env, ENVIRONMENTS["development"])
|
|
83
|
+
return {
|
|
84
|
+
"admin_api": admin_api_override or default_urls["admin_api"],
|
|
85
|
+
"user_api": user_api_override or default_urls["user_api"],
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
# No overrides, use configured environment
|
|
89
|
+
env = get_current_environment()
|
|
90
|
+
return ENVIRONMENTS.get(env, ENVIRONMENTS["development"])
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def save_tokens(
|
|
94
|
+
admin_token: str | None = None,
|
|
95
|
+
user_token: str | None = None,
|
|
96
|
+
admin_refresh: str | None = None,
|
|
97
|
+
user_refresh: str | None = None,
|
|
98
|
+
) -> None:
|
|
99
|
+
"""Save authentication tokens and refresh tokens."""
|
|
100
|
+
ensure_config_dir()
|
|
101
|
+
|
|
102
|
+
tokens: dict[str, Any] = {}
|
|
103
|
+
if TOKEN_FILE.exists():
|
|
104
|
+
try:
|
|
105
|
+
with open(TOKEN_FILE) as f:
|
|
106
|
+
tokens = json.load(f)
|
|
107
|
+
except (OSError, json.JSONDecodeError):
|
|
108
|
+
pass
|
|
109
|
+
|
|
110
|
+
env = get_current_environment()
|
|
111
|
+
if env not in tokens:
|
|
112
|
+
tokens[env] = {}
|
|
113
|
+
|
|
114
|
+
if admin_token:
|
|
115
|
+
tokens[env]["admin_token"] = admin_token
|
|
116
|
+
tokens[env]["admin_token_saved_at"] = datetime.now().isoformat()
|
|
117
|
+
if admin_refresh:
|
|
118
|
+
tokens[env]["admin_refresh_token"] = admin_refresh
|
|
119
|
+
|
|
120
|
+
if user_token:
|
|
121
|
+
tokens[env]["user_token"] = user_token
|
|
122
|
+
tokens[env]["user_token_saved_at"] = datetime.now().isoformat()
|
|
123
|
+
if user_refresh:
|
|
124
|
+
tokens[env]["user_refresh_token"] = user_refresh
|
|
125
|
+
|
|
126
|
+
with open(TOKEN_FILE, "w") as f:
|
|
127
|
+
json.dump(tokens, f, indent=2)
|
|
128
|
+
|
|
129
|
+
# Set restrictive permissions
|
|
130
|
+
os.chmod(TOKEN_FILE, 0o600)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def get_token(api_type: str = "user") -> str | None:
|
|
134
|
+
"""Get the stored authentication token for the current environment."""
|
|
135
|
+
ensure_config_dir()
|
|
136
|
+
|
|
137
|
+
if not TOKEN_FILE.exists():
|
|
138
|
+
return None
|
|
139
|
+
|
|
140
|
+
try:
|
|
141
|
+
with open(TOKEN_FILE) as f:
|
|
142
|
+
tokens = json.load(f)
|
|
143
|
+
|
|
144
|
+
env = get_current_environment()
|
|
145
|
+
env_tokens: dict[str, Any] = tokens.get(env, {})
|
|
146
|
+
|
|
147
|
+
token_key = f"{api_type}_token"
|
|
148
|
+
result: str | None = env_tokens.get(token_key)
|
|
149
|
+
return result
|
|
150
|
+
except (OSError, json.JSONDecodeError):
|
|
151
|
+
return None
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def get_refresh_token(api_type: str = "user") -> str | None:
|
|
155
|
+
"""Get the stored refresh token for the current environment."""
|
|
156
|
+
ensure_config_dir()
|
|
157
|
+
|
|
158
|
+
if not TOKEN_FILE.exists():
|
|
159
|
+
return None
|
|
160
|
+
|
|
161
|
+
try:
|
|
162
|
+
with open(TOKEN_FILE) as f:
|
|
163
|
+
tokens = json.load(f)
|
|
164
|
+
|
|
165
|
+
env = get_current_environment()
|
|
166
|
+
env_tokens: dict[str, Any] = tokens.get(env, {})
|
|
167
|
+
|
|
168
|
+
token_key = f"{api_type}_refresh_token"
|
|
169
|
+
result: str | None = env_tokens.get(token_key)
|
|
170
|
+
return result
|
|
171
|
+
except (OSError, json.JSONDecodeError):
|
|
172
|
+
return None
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def clear_tokens() -> None:
|
|
176
|
+
"""Clear all stored tokens for the current environment."""
|
|
177
|
+
ensure_config_dir()
|
|
178
|
+
|
|
179
|
+
if not TOKEN_FILE.exists():
|
|
180
|
+
return
|
|
181
|
+
|
|
182
|
+
try:
|
|
183
|
+
with open(TOKEN_FILE) as f:
|
|
184
|
+
tokens: dict[str, Any] = json.load(f)
|
|
185
|
+
|
|
186
|
+
env = get_current_environment()
|
|
187
|
+
if env in tokens:
|
|
188
|
+
del tokens[env]
|
|
189
|
+
|
|
190
|
+
with open(TOKEN_FILE, "w") as f:
|
|
191
|
+
json.dump(tokens, f, indent=2)
|
|
192
|
+
except (OSError, json.JSONDecodeError):
|
|
193
|
+
pass
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def get_default_api_type() -> str:
|
|
197
|
+
"""Get the default API type (admin or user)."""
|
|
198
|
+
ensure_config_dir()
|
|
199
|
+
if not CONFIG_FILE.exists():
|
|
200
|
+
return "user"
|
|
201
|
+
|
|
202
|
+
try:
|
|
203
|
+
with open(CONFIG_FILE) as f:
|
|
204
|
+
config: dict[str, Any] = json.load(f)
|
|
205
|
+
result: str = config.get("default_api", "user")
|
|
206
|
+
return result
|
|
207
|
+
except (OSError, json.JSONDecodeError):
|
|
208
|
+
return "user"
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def set_default_api_type(api_type: str) -> None:
|
|
212
|
+
"""Set the default API type."""
|
|
213
|
+
ensure_config_dir()
|
|
214
|
+
config: dict[str, Any] = {}
|
|
215
|
+
if CONFIG_FILE.exists():
|
|
216
|
+
try:
|
|
217
|
+
with open(CONFIG_FILE) as f:
|
|
218
|
+
config = json.load(f)
|
|
219
|
+
except (OSError, json.JSONDecodeError):
|
|
220
|
+
pass
|
|
221
|
+
|
|
222
|
+
config["default_api"] = api_type
|
|
223
|
+
with open(CONFIG_FILE, "w") as f:
|
|
224
|
+
json.dump(config, f, indent=2)
|
proxy_platform/main.py
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"""Main CLI application entry point."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
|
|
5
|
+
import typer
|
|
6
|
+
from rich.console import Console
|
|
7
|
+
from rich.logging import RichHandler
|
|
8
|
+
|
|
9
|
+
from . import __version__
|
|
10
|
+
from .commands import auth, clusters, feedback, firewalls, orders, products, support, users
|
|
11
|
+
from .commands.admin import app as admin_app
|
|
12
|
+
from .config import ENVIRONMENTS, get_current_environment, set_environment
|
|
13
|
+
|
|
14
|
+
app = typer.Typer(
|
|
15
|
+
name="pbd",
|
|
16
|
+
help="PBD API CLI - Command line client for PBD Admin and User APIs",
|
|
17
|
+
add_completion=True,
|
|
18
|
+
)
|
|
19
|
+
console = Console()
|
|
20
|
+
|
|
21
|
+
# Global state for verbose logging
|
|
22
|
+
_verbose_enabled = False
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def setup_logging(verbose: bool = False) -> None:
|
|
26
|
+
"""Configure logging for the CLI.
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
verbose: If True, enable DEBUG level logging with detailed output
|
|
30
|
+
"""
|
|
31
|
+
global _verbose_enabled
|
|
32
|
+
_verbose_enabled = verbose
|
|
33
|
+
|
|
34
|
+
level = logging.DEBUG if verbose else logging.WARNING
|
|
35
|
+
|
|
36
|
+
# Configure root logger with Rich handler for beautiful output
|
|
37
|
+
logging.basicConfig(
|
|
38
|
+
level=level,
|
|
39
|
+
format="%(message)s",
|
|
40
|
+
datefmt="[%X]",
|
|
41
|
+
handlers=[RichHandler(console=console, rich_tracebacks=True, show_path=verbose)],
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
# Set specific loggers
|
|
45
|
+
logger = logging.getLogger("proxy_platform")
|
|
46
|
+
logger.setLevel(level)
|
|
47
|
+
|
|
48
|
+
if verbose:
|
|
49
|
+
logger.debug("Verbose logging enabled")
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@app.callback()
|
|
53
|
+
def main_callback(
|
|
54
|
+
verbose: bool = typer.Option(
|
|
55
|
+
False,
|
|
56
|
+
"--verbose",
|
|
57
|
+
"-v",
|
|
58
|
+
help="Enable verbose output with debug logging",
|
|
59
|
+
),
|
|
60
|
+
) -> None:
|
|
61
|
+
"""PBD CLI - Command line client for PBD Admin and User APIs.
|
|
62
|
+
|
|
63
|
+
Use --verbose to see detailed debug output including API calls and responses.
|
|
64
|
+
"""
|
|
65
|
+
setup_logging(verbose)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
# Register command groups
|
|
69
|
+
app.add_typer(auth.app, name="auth", help="Authentication commands")
|
|
70
|
+
app.add_typer(feedback.app, name="feedback", help="Feedback portal commands")
|
|
71
|
+
app.add_typer(support.app, name="support", help="Support ticket commands")
|
|
72
|
+
app.add_typer(products.app, name="products", help="Product catalog commands")
|
|
73
|
+
app.add_typer(orders.app, name="orders", help="Order and payment management commands")
|
|
74
|
+
app.add_typer(clusters.app, name="clusters", help="Cluster management commands")
|
|
75
|
+
app.add_typer(firewalls.app, name="firewall", help="Firewall management commands")
|
|
76
|
+
app.add_typer(users.app, name="users", help="User management commands")
|
|
77
|
+
app.add_typer(admin_app, name="admin", help="Admin commands (for Proxy employees)")
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
@app.command()
|
|
81
|
+
def version() -> None:
|
|
82
|
+
"""Show CLI version."""
|
|
83
|
+
console.print(f"PBD CLI version: [bold cyan]{__version__}[/bold cyan]")
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@app.command()
|
|
87
|
+
def env(
|
|
88
|
+
environment: str | None = typer.Argument(
|
|
89
|
+
None,
|
|
90
|
+
help="Environment to switch to (development, test, acceptance, production)",
|
|
91
|
+
),
|
|
92
|
+
show: bool = typer.Option(
|
|
93
|
+
False,
|
|
94
|
+
"--show",
|
|
95
|
+
"-s",
|
|
96
|
+
help="Show current environment",
|
|
97
|
+
),
|
|
98
|
+
) -> None:
|
|
99
|
+
"""Manage environment settings.
|
|
100
|
+
|
|
101
|
+
Switch between development, test, acceptance, and production environments.
|
|
102
|
+
"""
|
|
103
|
+
if show or environment is None:
|
|
104
|
+
current = get_current_environment()
|
|
105
|
+
console.print(f"Current environment: [bold cyan]{current}[/bold cyan]")
|
|
106
|
+
console.print("\nAvailable environments:")
|
|
107
|
+
for env_name, urls in ENVIRONMENTS.items():
|
|
108
|
+
marker = "→" if env_name == current else " "
|
|
109
|
+
console.print(f"{marker} [yellow]{env_name}[/yellow]")
|
|
110
|
+
console.print(f" Admin API: {urls['admin_api']}")
|
|
111
|
+
console.print(f" User API: {urls['user_api']}")
|
|
112
|
+
return
|
|
113
|
+
|
|
114
|
+
if environment not in ENVIRONMENTS:
|
|
115
|
+
console.print(f"[red]Error: Invalid environment '{environment}'[/red]")
|
|
116
|
+
console.print(f"Available: {', '.join(ENVIRONMENTS.keys())}")
|
|
117
|
+
raise typer.Exit(1)
|
|
118
|
+
|
|
119
|
+
set_environment(environment)
|
|
120
|
+
console.print(f"[green]✓[/green] Switched to [bold cyan]{environment}[/bold cyan] environment")
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
# Convenience aliases for common commands
|
|
124
|
+
@app.command(name="login")
|
|
125
|
+
def login_alias(
|
|
126
|
+
email: str | None = typer.Option(None, "--email", "-e", help="Email address"),
|
|
127
|
+
password: str | None = typer.Option(None, "--password", "-p", help="Password"),
|
|
128
|
+
api: str = typer.Option("user", "--api", "-a", help="API type (admin or user)"),
|
|
129
|
+
) -> None:
|
|
130
|
+
"""Login to the API (alias for 'auth login')."""
|
|
131
|
+
from .commands.auth import login as auth_login
|
|
132
|
+
|
|
133
|
+
auth_login(email=email, password=password, api=api)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
@app.command(name="logout")
|
|
137
|
+
def logout_alias() -> None:
|
|
138
|
+
"""Logout from the API (alias for 'auth logout')."""
|
|
139
|
+
from .commands.auth import logout as auth_logout
|
|
140
|
+
|
|
141
|
+
auth_logout()
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
@app.command(name="whoami")
|
|
145
|
+
def whoami_alias(
|
|
146
|
+
api: str | None = typer.Option(None, "--api", "-a", help="API type (admin or user)"),
|
|
147
|
+
) -> None:
|
|
148
|
+
"""Show current user info (alias for 'auth whoami')."""
|
|
149
|
+
from .commands.auth import whoami as auth_whoami
|
|
150
|
+
|
|
151
|
+
auth_whoami(api=api)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
if __name__ == "__main__":
|
|
155
|
+
app()
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"""Public CLI application entry point (no admin commands)."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
|
|
5
|
+
import typer
|
|
6
|
+
from rich.console import Console
|
|
7
|
+
from rich.logging import RichHandler
|
|
8
|
+
|
|
9
|
+
from . import __version__
|
|
10
|
+
from .commands import auth, clusters, feedback, firewalls, orders, products, support, users
|
|
11
|
+
from .config import ENVIRONMENTS, get_current_environment, set_environment
|
|
12
|
+
|
|
13
|
+
app = typer.Typer(
|
|
14
|
+
name="pbd",
|
|
15
|
+
help="PBD CLI - Command line client for the PBD platform",
|
|
16
|
+
add_completion=True,
|
|
17
|
+
)
|
|
18
|
+
console = Console()
|
|
19
|
+
|
|
20
|
+
_verbose_enabled = False
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def setup_logging(verbose: bool = False) -> None:
|
|
24
|
+
global _verbose_enabled
|
|
25
|
+
_verbose_enabled = verbose
|
|
26
|
+
level = logging.DEBUG if verbose else logging.WARNING
|
|
27
|
+
logging.basicConfig(
|
|
28
|
+
level=level,
|
|
29
|
+
format="%(message)s",
|
|
30
|
+
datefmt="[%X]",
|
|
31
|
+
handlers=[RichHandler(console=console, rich_tracebacks=True, show_path=verbose)],
|
|
32
|
+
)
|
|
33
|
+
logger = logging.getLogger("proxy_platform")
|
|
34
|
+
logger.setLevel(level)
|
|
35
|
+
if verbose:
|
|
36
|
+
logger.debug("Verbose logging enabled")
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@app.callback()
|
|
40
|
+
def main_callback(
|
|
41
|
+
verbose: bool = typer.Option(
|
|
42
|
+
False,
|
|
43
|
+
"--verbose",
|
|
44
|
+
"-v",
|
|
45
|
+
help="Enable verbose output with debug logging",
|
|
46
|
+
),
|
|
47
|
+
) -> None:
|
|
48
|
+
"""PBD CLI - Command line client for the PBD platform.
|
|
49
|
+
|
|
50
|
+
Use --verbose to see detailed debug output including API calls and responses.
|
|
51
|
+
"""
|
|
52
|
+
setup_logging(verbose)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
app.add_typer(auth.app, name="auth", help="Authentication commands")
|
|
56
|
+
app.add_typer(feedback.app, name="feedback", help="Feedback portal commands")
|
|
57
|
+
app.add_typer(support.app, name="support", help="Support ticket commands")
|
|
58
|
+
app.add_typer(products.app, name="products", help="Product catalog commands")
|
|
59
|
+
app.add_typer(orders.app, name="orders", help="Order and payment management commands")
|
|
60
|
+
app.add_typer(clusters.app, name="clusters", help="Cluster management commands")
|
|
61
|
+
app.add_typer(firewalls.app, name="firewall", help="Firewall management commands")
|
|
62
|
+
app.add_typer(users.app, name="users", help="User management commands")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@app.command()
|
|
66
|
+
def version() -> None:
|
|
67
|
+
"""Show CLI version."""
|
|
68
|
+
console.print(f"PBD CLI version: [bold cyan]{__version__}[/bold cyan]")
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@app.command()
|
|
72
|
+
def env(
|
|
73
|
+
environment: str | None = typer.Argument(
|
|
74
|
+
None,
|
|
75
|
+
help="Environment to switch to (development, test, acceptance, production)",
|
|
76
|
+
),
|
|
77
|
+
show: bool = typer.Option(
|
|
78
|
+
False,
|
|
79
|
+
"--show",
|
|
80
|
+
"-s",
|
|
81
|
+
help="Show current environment",
|
|
82
|
+
),
|
|
83
|
+
) -> None:
|
|
84
|
+
"""Manage environment settings."""
|
|
85
|
+
if show or environment is None:
|
|
86
|
+
current = get_current_environment()
|
|
87
|
+
console.print(f"Current environment: [bold cyan]{current}[/bold cyan]")
|
|
88
|
+
console.print("\nAvailable environments:")
|
|
89
|
+
for env_name, urls in ENVIRONMENTS.items():
|
|
90
|
+
marker = "→" if env_name == current else " "
|
|
91
|
+
console.print(f"{marker} [yellow]{env_name}[/yellow]")
|
|
92
|
+
console.print(f" User API: {urls['user_api']}")
|
|
93
|
+
return
|
|
94
|
+
|
|
95
|
+
if environment not in ENVIRONMENTS:
|
|
96
|
+
console.print(f"[red]Error: Invalid environment '{environment}'[/red]")
|
|
97
|
+
console.print(f"Available: {', '.join(ENVIRONMENTS.keys())}")
|
|
98
|
+
raise typer.Exit(1)
|
|
99
|
+
|
|
100
|
+
set_environment(environment)
|
|
101
|
+
console.print(f"[green]✓[/green] Switched to [bold cyan]{environment}[/bold cyan] environment")
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
@app.command(name="login")
|
|
105
|
+
def login_alias(
|
|
106
|
+
email: str | None = typer.Option(None, "--email", "-e", help="Email address"),
|
|
107
|
+
password: str | None = typer.Option(None, "--password", "-p", help="Password"),
|
|
108
|
+
api: str = typer.Option("user", "--api", "-a", help="API type"),
|
|
109
|
+
) -> None:
|
|
110
|
+
"""Login to the API (alias for 'auth login')."""
|
|
111
|
+
from .commands.auth import login as auth_login
|
|
112
|
+
|
|
113
|
+
auth_login(email=email, password=password, api=api)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
@app.command(name="logout")
|
|
117
|
+
def logout_alias() -> None:
|
|
118
|
+
"""Logout from the API (alias for 'auth logout')."""
|
|
119
|
+
from .commands.auth import logout as auth_logout
|
|
120
|
+
|
|
121
|
+
auth_logout()
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
@app.command(name="whoami")
|
|
125
|
+
def whoami_alias(
|
|
126
|
+
api: str | None = typer.Option(None, "--api", "-a", help="API type"),
|
|
127
|
+
) -> None:
|
|
128
|
+
"""Show current user info (alias for 'auth whoami')."""
|
|
129
|
+
from .commands.auth import whoami as auth_whoami
|
|
130
|
+
|
|
131
|
+
auth_whoami(api=api)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
if __name__ == "__main__":
|
|
135
|
+
app()
|