py-connect-test 2.2.0__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.
- py_connect_test-2.2.0/PKG-INFO +169 -0
- py_connect_test-2.2.0/README.md +132 -0
- py_connect_test-2.2.0/pyproject.toml +241 -0
- py_connect_test-2.2.0/src/py_connect_test/__init__.py +0 -0
- py_connect_test-2.2.0/src/py_connect_test/main.py +51 -0
- py_connect_test-2.2.0/src/py_connect_test/services/__init__.py +0 -0
- py_connect_test-2.2.0/src/py_connect_test/services/http.py +54 -0
- py_connect_test-2.2.0/src/py_connect_test/settings.py +12 -0
- py_connect_test-2.2.0/src/py_connect_test/setup_logger.py +14 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: py_connect_test
|
|
3
|
+
Version: 2.2.0
|
|
4
|
+
Summary: A simple Python package for testing connectivity.
|
|
5
|
+
License: MIT
|
|
6
|
+
Keywords: python3
|
|
7
|
+
Author: Victor Bajada
|
|
8
|
+
Author-email: bajada.victor@gmail.com
|
|
9
|
+
Maintainer: Victor Bajada
|
|
10
|
+
Maintainer-email: bajada.victor@gmail.com
|
|
11
|
+
Requires-Python: >=3.14,<4.0
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
22
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
23
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Dist: httpx (>=0.28.1,<0.29.0)
|
|
26
|
+
Requires-Dist: loguru (>=0.7.0,<0.8.0)
|
|
27
|
+
Requires-Dist: pydantic-settings (>=2.14.1,<3.0.0)
|
|
28
|
+
Requires-Dist: rich (>=14.0.0,<15.0.0)
|
|
29
|
+
Requires-Dist: typer (>=0.25.0,<0.26.0)
|
|
30
|
+
Project-URL: Changelog, https://github.com/Diapolo10/project-name/blob/main/CHANGELOG.md
|
|
31
|
+
Project-URL: Documentation, https://github.com/tech1ndex/py-connect-test/tree/main/docs
|
|
32
|
+
Project-URL: Homepage, https://pypi.org/project/py-connect-test/
|
|
33
|
+
Project-URL: Repository, https://github.com/tech1ndex/py-connect-test
|
|
34
|
+
Project-URL: Tracker, https://github.com/Diapolo10/project-name/issues
|
|
35
|
+
Description-Content-Type: text/markdown
|
|
36
|
+
|
|
37
|
+
# py-connect-test
|
|
38
|
+
|
|
39
|
+
A simple Python package to test HTTP connectivity to URLs and retrieve status codes. Built with Typer CLI framework and httpx.
|
|
40
|
+
|
|
41
|
+
## Prerequisites
|
|
42
|
+
|
|
43
|
+
- Python 3.14 or higher
|
|
44
|
+
- Poetry (for dependency management)
|
|
45
|
+
|
|
46
|
+
## Installation
|
|
47
|
+
|
|
48
|
+
### From Source
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
git clone https://github.com/tech1ndex/py-connect-test.git
|
|
52
|
+
cd py-connect-test
|
|
53
|
+
poetry install
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Usage
|
|
57
|
+
|
|
58
|
+
### Basic Usage
|
|
59
|
+
|
|
60
|
+
Test connectivity to the default URL (https://ifconfig.me):
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
poetry run py-connect-test test
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Or directly:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
python -m py_connect_test.main test
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Options
|
|
73
|
+
|
|
74
|
+
#### Bypass SSL Certificate Validation
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
poetry run py-connect-test test --insecure
|
|
78
|
+
# or
|
|
79
|
+
poetry run py-connect-test test -i
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
#### Send Alerts to Webhook
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
poetry run py-connect-test test --alerts
|
|
86
|
+
# or
|
|
87
|
+
poetry run py-connect-test test -a
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
#### Combined Options
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
poetry run py-connect-test test --insecure --alerts
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### View Help
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
poetry run py-connect-test test --help
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Docker Usage
|
|
103
|
+
|
|
104
|
+
### Build Image
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
docker build -t py-connect-test:latest .
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Run Container
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
docker run -d \
|
|
114
|
+
-e HTTP_URL=https://example.com \
|
|
115
|
+
-e WEBHOOK_URL=http://prometheus.local \
|
|
116
|
+
ghcr.io/tech1ndex/py-connect-test:latest
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Bypass SSL Validation
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
docker run -d \
|
|
123
|
+
-e PY_CONNECT_TEST_URL=https://example.com \
|
|
124
|
+
ghcr.io/tech1ndex/py-connect-test:latest \
|
|
125
|
+
py-connect-test test --insecure
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Multi-Architecture Support
|
|
129
|
+
|
|
130
|
+
Available architectures:
|
|
131
|
+
- `amd64`
|
|
132
|
+
- `arm64`
|
|
133
|
+
|
|
134
|
+
Pull specific architecture:
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
docker pull ghcr.io/tech1ndex/py-connect-test:latest-amd64
|
|
138
|
+
docker pull ghcr.io/tech1ndex/py-connect-test:latest-arm64
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Environment Variables
|
|
142
|
+
|
|
143
|
+
| Variable | Description | Default | Required |
|
|
144
|
+
|-----------------------|-------------|---------|----------|
|
|
145
|
+
| `PY_CONNECT_TEST_URL` | URL to test connectivity to | `https://ifconfig.me` | No |
|
|
146
|
+
| `WEBHOOK_URL` | Webhook URL for alerts | `http://prometheus.local` | No |
|
|
147
|
+
| `PAYLOAD_FILE_PATH` | Path to JSON payload file for webhooks | `/tmp/payload.json` | No |
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
## Project Structure
|
|
151
|
+
|
|
152
|
+
```
|
|
153
|
+
py-connect-test/
|
|
154
|
+
├── src/py_connect_test/
|
|
155
|
+
│ ├── main.py # CLI entry point
|
|
156
|
+
│ ├── settings.py # Configuration management
|
|
157
|
+
│ ├── setup_logger.py # Logger setup
|
|
158
|
+
│ ├── py.typed # Type hints marker
|
|
159
|
+
│ └── services/
|
|
160
|
+
│ └── http.py # HTTP service
|
|
161
|
+
├── tests/
|
|
162
|
+
│ ├── conftest.py # Pytest fixtures
|
|
163
|
+
│ └── services/
|
|
164
|
+
│ └── test_http_service.py # HTTP service tests
|
|
165
|
+
├── pyproject.toml # Project configuration
|
|
166
|
+
├── Dockerfile # Docker configuration
|
|
167
|
+
└── README.md
|
|
168
|
+
```
|
|
169
|
+
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# py-connect-test
|
|
2
|
+
|
|
3
|
+
A simple Python package to test HTTP connectivity to URLs and retrieve status codes. Built with Typer CLI framework and httpx.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
- Python 3.14 or higher
|
|
8
|
+
- Poetry (for dependency management)
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
### From Source
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
git clone https://github.com/tech1ndex/py-connect-test.git
|
|
16
|
+
cd py-connect-test
|
|
17
|
+
poetry install
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
### Basic Usage
|
|
23
|
+
|
|
24
|
+
Test connectivity to the default URL (https://ifconfig.me):
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
poetry run py-connect-test test
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Or directly:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
python -m py_connect_test.main test
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Options
|
|
37
|
+
|
|
38
|
+
#### Bypass SSL Certificate Validation
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
poetry run py-connect-test test --insecure
|
|
42
|
+
# or
|
|
43
|
+
poetry run py-connect-test test -i
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
#### Send Alerts to Webhook
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
poetry run py-connect-test test --alerts
|
|
50
|
+
# or
|
|
51
|
+
poetry run py-connect-test test -a
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
#### Combined Options
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
poetry run py-connect-test test --insecure --alerts
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### View Help
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
poetry run py-connect-test test --help
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Docker Usage
|
|
67
|
+
|
|
68
|
+
### Build Image
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
docker build -t py-connect-test:latest .
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Run Container
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
docker run -d \
|
|
78
|
+
-e HTTP_URL=https://example.com \
|
|
79
|
+
-e WEBHOOK_URL=http://prometheus.local \
|
|
80
|
+
ghcr.io/tech1ndex/py-connect-test:latest
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Bypass SSL Validation
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
docker run -d \
|
|
87
|
+
-e PY_CONNECT_TEST_URL=https://example.com \
|
|
88
|
+
ghcr.io/tech1ndex/py-connect-test:latest \
|
|
89
|
+
py-connect-test test --insecure
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Multi-Architecture Support
|
|
93
|
+
|
|
94
|
+
Available architectures:
|
|
95
|
+
- `amd64`
|
|
96
|
+
- `arm64`
|
|
97
|
+
|
|
98
|
+
Pull specific architecture:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
docker pull ghcr.io/tech1ndex/py-connect-test:latest-amd64
|
|
102
|
+
docker pull ghcr.io/tech1ndex/py-connect-test:latest-arm64
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Environment Variables
|
|
106
|
+
|
|
107
|
+
| Variable | Description | Default | Required |
|
|
108
|
+
|-----------------------|-------------|---------|----------|
|
|
109
|
+
| `PY_CONNECT_TEST_URL` | URL to test connectivity to | `https://ifconfig.me` | No |
|
|
110
|
+
| `WEBHOOK_URL` | Webhook URL for alerts | `http://prometheus.local` | No |
|
|
111
|
+
| `PAYLOAD_FILE_PATH` | Path to JSON payload file for webhooks | `/tmp/payload.json` | No |
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
## Project Structure
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
py-connect-test/
|
|
118
|
+
├── src/py_connect_test/
|
|
119
|
+
│ ├── main.py # CLI entry point
|
|
120
|
+
│ ├── settings.py # Configuration management
|
|
121
|
+
│ ├── setup_logger.py # Logger setup
|
|
122
|
+
│ ├── py.typed # Type hints marker
|
|
123
|
+
│ └── services/
|
|
124
|
+
│ └── http.py # HTTP service
|
|
125
|
+
├── tests/
|
|
126
|
+
│ ├── conftest.py # Pytest fixtures
|
|
127
|
+
│ └── services/
|
|
128
|
+
│ └── test_http_service.py # HTTP service tests
|
|
129
|
+
├── pyproject.toml # Project configuration
|
|
130
|
+
├── Dockerfile # Docker configuration
|
|
131
|
+
└── README.md
|
|
132
|
+
```
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["poetry-core>=1.2.0", "wheel>=0.47.0",]
|
|
3
|
+
build-backend = "poetry.core.masonry.api"
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
[tool.coverage.run]
|
|
7
|
+
branch = true
|
|
8
|
+
relative_files = true
|
|
9
|
+
omit = [
|
|
10
|
+
".tox/*",
|
|
11
|
+
"tests/*",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
[tool.poetry]
|
|
16
|
+
name = "py_connect_test"
|
|
17
|
+
version = "2.2.0"
|
|
18
|
+
description = "A simple Python package for testing connectivity."
|
|
19
|
+
|
|
20
|
+
packages = [
|
|
21
|
+
{ include = "py_connect_test", from = "src" },
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
authors = ["Victor Bajada <bajada.victor@gmail.com>",]
|
|
25
|
+
maintainers = ["Victor Bajada <bajada.victor@gmail.com>",]
|
|
26
|
+
|
|
27
|
+
include = []
|
|
28
|
+
license = "MIT"
|
|
29
|
+
readme = "README.md"
|
|
30
|
+
|
|
31
|
+
homepage = "https://pypi.org/project/py-connect-test/"
|
|
32
|
+
repository = "https://github.com/tech1ndex/py-connect-test"
|
|
33
|
+
documentation = "https://github.com/tech1ndex/py-connect-test/tree/main/docs"
|
|
34
|
+
|
|
35
|
+
keywords = [
|
|
36
|
+
"python3",
|
|
37
|
+
]
|
|
38
|
+
classifiers = [
|
|
39
|
+
"Development Status :: 3 - Alpha",
|
|
40
|
+
"License :: OSI Approved :: MIT License",
|
|
41
|
+
"Operating System :: OS Independent",
|
|
42
|
+
"Programming Language :: Python :: 3.8",
|
|
43
|
+
"Programming Language :: Python :: 3.9",
|
|
44
|
+
"Programming Language :: Python :: 3.10",
|
|
45
|
+
"Programming Language :: Python :: 3.11",
|
|
46
|
+
"Programming Language :: Python :: 3.12",
|
|
47
|
+
"Programming Language :: Python :: Implementation :: CPython",
|
|
48
|
+
"Programming Language :: Python :: Implementation :: PyPy",
|
|
49
|
+
"Typing :: Typed",
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
[tool.poetry.dependencies]
|
|
54
|
+
python="^3.14"
|
|
55
|
+
httpx="^0.28.1"
|
|
56
|
+
typer="^0.25.0"
|
|
57
|
+
loguru="^0.7.0"
|
|
58
|
+
pydantic-settings="^2.14.1"
|
|
59
|
+
rich="^14.0.0"
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
[tool.poetry.group.dev.dependencies]
|
|
63
|
+
mypy = "^2.1.0"
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
[tool.poetry.group.linters]
|
|
67
|
+
optional = true
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
[tool.poetry.group.linters.dependencies]
|
|
71
|
+
ruff = "^0.15.0"
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
[tool.poetry.group.tests]
|
|
75
|
+
optional = true
|
|
76
|
+
|
|
77
|
+
[tool.poetry.scripts]
|
|
78
|
+
py_connect_test = "py_connect_test.main:app"
|
|
79
|
+
|
|
80
|
+
[tool.poetry.group.tests.dependencies]
|
|
81
|
+
pytest = "^8.3.3"
|
|
82
|
+
pytest-cov = "^6.0.0"
|
|
83
|
+
tox = "^4.23.2"
|
|
84
|
+
tox-gh-actions = "^3.2.0"
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
[tool.poetry.urls]
|
|
88
|
+
"Tracker" = "https://github.com/Diapolo10/project-name/issues"
|
|
89
|
+
"Changelog" = "https://github.com/Diapolo10/project-name/blob/main/CHANGELOG.md"
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
[tool.pytest.ini_options]
|
|
93
|
+
minversion = "6.0"
|
|
94
|
+
addopts = """
|
|
95
|
+
--doctest-modules \
|
|
96
|
+
--cov=./ \
|
|
97
|
+
--cov-append \
|
|
98
|
+
--cov-report html:tests/reports/coverage-html \
|
|
99
|
+
--cov-report xml:tests/reports/coverage.xml \
|
|
100
|
+
--ignore=docs/
|
|
101
|
+
"""
|
|
102
|
+
testpaths = [
|
|
103
|
+
"tests",
|
|
104
|
+
]
|
|
105
|
+
|
|
106
|
+
[tool.ruff]
|
|
107
|
+
lint.extend-select = [
|
|
108
|
+
"A", # Builtins
|
|
109
|
+
"ANN", # Annotations
|
|
110
|
+
"ARG", # Unused arguments
|
|
111
|
+
"B", # Bugbear
|
|
112
|
+
"BLE", # Blind except
|
|
113
|
+
"C4", # Comprehensions
|
|
114
|
+
"C90", # mccabe
|
|
115
|
+
"COM", # Commas
|
|
116
|
+
"D1", # Undocumented public elements
|
|
117
|
+
"D2", # Docstring conventions
|
|
118
|
+
"D3", # Triple double quotes
|
|
119
|
+
"D4", # Docstring text format
|
|
120
|
+
"DTZ", # Datetimes
|
|
121
|
+
"EM", # Error messages
|
|
122
|
+
"ERA", # Commented-out code
|
|
123
|
+
"EXE", # Executable
|
|
124
|
+
"F", # Pyflakes
|
|
125
|
+
"FA", # __future__ annotations
|
|
126
|
+
"FLY", # F-strings
|
|
127
|
+
"G", # Logging format
|
|
128
|
+
"I", # Isort
|
|
129
|
+
"ICN", # Import conventions
|
|
130
|
+
"INP", # Disallow PEP-420 (Implicit namespace packages)
|
|
131
|
+
"INT", # gettext
|
|
132
|
+
"ISC", # Implicit str concat
|
|
133
|
+
"N", # PEP-8 Naming
|
|
134
|
+
"NPY", # Numpy
|
|
135
|
+
"PERF", # Unnecessary performance costs
|
|
136
|
+
"PGH", # Pygrep hooks
|
|
137
|
+
"PIE", # Unnecessary code
|
|
138
|
+
"PL", # Pylint
|
|
139
|
+
"PT", # Pytest
|
|
140
|
+
"PTH", # Use Pathlib
|
|
141
|
+
"PYI", # Stub files
|
|
142
|
+
"Q", # Quotes
|
|
143
|
+
"RET", # Return
|
|
144
|
+
"RUF", # Ruff
|
|
145
|
+
"RSE", # Raise
|
|
146
|
+
"S", # Bandit
|
|
147
|
+
"SIM", # Code simplification
|
|
148
|
+
"SLF", # Private member access
|
|
149
|
+
"SLOT", # __slots__
|
|
150
|
+
"T10", # Debugger
|
|
151
|
+
"T20", # Print
|
|
152
|
+
"TCH", # Type checking
|
|
153
|
+
"TID", # Tidy imports
|
|
154
|
+
"TRY", # Exception handling
|
|
155
|
+
"UP", # Pyupgrade
|
|
156
|
+
"W", # Warnings
|
|
157
|
+
"YTT", # sys.version
|
|
158
|
+
]
|
|
159
|
+
lint.extend-ignore = [
|
|
160
|
+
"D203", # One blank line before class docstring
|
|
161
|
+
"D212", # Multi-line summary first line
|
|
162
|
+
"PLR0913", # Too many arguments
|
|
163
|
+
"Q000", # Single quotes found but double quotes preferred
|
|
164
|
+
"D100", # Missing docstring in public module
|
|
165
|
+
"D101", # Missing docstring in public module
|
|
166
|
+
"D102", # Missing docstring in public class
|
|
167
|
+
"D103", # Missing docstring in public function
|
|
168
|
+
"D104", # Missing docstring in public package
|
|
169
|
+
"D105", # Missing docstring in magic method
|
|
170
|
+
"D106", # Missing docstring in public nested class
|
|
171
|
+
"D107", # Missing docstring in __init__
|
|
172
|
+
"PT028", # Pytest test function without assert
|
|
173
|
+
"ANN201", # Missing type annotation for self in method
|
|
174
|
+
"ANN202", # Missing type annotation for cls in classmethod
|
|
175
|
+
"ANN204", # Missing type annotation for magic method
|
|
176
|
+
"PTH123", # Use of os.path for path manipulation
|
|
177
|
+
"PLE1205", # Pylint: Too many arguments for logging format string
|
|
178
|
+
"TRY300", # Try block ends with a continue statement
|
|
179
|
+
"TRY400", # Try block ends with a return statement
|
|
180
|
+
|
|
181
|
+
]
|
|
182
|
+
|
|
183
|
+
line-length = 120
|
|
184
|
+
# preview = true
|
|
185
|
+
show-fixes = true
|
|
186
|
+
src = ["src",]
|
|
187
|
+
target-version = "py38"
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
[tool.ruff.lint.flake8-quotes]
|
|
191
|
+
docstring-quotes = "double"
|
|
192
|
+
multiline-quotes = "double"
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
[tool.ruff.lint.mccabe]
|
|
196
|
+
# Unlike Flake8, default to a complexity level of 10.
|
|
197
|
+
max-complexity = 10
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
[tool.ruff.lint.per-file-ignores]
|
|
201
|
+
# https://beta.ruff.rs/docs/rules/
|
|
202
|
+
"__init__.py" = ["F401","F403","F405",]
|
|
203
|
+
"tests/*" = ["ANN", "ARG", "INP001", "S101",]
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
[tool.ruff.lint.pylint]
|
|
207
|
+
max-args = 15
|
|
208
|
+
max-branches = 20
|
|
209
|
+
max-returns = 10
|
|
210
|
+
max-statements = 80
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
[tool.ruff.lint.flake8-tidy-imports]
|
|
214
|
+
ban-relative-imports = "all"
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
[tool.tox]
|
|
218
|
+
legacy_tox_ini = """
|
|
219
|
+
[tox]
|
|
220
|
+
envlist = py38, py39, py310, py311, pypy3
|
|
221
|
+
skip_missing_interpreters = true
|
|
222
|
+
|
|
223
|
+
[gh-actions]
|
|
224
|
+
python =
|
|
225
|
+
3.8: py38
|
|
226
|
+
3.9: py39
|
|
227
|
+
3.10: py310
|
|
228
|
+
3.11: py311
|
|
229
|
+
pypy-3.10: pypy3
|
|
230
|
+
|
|
231
|
+
[testenv]
|
|
232
|
+
passenv = GITHUB_*
|
|
233
|
+
allowlist_externals = poetry
|
|
234
|
+
|
|
235
|
+
commands =
|
|
236
|
+
poetry run pytest
|
|
237
|
+
poetry run coverage report
|
|
238
|
+
"""
|
|
239
|
+
|
|
240
|
+
[tool.mypy]
|
|
241
|
+
ignore_missing_imports = true
|
|
File without changes
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
import typer
|
|
6
|
+
|
|
7
|
+
from py_connect_test.services.http import HttpTest
|
|
8
|
+
from py_connect_test.setup_logger import setup_logger
|
|
9
|
+
|
|
10
|
+
app = typer.Typer(help="Http Connection Test")
|
|
11
|
+
|
|
12
|
+
logger = setup_logger()
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@app.callback(invoke_without_command=True)
|
|
16
|
+
def callback(ctx: typer.Context) -> None:
|
|
17
|
+
if ctx.invoked_subcommand is None:
|
|
18
|
+
typer.echo(ctx.get_help())
|
|
19
|
+
sys.exit(0)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@app.command()
|
|
23
|
+
def test(
|
|
24
|
+
insecure: bool = typer.Option(
|
|
25
|
+
False,
|
|
26
|
+
"-i",
|
|
27
|
+
"--insecure",
|
|
28
|
+
help="Bypass Certificate Checking",
|
|
29
|
+
),
|
|
30
|
+
alerts: bool = typer.Option(
|
|
31
|
+
False,
|
|
32
|
+
"-a",
|
|
33
|
+
"--alerts",
|
|
34
|
+
help="Send Alert to Webhook (WEBHOOK_URL env variable)",
|
|
35
|
+
),
|
|
36
|
+
):
|
|
37
|
+
http_test = HttpTest(insecure=insecure)
|
|
38
|
+
status_code = http_test.get_status_code()
|
|
39
|
+
logger.success("Connected: {}", status_code)
|
|
40
|
+
|
|
41
|
+
if alerts:
|
|
42
|
+
alert = http_test.post_alerts()
|
|
43
|
+
logger.success("Alert response: {}", alert.status_code)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def main() -> None:
|
|
47
|
+
app()
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
if __name__ == "__main__":
|
|
51
|
+
main()
|
|
File without changes
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
|
|
5
|
+
import httpx
|
|
6
|
+
|
|
7
|
+
from py_connect_test.settings import AlertSettings, HttpSettings
|
|
8
|
+
from py_connect_test.setup_logger import setup_logger
|
|
9
|
+
|
|
10
|
+
logger = setup_logger()
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class HttpTest:
|
|
14
|
+
def __init__(self, insecure: bool) -> None:
|
|
15
|
+
self.http_settings = HttpSettings()
|
|
16
|
+
self.alert_settings = AlertSettings()
|
|
17
|
+
self.insecure = insecure
|
|
18
|
+
|
|
19
|
+
def get(self) -> httpx.Response | None:
|
|
20
|
+
with httpx.Client(
|
|
21
|
+
base_url=self.http_settings.url,
|
|
22
|
+
verify=not self.insecure,
|
|
23
|
+
follow_redirects=True,
|
|
24
|
+
) as client:
|
|
25
|
+
logger.info("Connecting to {}", self.http_settings.url)
|
|
26
|
+
try:
|
|
27
|
+
response = client.get("/")
|
|
28
|
+
response.raise_for_status()
|
|
29
|
+
return response
|
|
30
|
+
except httpx.RequestError as e:
|
|
31
|
+
logger.error("Error connecting to {}: {}", self.http_settings.url, e)
|
|
32
|
+
return None
|
|
33
|
+
|
|
34
|
+
def get_status_code(self) -> int | None:
|
|
35
|
+
response = self.get()
|
|
36
|
+
if not response:
|
|
37
|
+
return None
|
|
38
|
+
return response.status_code
|
|
39
|
+
|
|
40
|
+
def post_alerts(self) -> httpx.Response:
|
|
41
|
+
with open(self.alert_settings.payload_file_path) as f:
|
|
42
|
+
payload = json.load(f)
|
|
43
|
+
|
|
44
|
+
with httpx.Client(
|
|
45
|
+
base_url=self.alert_settings.webhook_url,
|
|
46
|
+
verify=not self.insecure,
|
|
47
|
+
) as client:
|
|
48
|
+
response = client.post("/", json=payload)
|
|
49
|
+
response.raise_for_status()
|
|
50
|
+
logger.success(
|
|
51
|
+
"Alert posted successfully to {}",
|
|
52
|
+
self.alert_settings.webhook_url,
|
|
53
|
+
)
|
|
54
|
+
return response
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class HttpSettings(BaseSettings):
|
|
5
|
+
model_config = SettingsConfigDict(env_prefix="PY_CONNECT_TEST_")
|
|
6
|
+
|
|
7
|
+
url: str = "https://ifconfig.me"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class AlertSettings(BaseSettings):
|
|
11
|
+
webhook_url: str = "http://prometheus.local"
|
|
12
|
+
payload_file_path: str = "payload.json"
|