xenfra 0.4.3__py3-none-any.whl → 0.4.5__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.
@@ -1,233 +1,233 @@
1
- """
2
- Security configuration commands for Xenfra CLI.
3
- """
4
-
5
- import os
6
-
7
- import click
8
- from rich.console import Console
9
- from rich.panel import Panel
10
- from rich.table import Table
11
-
12
- from ..utils.security import ALLOWED_DOMAINS, security_config, validate_and_get_api_url
13
-
14
- console = Console()
15
-
16
-
17
- @click.group(hidden=True)
18
- def security():
19
- """Security and configuration management (for debugging/advanced users)."""
20
- pass
21
-
22
-
23
- @security.command()
24
- def check():
25
- """Display current security configuration."""
26
- # Get current API URL
27
- try:
28
- api_url = validate_and_get_api_url()
29
- except click.Abort:
30
- api_url = os.getenv("XENFRA_API_URL", "Not set")
31
-
32
- # Display configuration
33
- console.print("\n[bold cyan]🔒 Xenfra CLI Security Configuration[/bold cyan]\n")
34
-
35
- # API URL
36
- console.print(f"[bold]API URL:[/bold] {api_url}")
37
-
38
- # Environment
39
- env_color = "green" if security_config.is_production() else "yellow"
40
- console.print(
41
- f"[bold]Environment:[/bold] [{env_color}]{security_config.environment}[/{env_color}]"
42
- )
43
-
44
- console.print()
45
-
46
- # Security features table
47
- table = Table(title="Security Features", show_header=True)
48
- table.add_column("Feature", style="cyan")
49
- table.add_column("Status", style="white")
50
- table.add_column("Description", style="dim")
51
-
52
- features = [
53
- (
54
- "HTTPS Enforcement",
55
- "✅ Enabled" if security_config.enforce_https else "⚠️ Disabled",
56
- "Blocks HTTP connections (except localhost)",
57
- ),
58
- (
59
- "Domain Whitelist",
60
- "✅ Enforced" if security_config.enforce_whitelist else "⚠️ Warning Only",
61
- "Restricts connections to approved domains",
62
- ),
63
- (
64
- "HTTP Warning",
65
- "✅ Enabled" if security_config.warn_on_http else "❌ Disabled",
66
- "Warns when using insecure HTTP",
67
- ),
68
- (
69
- "Certificate Pinning",
70
- "✅ Enabled" if security_config.enable_cert_pinning else "❌ Disabled",
71
- "Validates SSL certificate fingerprints",
72
- ),
73
- ]
74
-
75
- for feature, status, description in features:
76
- table.add_row(feature, status, description)
77
-
78
- console.print(table)
79
- console.print()
80
-
81
- # Whitelisted domains
82
- console.print("[bold]Whitelisted Domains:[/bold]")
83
- for domain in ALLOWED_DOMAINS:
84
- console.print(f" • {domain}")
85
-
86
- console.print()
87
-
88
- # Environment variables
89
- console.print("[bold]Configuration via Environment Variables:[/bold]")
90
- env_vars = [
91
- ("XENFRA_ENV", os.getenv("XENFRA_ENV", "development")),
92
- ("XENFRA_API_URL", os.getenv("XENFRA_API_URL", "http://localhost:8000")),
93
- ("XENFRA_ENFORCE_HTTPS", os.getenv("XENFRA_ENFORCE_HTTPS", "auto")),
94
- ("XENFRA_ENFORCE_WHITELIST", os.getenv("XENFRA_ENFORCE_WHITELIST", "auto")),
95
- ("XENFRA_ENABLE_CERT_PINNING", os.getenv("XENFRA_ENABLE_CERT_PINNING", "auto")),
96
- ("XENFRA_WARN_ON_HTTP", os.getenv("XENFRA_WARN_ON_HTTP", "true")),
97
- ]
98
-
99
- for var, value in env_vars:
100
- console.print(f" {var}=[cyan]{value}[/cyan]")
101
-
102
- console.print()
103
-
104
- # Security recommendations
105
- if not security_config.is_production():
106
- console.print(
107
- Panel(
108
- "[yellow]⚠️ Development Mode Active[/yellow]\n\n"
109
- "For production use:\n"
110
- "1. Set XENFRA_ENV=production\n"
111
- "2. Use HTTPS API URL\n"
112
- "3. All security features will auto-enable",
113
- title="Recommendation",
114
- border_style="yellow",
115
- )
116
- )
117
- else:
118
- console.print(
119
- Panel(
120
- "[green]✅ Production Security Enabled[/green]\n\n"
121
- "All security features are active.\n"
122
- "Your credentials and data are protected.",
123
- title="Status",
124
- border_style="green",
125
- )
126
- )
127
-
128
-
129
- @security.command()
130
- @click.argument("url")
131
- def validate(url):
132
- """Validate an API URL against security policies."""
133
- console.print(f"\n[cyan]Validating URL:[/cyan] {url}\n")
134
-
135
- try:
136
- validated_url = validate_and_get_api_url(url)
137
- console.print("[bold green]✅ URL is valid and passed all security checks![/bold green]")
138
- console.print(f"[dim]Validated URL: {validated_url}[/dim]")
139
- except click.Abort:
140
- console.print("[bold red]❌ URL failed security validation[/bold red]")
141
- except Exception as e:
142
- console.print(f"[bold red]❌ Validation error: {e}[/bold red]")
143
-
144
-
145
- @security.command()
146
- def docs():
147
- """Show security documentation."""
148
- docs_text = """
149
- [bold cyan]Xenfra CLI Security Guide[/bold cyan]
150
-
151
- [bold]Environment Detection:[/bold]
152
- The CLI automatically adjusts security based on the environment:
153
-
154
- • [green]production[/green]: All security features enforced
155
- • [yellow]staging[/yellow]: HTTPS required, whitelist warnings
156
- • [blue]development[/blue]: Permissive (localhost allowed)
157
-
158
- [bold]Security Features:[/bold]
159
-
160
- 1. [cyan]URL Validation[/cyan]
161
- - Prevents malicious URL patterns
162
- - Blocks URLs with embedded credentials
163
- - Validates scheme (http/https only)
164
-
165
- 2. [cyan]Domain Whitelist[/cyan]
166
- - Restricts connections to approved domains
167
- - Prevents credential theft via fake APIs
168
- - Can be disabled for self-hosted instances
169
-
170
- 3. [cyan]HTTPS Enforcement[/cyan]
171
- - Requires encrypted connections in production
172
- - Warns on insecure HTTP (non-localhost)
173
- - Protects credentials and data in transit
174
-
175
- 4. [cyan]Certificate Pinning[/cyan]
176
- - Validates SSL certificate fingerprints
177
- - Prevents man-in-the-middle attacks
178
- - Optional (enabled in production by default)
179
-
180
- [bold]Configuration Examples:[/bold]
181
-
182
- [yellow]Development (default):[/yellow]
183
- $ xenfra login
184
- # Uses http://localhost:8000
185
-
186
- [yellow]Self-hosted instance:[/yellow]
187
- $ export XENFRA_API_URL=https://xenfra.mycompany.com
188
- $ export XENFRA_ENFORCE_WHITELIST=false
189
- $ xenfra login
190
-
191
- [yellow]Production (strict):[/yellow]
192
- $ export XENFRA_ENV=production
193
- $ xenfra login
194
- # All security features enabled
195
-
196
- [bold]Environment Variables:[/bold]
197
-
198
- XENFRA_ENV
199
- Values: production | staging | development
200
- Default: development
201
-
202
- XENFRA_API_URL
203
- Default: http://localhost:8000 (dev), https://api.xenfra.tech (prod)
204
-
205
- XENFRA_ENFORCE_HTTPS
206
- Values: true | false
207
- Default: false (dev), true (prod)
208
-
209
- XENFRA_ENFORCE_WHITELIST
210
- Values: true | false
211
- Default: false (dev), true (prod)
212
-
213
- XENFRA_ENABLE_CERT_PINNING
214
- Values: true | false
215
- Default: false (dev), true (prod)
216
-
217
- XENFRA_WARN_ON_HTTP
218
- Values: true | false
219
- Default: true
220
-
221
- [bold]Security Best Practices:[/bold]
222
-
223
- 1. Always use HTTPS in production
224
- 2. Never disable security features without understanding risks
225
- 3. Keep whitelisted domains list updated
226
- 4. Rotate credentials if you suspect compromise
227
- 5. Use environment-specific configurations
228
- 6. Enable all features for production deployments
229
-
230
- [dim]For more information: https://docs.xenfra.tech/security[/dim]
231
- """
232
-
233
- console.print(Panel(docs_text, border_style="cyan", padding=(1, 2)))
1
+ """
2
+ Security configuration commands for Xenfra CLI.
3
+ """
4
+
5
+ import os
6
+
7
+ import click
8
+ from rich.console import Console
9
+ from rich.panel import Panel
10
+ from rich.table import Table
11
+
12
+ from ..utils.security import ALLOWED_DOMAINS, security_config, validate_and_get_api_url
13
+
14
+ console = Console()
15
+
16
+
17
+ @click.group(hidden=True)
18
+ def security():
19
+ """Security and configuration management (for debugging/advanced users)."""
20
+ pass
21
+
22
+
23
+ @security.command()
24
+ def check():
25
+ """Display current security configuration."""
26
+ # Get current API URL
27
+ try:
28
+ api_url = validate_and_get_api_url()
29
+ except click.Abort:
30
+ api_url = os.getenv("XENFRA_API_URL", "Not set")
31
+
32
+ # Display configuration
33
+ console.print("\n[bold cyan]🔒 Xenfra CLI Security Configuration[/bold cyan]\n")
34
+
35
+ # API URL
36
+ console.print(f"[bold]API URL:[/bold] {api_url}")
37
+
38
+ # Environment
39
+ env_color = "green" if security_config.is_production() else "yellow"
40
+ console.print(
41
+ f"[bold]Environment:[/bold] [{env_color}]{security_config.environment}[/{env_color}]"
42
+ )
43
+
44
+ console.print()
45
+
46
+ # Security features table
47
+ table = Table(title="Security Features", show_header=True)
48
+ table.add_column("Feature", style="cyan")
49
+ table.add_column("Status", style="white")
50
+ table.add_column("Description", style="dim")
51
+
52
+ features = [
53
+ (
54
+ "HTTPS Enforcement",
55
+ "✅ Enabled" if security_config.enforce_https else "⚠️ Disabled",
56
+ "Blocks HTTP connections (except localhost)",
57
+ ),
58
+ (
59
+ "Domain Whitelist",
60
+ "✅ Enforced" if security_config.enforce_whitelist else "⚠️ Warning Only",
61
+ "Restricts connections to approved domains",
62
+ ),
63
+ (
64
+ "HTTP Warning",
65
+ "✅ Enabled" if security_config.warn_on_http else "❌ Disabled",
66
+ "Warns when using insecure HTTP",
67
+ ),
68
+ (
69
+ "Certificate Pinning",
70
+ "✅ Enabled" if security_config.enable_cert_pinning else "❌ Disabled",
71
+ "Validates SSL certificate fingerprints",
72
+ ),
73
+ ]
74
+
75
+ for feature, status, description in features:
76
+ table.add_row(feature, status, description)
77
+
78
+ console.print(table)
79
+ console.print()
80
+
81
+ # Whitelisted domains
82
+ console.print("[bold]Whitelisted Domains:[/bold]")
83
+ for domain in ALLOWED_DOMAINS:
84
+ console.print(f" • {domain}")
85
+
86
+ console.print()
87
+
88
+ # Environment variables
89
+ console.print("[bold]Configuration via Environment Variables:[/bold]")
90
+ env_vars = [
91
+ ("XENFRA_ENV", os.getenv("XENFRA_ENV", "development")),
92
+ ("XENFRA_API_URL", os.getenv("XENFRA_API_URL", "http://localhost:8000")),
93
+ ("XENFRA_ENFORCE_HTTPS", os.getenv("XENFRA_ENFORCE_HTTPS", "auto")),
94
+ ("XENFRA_ENFORCE_WHITELIST", os.getenv("XENFRA_ENFORCE_WHITELIST", "auto")),
95
+ ("XENFRA_ENABLE_CERT_PINNING", os.getenv("XENFRA_ENABLE_CERT_PINNING", "auto")),
96
+ ("XENFRA_WARN_ON_HTTP", os.getenv("XENFRA_WARN_ON_HTTP", "true")),
97
+ ]
98
+
99
+ for var, value in env_vars:
100
+ console.print(f" {var}=[cyan]{value}[/cyan]")
101
+
102
+ console.print()
103
+
104
+ # Security recommendations
105
+ if not security_config.is_production():
106
+ console.print(
107
+ Panel(
108
+ "[yellow]⚠️ Development Mode Active[/yellow]\n\n"
109
+ "For production use:\n"
110
+ "1. Set XENFRA_ENV=production\n"
111
+ "2. Use HTTPS API URL\n"
112
+ "3. All security features will auto-enable",
113
+ title="Recommendation",
114
+ border_style="yellow",
115
+ )
116
+ )
117
+ else:
118
+ console.print(
119
+ Panel(
120
+ "[green]✅ Production Security Enabled[/green]\n\n"
121
+ "All security features are active.\n"
122
+ "Your credentials and data are protected.",
123
+ title="Status",
124
+ border_style="green",
125
+ )
126
+ )
127
+
128
+
129
+ @security.command()
130
+ @click.argument("url")
131
+ def validate(url):
132
+ """Validate an API URL against security policies."""
133
+ console.print(f"\n[cyan]Validating URL:[/cyan] {url}\n")
134
+
135
+ try:
136
+ validated_url = validate_and_get_api_url(url)
137
+ console.print("[bold green]✅ URL is valid and passed all security checks![/bold green]")
138
+ console.print(f"[dim]Validated URL: {validated_url}[/dim]")
139
+ except click.Abort:
140
+ console.print("[bold red]❌ URL failed security validation[/bold red]")
141
+ except Exception as e:
142
+ console.print(f"[bold red]❌ Validation error: {e}[/bold red]")
143
+
144
+
145
+ @security.command()
146
+ def docs():
147
+ """Show security documentation."""
148
+ docs_text = """
149
+ [bold cyan]Xenfra CLI Security Guide[/bold cyan]
150
+
151
+ [bold]Environment Detection:[/bold]
152
+ The CLI automatically adjusts security based on the environment:
153
+
154
+ • [green]production[/green]: All security features enforced
155
+ • [yellow]staging[/yellow]: HTTPS required, whitelist warnings
156
+ • [blue]development[/blue]: Permissive (localhost allowed)
157
+
158
+ [bold]Security Features:[/bold]
159
+
160
+ 1. [cyan]URL Validation[/cyan]
161
+ - Prevents malicious URL patterns
162
+ - Blocks URLs with embedded credentials
163
+ - Validates scheme (http/https only)
164
+
165
+ 2. [cyan]Domain Whitelist[/cyan]
166
+ - Restricts connections to approved domains
167
+ - Prevents credential theft via fake APIs
168
+ - Can be disabled for self-hosted instances
169
+
170
+ 3. [cyan]HTTPS Enforcement[/cyan]
171
+ - Requires encrypted connections in production
172
+ - Warns on insecure HTTP (non-localhost)
173
+ - Protects credentials and data in transit
174
+
175
+ 4. [cyan]Certificate Pinning[/cyan]
176
+ - Validates SSL certificate fingerprints
177
+ - Prevents man-in-the-middle attacks
178
+ - Optional (enabled in production by default)
179
+
180
+ [bold]Configuration Examples:[/bold]
181
+
182
+ [yellow]Development (default):[/yellow]
183
+ $ xenfra login
184
+ # Uses http://localhost:8000
185
+
186
+ [yellow]Self-hosted instance:[/yellow]
187
+ $ export XENFRA_API_URL=https://xenfra.mycompany.com
188
+ $ export XENFRA_ENFORCE_WHITELIST=false
189
+ $ xenfra login
190
+
191
+ [yellow]Production (strict):[/yellow]
192
+ $ export XENFRA_ENV=production
193
+ $ xenfra login
194
+ # All security features enabled
195
+
196
+ [bold]Environment Variables:[/bold]
197
+
198
+ XENFRA_ENV
199
+ Values: production | staging | development
200
+ Default: development
201
+
202
+ XENFRA_API_URL
203
+ Default: http://localhost:8000 (dev), https://api.xenfra.tech (prod)
204
+
205
+ XENFRA_ENFORCE_HTTPS
206
+ Values: true | false
207
+ Default: false (dev), true (prod)
208
+
209
+ XENFRA_ENFORCE_WHITELIST
210
+ Values: true | false
211
+ Default: false (dev), true (prod)
212
+
213
+ XENFRA_ENABLE_CERT_PINNING
214
+ Values: true | false
215
+ Default: false (dev), true (prod)
216
+
217
+ XENFRA_WARN_ON_HTTP
218
+ Values: true | false
219
+ Default: true
220
+
221
+ [bold]Security Best Practices:[/bold]
222
+
223
+ 1. Always use HTTPS in production
224
+ 2. Never disable security features without understanding risks
225
+ 3. Keep whitelisted domains list updated
226
+ 4. Rotate credentials if you suspect compromise
227
+ 5. Use environment-specific configurations
228
+ 6. Enable all features for production deployments
229
+
230
+ [dim]For more information: https://docs.xenfra.tech/security[/dim]
231
+ """
232
+
233
+ console.print(Panel(docs_text, border_style="cyan", padding=(1, 2)))
xenfra/main.py CHANGED
@@ -1,75 +1,79 @@
1
- """
2
- Xenfra CLI - Main entry point.
3
-
4
- A modern, AI-powered CLI for deploying Python apps to DigitalOcean.
5
- """
6
-
7
- import os
8
-
9
- import click
10
- from rich.console import Console
11
-
12
- from .commands.auth import auth
13
- from .commands.deployments import deploy, logs, report, status
14
- from .commands.intelligence import analyze, diagnose, init
15
- from .commands.projects import projects
16
- from .commands.security_cmd import security
17
-
18
- console = Console()
19
-
20
- # Production-ready: API URL is hardcoded as https://api.xenfra.tech
21
- # No configuration needed - works out of the box after pip install
22
-
23
-
24
- @click.group()
25
- @click.version_option(version="0.2.9")
26
- def cli():
27
- """
28
- Xenfra CLI: Deploy Python apps to DigitalOcean with zero configuration.
29
-
30
- Quick Start:
31
- xenfra auth login # Authenticate with Xenfra
32
- xenfra init # Initialize your project (AI-powered)
33
- xenfra deploy # Deploy to DigitalOcean
34
-
35
- Commands:
36
- auth Authentication (login, logout, whoami)
37
- projects Manage projects (list, show, delete)
38
- init Smart project initialization (AI-powered)
39
- diagnose Diagnose deployment failures (AI-powered)
40
- analyze Analyze codebase without creating config
41
-
42
- For help on a specific command:
43
- xenfra <command> --help
44
- """
45
- # Configure keyring backend
46
- os.environ["KEYRING_BACKEND"] = "keyrings.alt.file.PlaintextKeyring"
47
-
48
- # Security works silently in the background
49
- # Only shows warnings if there's an actual security issue
50
-
51
-
52
- # Register command groups
53
- cli.add_command(auth)
54
- cli.add_command(projects)
55
- cli.add_command(security)
56
-
57
- # Register intelligence commands at root level
58
- cli.add_command(init)
59
- cli.add_command(diagnose)
60
- cli.add_command(analyze)
61
-
62
- # Register deployment commands at root level
63
- cli.add_command(deploy)
64
- cli.add_command(status)
65
- cli.add_command(logs)
66
- cli.add_command(report)
67
-
68
-
69
- def main():
70
- """Main entry point."""
71
- cli()
72
-
73
-
74
- if __name__ == "__main__":
75
- main()
1
+ """
2
+ Xenfra CLI - Main entry point.
3
+
4
+ A modern, AI-powered CLI for deploying Python apps to DigitalOcean.
5
+ """
6
+
7
+ import os
8
+
9
+ import click
10
+ from rich.console import Console
11
+
12
+ from .commands.auth import auth
13
+ from .commands.deployments import delete, deploy, dry_run_command, logs, report, status
14
+ from .commands.intelligence import analyze, diagnose, init
15
+ from .commands.projects import projects
16
+ from .commands.security_cmd import security
17
+
18
+ console = Console()
19
+
20
+ # Production-ready: API URL is hardcoded as https://api.xenfra.tech
21
+ # No configuration needed - works out of the box after pip install
22
+
23
+
24
+ @click.group()
25
+ @click.version_option(version="0.2.9")
26
+ def cli():
27
+ """
28
+ Xenfra CLI: Deploy Python apps to DigitalOcean with zero configuration.
29
+
30
+ Quick Start:
31
+ xenfra auth login # Authenticate with Xenfra
32
+ xenfra init # Initialize your project (AI-powered)
33
+ xenfra dry-run # Validate before deploying (3-tier)
34
+ xenfra deploy # Deploy to DigitalOcean
35
+
36
+ Commands:
37
+ auth Authentication (login, logout, whoami)
38
+ projects Manage projects (list, show, delete)
39
+ init Smart project initialization (AI-powered)
40
+ dry-run Validate project without deploying (3-tier)
41
+ diagnose Diagnose deployment failures (AI-powered)
42
+ analyze Analyze codebase without creating config
43
+
44
+ For help on a specific command:
45
+ xenfra <command> --help
46
+ """
47
+ # Configure keyring backend
48
+ os.environ["KEYRING_BACKEND"] = "keyrings.alt.file.PlaintextKeyring"
49
+
50
+ # Security works silently in the background
51
+ # Only shows warnings if there's an actual security issue
52
+
53
+
54
+ # Register command groups
55
+ cli.add_command(auth)
56
+ cli.add_command(projects)
57
+ cli.add_command(security)
58
+
59
+ # Register intelligence commands at root level
60
+ cli.add_command(init)
61
+ cli.add_command(diagnose)
62
+ cli.add_command(analyze)
63
+
64
+ # Register deployment commands at root level
65
+ cli.add_command(deploy)
66
+ cli.add_command(dry_run_command)
67
+ cli.add_command(status)
68
+ cli.add_command(logs)
69
+ cli.add_command(report)
70
+ cli.add_command(delete)
71
+
72
+
73
+ def main():
74
+ """Main entry point."""
75
+ cli()
76
+
77
+
78
+ if __name__ == "__main__":
79
+ main()
xenfra/utils/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
- """
2
- Utility functions for Xenfra CLI.
3
- """
1
+ """
2
+ Utility functions for Xenfra CLI.
3
+ """