pingera-cli 0.1.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.
@@ -0,0 +1,187 @@
1
+ """
2
+ Configuration management utilities
3
+ """
4
+
5
+ import os
6
+ import json
7
+ from pathlib import Path
8
+ from typing import Dict, Any, Optional
9
+
10
+ from .console import console, error_console
11
+
12
+
13
+ def get_config_path() -> Path:
14
+ """
15
+ Get the path to the configuration file
16
+
17
+ Returns:
18
+ Path: Path to the config file
19
+ """
20
+ # Use XDG_CONFIG_HOME if available, otherwise use ~/.config
21
+ config_dir = os.getenv('XDG_CONFIG_HOME')
22
+ if config_dir:
23
+ config_path = Path(config_dir) / 'pingera-cli'
24
+ else:
25
+ config_path = Path.home() / '.config' / 'pingera-cli'
26
+
27
+ try:
28
+ config_path.mkdir(parents=True, exist_ok=True)
29
+ except (OSError, PermissionError):
30
+ # If we can't create the directory, use a temp location for tests
31
+ import tempfile
32
+ temp_dir = Path(tempfile.gettempdir()) / 'pingera-cli'
33
+ temp_dir.mkdir(parents=True, exist_ok=True)
34
+ config_path = temp_dir
35
+
36
+ return config_path / 'config.json'
37
+
38
+
39
+ def get_config() -> Dict[str, Any]:
40
+ """
41
+ Load configuration from file or return default configuration
42
+
43
+ Returns:
44
+ Dict[str, Any]: Configuration dictionary
45
+ """
46
+ default_config = {
47
+ 'base_url': 'https://api.pingera.ru',
48
+ 'output_format': 'table',
49
+ 'verbose': False,
50
+ 'color': True,
51
+ 'timeout': 30.0,
52
+ 'retries': 3,
53
+ 'config_path': str(get_config_path()),
54
+ }
55
+
56
+ config_path = get_config_path()
57
+
58
+ if not config_path.exists():
59
+ return default_config
60
+
61
+ try:
62
+ with open(config_path, 'r') as f:
63
+ config = json.load(f)
64
+
65
+ # Merge with defaults to ensure all keys are present
66
+ merged_config = default_config.copy()
67
+ merged_config.update(config)
68
+ return merged_config
69
+
70
+ except (json.JSONDecodeError, IOError) as e:
71
+ error_console.print(f"[danger]Error reading config file: {e}[/danger]")
72
+ return default_config
73
+
74
+
75
+ def save_config(config: Dict[str, Any]) -> bool:
76
+ """
77
+ Save configuration to file
78
+
79
+ Args:
80
+ config: Configuration dictionary to save
81
+
82
+ Returns:
83
+ bool: True if saved successfully, False otherwise
84
+ """
85
+ config_path = get_config_path()
86
+
87
+ try:
88
+ with open(config_path, 'w') as f:
89
+ json.dump(config, f, indent=2)
90
+ return True
91
+
92
+ except IOError as e:
93
+ error_console.print(f"[danger]Error saving config file: {e}[/danger]")
94
+ return False
95
+
96
+
97
+ def get_api_key() -> Optional[str]:
98
+ """
99
+ Get API key from environment or config
100
+
101
+ Returns:
102
+ Optional[str]: API key if found, None otherwise
103
+ """
104
+ # First try environment variable
105
+ api_key = os.getenv('PINGERA_API_KEY')
106
+ if api_key:
107
+ return api_key
108
+
109
+ # Then try config file
110
+ config = get_config()
111
+ return config.get('api_key')
112
+
113
+
114
+ def set_api_key(api_key: str) -> bool:
115
+ """
116
+ Set API key in configuration file
117
+
118
+ Args:
119
+ api_key: API key to save
120
+
121
+ Returns:
122
+ bool: True if saved successfully, False otherwise
123
+ """
124
+ if not api_key or not api_key.strip():
125
+ return False
126
+
127
+ config = get_config()
128
+ config['api_key'] = api_key.strip()
129
+ return save_config(config)
130
+
131
+
132
+ def set_output_format(output_format: str) -> bool:
133
+ """
134
+ Set output format in configuration file
135
+
136
+ Args:
137
+ output_format: Output format (table, json, yaml)
138
+
139
+ Returns:
140
+ bool: True if saved successfully, False otherwise
141
+ """
142
+ if output_format not in ['table', 'json', 'yaml']:
143
+ return False
144
+
145
+ config = get_config()
146
+ config['output_format'] = output_format
147
+ return save_config(config)
148
+
149
+
150
+ def get_output_format() -> str:
151
+ """
152
+ Get output format from configuration
153
+
154
+ Returns:
155
+ str: Output format (default: table)
156
+ """
157
+ config = get_config()
158
+ return config.get('output_format', 'table')
159
+
160
+
161
+ def validate_config() -> Dict[str, bool]:
162
+ """
163
+ Validate current configuration
164
+
165
+ Returns:
166
+ Dict[str, bool]: Validation results
167
+ """
168
+ results = {
169
+ 'api_key_set': bool(get_api_key()),
170
+ 'config_file_exists': get_config_path().exists(),
171
+ 'config_file_readable': True,
172
+ 'pingera_sdk_available': True,
173
+ }
174
+
175
+ # Test config file readability
176
+ try:
177
+ get_config()
178
+ except Exception:
179
+ results['config_file_readable'] = False
180
+
181
+ # Test Pingera SDK availability
182
+ try:
183
+ from pingera import ApiClient
184
+ except ImportError:
185
+ results['pingera_sdk_available'] = False
186
+
187
+ return results
@@ -0,0 +1,87 @@
1
+ """
2
+ Console utilities for rich output formatting
3
+ """
4
+
5
+ from rich.console import Console
6
+ from rich.theme import Theme
7
+
8
+ # Define custom theme for consistent styling
9
+ custom_theme = Theme({
10
+ "info": "dim cyan",
11
+ "warning": "magenta",
12
+ "danger": "bold red",
13
+ "success": "bold green",
14
+ "error": "bold red on white",
15
+ "highlight": "bold yellow",
16
+ "primary": "bold blue",
17
+ "secondary": "dim white",
18
+ })
19
+
20
+ # Main console for standard output
21
+ console = Console(
22
+ theme=custom_theme,
23
+ highlight=True,
24
+ markup=True,
25
+ emoji=True,
26
+ width=None, # Auto-detect terminal width
27
+ )
28
+
29
+ # Error console for error messages
30
+ error_console = Console(
31
+ stderr=True,
32
+ theme=custom_theme,
33
+ highlight=True,
34
+ markup=True,
35
+ emoji=True,
36
+ width=None,
37
+ )
38
+
39
+ def print_banner():
40
+ """
41
+ Print a welcome banner for PingeraCLI
42
+ """
43
+ banner = """
44
+ [bold blue]
45
+ ██████╗ ██╗███╗ ██╗ ██████╗ ███████╗██████╗ █████╗ ██████╗██╗ ██╗
46
+ ██╔══██╗██║████╗ ██║██╔════╝ ██╔════╝██╔══██╗██╔══██╗ ██╔════╝██║ ██║
47
+ ██████╔╝██║██╔██╗ ██║██║ ███╗█████╗ ██████╔╝███████║ ██║ ██║ ██║
48
+ ██╔═══╝ ██║██║╚██╗██║██║ ██║██╔══╝ ██╔══██╗██╔══██║ ██║ ██║ ██║
49
+ ██║ ██║██║ ╚████║╚██████╔╝███████╗██║ ██║██║ ██║ ╚██████╗███████╗██║
50
+ ╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚══════╝╚═╝
51
+ [/bold blue]
52
+ """
53
+ console.print(banner)
54
+ console.print("[dim]A beautiful CLI tool for Pingera Platform[/dim]\n")
55
+
56
+
57
+ def print_separator(char: str = "─", length: int = 50, style: str = "dim"):
58
+ """
59
+ Print a separator line
60
+
61
+ Args:
62
+ char: Character to use for separator
63
+ length: Length of the separator
64
+ style: Rich style to apply
65
+ """
66
+ separator = char * length
67
+ console.print(f"[{style}]{separator}[/{style}]")
68
+
69
+
70
+ def print_status(message: str, status: str = "info"):
71
+ """
72
+ Print a status message with appropriate styling
73
+
74
+ Args:
75
+ message: The message to print
76
+ status: Status type (info, warning, danger, success, error)
77
+ """
78
+ status_icons = {
79
+ "info": "ℹ️",
80
+ "warning": "⚠️",
81
+ "danger": "🚨",
82
+ "success": "✅",
83
+ "error": "❌",
84
+ }
85
+
86
+ icon = status_icons.get(status, "•")
87
+ console.print(f"[{status}]{icon} {message}[/{status}]")
@@ -0,0 +1,199 @@
1
+ Metadata-Version: 2.4
2
+ Name: pingera-cli
3
+ Version: 0.1.0
4
+ Summary: A beautiful Python CLI tool built with typer and rich, distributed via pip and based on Pingera SDK
5
+ Home-page: https://github.com/pingera/pingera-cli
6
+ Author: PingeraCLI Team
7
+ Author-email: Pingera Team <privet@pingera.ru>
8
+ Maintainer-email: Pingera Team <privet@pingera.ru>
9
+ License: MIT
10
+ Project-URL: Homepage, https://github.com/pingera/pingera-cli
11
+ Project-URL: Documentation, https://docs.pingera.com/cli
12
+ Project-URL: Repository, https://github.com/pingera/pingera-cli
13
+ Project-URL: Bug Tracker, https://github.com/pingera/pingera-cli/issues
14
+ Keywords: cli,pingera,network,monitoring,typer,rich,terminal
15
+ Classifier: Development Status :: 3 - Alpha
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: Intended Audience :: System Administrators
18
+ Classifier: License :: OSI Approved :: MIT License
19
+ Classifier: Operating System :: OS Independent
20
+ Classifier: Programming Language :: Python :: 3
21
+ Classifier: Programming Language :: Python :: 3.7
22
+ Classifier: Programming Language :: Python :: 3.8
23
+ Classifier: Programming Language :: Python :: 3.9
24
+ Classifier: Programming Language :: Python :: 3.10
25
+ Classifier: Programming Language :: Python :: 3.11
26
+ Classifier: Topic :: System :: Networking
27
+ Classifier: Topic :: Utilities
28
+ Classifier: Environment :: Console
29
+ Requires-Python: >=3.7
30
+ Description-Content-Type: text/markdown
31
+ License-File: LICENSE
32
+ Requires-Dist: typer[all]>=0.9.0
33
+ Requires-Dist: rich>=13.0.0
34
+ Requires-Dist: pingera-sdk
35
+ Requires-Dist: click>=8.0.0
36
+ Provides-Extra: dev
37
+ Requires-Dist: pytest>=6.0; extra == "dev"
38
+ Requires-Dist: pytest-cov; extra == "dev"
39
+ Requires-Dist: black; extra == "dev"
40
+ Requires-Dist: flake8; extra == "dev"
41
+ Requires-Dist: mypy; extra == "dev"
42
+ Dynamic: author
43
+ Dynamic: home-page
44
+ Dynamic: license-file
45
+ Dynamic: requires-python
46
+
47
+
48
+ # Pingera Platform CLI 🚀
49
+
50
+ A beautiful Python CLI tool for the [Pingera Platform](https://pingera.ru) - built with typer and rich, distributed via pip and based on Pingera SDK.
51
+
52
+ [![PyPI version](https://badge.fury.io/py/pingera-cli.svg)](https://badge.fury.io/py/pingera-cli)
53
+ [![Python Support](https://img.shields.io/pypi/pyversions/pingera-cli.svg)](https://pypi.org/project/pingera-cli/)
54
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
55
+
56
+ ## ✨ Features
57
+
58
+ - **Beautiful Terminal Output**: Powered by Rich library for colorful, formatted output
59
+ - **Modern CLI Interface**: Built with Typer for intuitive command-line interactions
60
+ - **Pingera Platform Integration**: Seamlessly integrates with Pingera SDK for network monitoring
61
+ - **Cross-Platform**: Works on Windows, macOS, and Linux
62
+ - **Easy Installation**: Simple pip install with all dependencies managed
63
+ - **Configuration Management**: Flexible configuration with environment variables and config files
64
+
65
+ ## 🚀 Installation
66
+
67
+ Install Pingera Platform CLI using pip:
68
+
69
+ ```bash
70
+ pip install pingera-cli
71
+ ```
72
+
73
+ ## 🔐 Authentication
74
+
75
+ Before using the CLI, you need to authenticate with the Pingera Platform:
76
+
77
+ 1. **Get your API key**: Visit [app.pingera.ru](https://app.pingera.ru) and create an API token in your account settings
78
+ 2. **Login to the CLI**:
79
+ ```bash
80
+ pngr auth login --api-key your-api-key-here
81
+ ```
82
+ 3. **Verify authentication**:
83
+ ```bash
84
+ pngr auth status
85
+ ```
86
+
87
+ Alternatively, you can set the API key as an environment variable:
88
+ ```bash
89
+ export PINGERA_API_KEY=your-api-key-here
90
+ ```
91
+
92
+ ## 📖 Basic Usage
93
+
94
+ ### List all monitoring checks
95
+ ```bash
96
+ pngr checks list
97
+ ```
98
+
99
+ ### Get details of a specific check
100
+ ```bash
101
+ pngr checks get <check-id>
102
+ ```
103
+
104
+ ### Create a new web check
105
+ ```bash
106
+ pngr checks create \
107
+ --name "My Website" \
108
+ --type web \
109
+ --url https://example.com \
110
+ --interval 300
111
+ ```
112
+
113
+ ### Get check results
114
+ ```bash
115
+ pngr checks results <check-id>
116
+ ```
117
+
118
+ ### Run an on-demand check
119
+ ```bash
120
+ pngr checks run custom \
121
+ --type web \
122
+ --url https://example.com \
123
+ --name "Quick Test"
124
+ ```
125
+
126
+ ### List available regions
127
+ ```bash
128
+ pngr checks list-regions
129
+ ```
130
+
131
+ ### Filter regions by check type
132
+ ```bash
133
+ pngr checks list-regions --check-type web
134
+ ```
135
+
136
+ ## 🔧 Configuration
137
+
138
+ The CLI stores configuration in `~/.config/pingera-cli/config.json`. You can manage settings with:
139
+
140
+ ```bash
141
+ # Show current configuration
142
+ pngr config show
143
+
144
+ # Set default output format
145
+ pngr config set output_format json
146
+ ```
147
+
148
+ ## 📊 Output Formats
149
+
150
+ The CLI supports multiple output formats:
151
+
152
+ - **table** (default): Human-readable tables
153
+ - **json**: JSON format for scripting
154
+ - **yaml**: YAML format
155
+
156
+ ```bash
157
+ # JSON output
158
+ pngr checks list --output json
159
+
160
+ # YAML output
161
+ pngr checks list --output yaml
162
+ ```
163
+
164
+ ## 🌐 Platform Links
165
+
166
+ - **Pingera Platform**: [https://pingera.ru](https://pingera.ru)
167
+ - **Web Application**: [https://app.pingera.ru](https://app.pingera.ru)
168
+ - **Documentation**: [https://docs.pingera.ru](https://docs.pingera.ru)
169
+
170
+ ## 🛠️ Development
171
+
172
+ ```bash
173
+ # Clone the repository
174
+ git clone https://github.com/pingera/pingera-cli.git
175
+ cd pingera-cli
176
+
177
+ # Install in development mode
178
+ pip install -e .
179
+
180
+ # Test the CLI (after installation)
181
+ pngr --help
182
+
183
+ # Run tests
184
+ python -m pytest tests/
185
+ ```
186
+
187
+ ## 📝 License
188
+
189
+ This project is licensed under the MIT License - see the LICENSE file for details.
190
+
191
+ ## 🤝 Contributing
192
+
193
+ Contributions are welcome! Please feel free to submit a Pull Request.
194
+
195
+ ## 📞 Support
196
+
197
+ - **Issues**: [GitHub Issues](https://github.com/pingera/pingera-cli/issues)
198
+ - **Documentation**: [Pingera CLI Docs](https://docs.pingera.ru/devs/cli)
199
+ - **Platform Support**: [app.pingera.ru](https://app.pingera.ru)
@@ -0,0 +1,25 @@
1
+ pingera_cli/__init__.py,sha256=3KY4WOVAHRoLw6fapxhL8JOs8vE_-EpdgN3ZyUlnP8c,294
2
+ pingera_cli/__main__.py,sha256=_yI6Ujgf0MXLSziFmPceqOhrqh9G7LlSW0SoHSpEu9k,154
3
+ pingera_cli/main.py,sha256=NqFfsHlCmIoQPzhZH8YclwnqK8hGBGwt5hV2dAxzKwk,6580
4
+ pingera_cli/commands/__init__.py,sha256=SROYrwAX2ycbGb9N627suPR0zb76QX89h_zLvmNX3ng,149
5
+ pingera_cli/commands/auth.py,sha256=671Q1-LBgGATJrZog0CWyLhTNM3j3SNs_9MnL5NbkWI,7744
6
+ pingera_cli/commands/base.py,sha256=VQNJNhALdDjUTKDrP6XqciuLyeb98885RP-nnUPNXKk,8183
7
+ pingera_cli/commands/checks.py,sha256=XvQr63xYjzwj2JLYNJQSv-CeZJZ-F6ivtBSLlp6l2UA,50163
8
+ pingera_cli/commands/on_demand_checks.py,sha256=nCOh6ugB715Y0TOv4hjxP40fh-FWb_XJRwG0oGjLFdE,32342
9
+ pingera_cli/formatters/__init__.py,sha256=Zsm4o27fYm1DB5eijkvwDSS8Z91cVZmZ7rALZKJXNHw,455
10
+ pingera_cli/formatters/base_formatter.py,sha256=R459DnNlP_-ocB5g_McVdkY2CADBlGgzP8Y0t7DQ8CE,1369
11
+ pingera_cli/formatters/generic_formatter.py,sha256=dwMTaH6sKHBIDQHg1Ln7X1pqrs0iWofg_KzoIj6yH0Y,1871
12
+ pingera_cli/formatters/multistep_formatter.py,sha256=Z0aa35IeGlqm-XLb5X_GYFNKkbaP-KCzZUsBH-Zv5pQ,5840
13
+ pingera_cli/formatters/registry.py,sha256=OgEKwNgU2jozj_7rFrNDjyjx2SbbGcbI5zV-zhPWh24,1290
14
+ pingera_cli/formatters/ssl_formatter.py,sha256=20-TuuBT_uK8Ka2rrNUysnI04mPMuvuR428BbqiMmJs,4777
15
+ pingera_cli/formatters/synthetic_formatter.py,sha256=02CNEvY9evxRsUpOoQfAuI2VvI9VIXIGQS9Yrn2qEfI,14615
16
+ pingera_cli/formatters/web_formatter.py,sha256=DtzCPqjdC-7y3DnE7F-aoQ_AgkPmJA3vQkMWSC_FfjE,3123
17
+ pingera_cli/utils/__init__.py,sha256=_Qf6IIB5nYse67eQx1kBGJeaIpUpSiYIGEMr47eDSNU,198
18
+ pingera_cli/utils/config.py,sha256=mk6ebcxywMep3xk1Bb6jNLn9P-eqXcvf9IiCnAn7q5s,4491
19
+ pingera_cli/utils/console.py,sha256=DrBu0hN76UVaEbMY_HJBXT_m3ISDk9AywFrBqbqx9pg,3041
20
+ pingera_cli-0.1.0.dist-info/licenses/LICENSE,sha256=CGqfM1VE8cez-_paPyIzeNqzf4CqmabV-O2GDCgCwQs,1070
21
+ pingera_cli-0.1.0.dist-info/METADATA,sha256=98Fn2QS8h_c0jj8vl-_ZF1-iXHF2EMdXB2E-XQ3-HtY,5544
22
+ pingera_cli-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
23
+ pingera_cli-0.1.0.dist-info/entry_points.txt,sha256=0hXkvXTj1u19n4RzZPh8ijsaSiVJ7t-pth6TnnrUeGQ,58
24
+ pingera_cli-0.1.0.dist-info/top_level.txt,sha256=mSBLX-_HqQ1DBSOKhzfj7L-YgeM5OWGW6wVYTVHveTg,12
25
+ pingera_cli-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ pngr = pingera_cli.main:cli_entry_point
@@ -0,0 +1,22 @@
1
+
2
+ MIT License
3
+
4
+ Copyright (c) 2025 Pingera Team
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ pingera_cli