https-checker-simple 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.
- https_checker_simple-0.1.0.dist-info/METADATA +31 -0
- https_checker_simple-0.1.0.dist-info/RECORD +9 -0
- https_checker_simple-0.1.0.dist-info/WHEEL +5 -0
- https_checker_simple-0.1.0.dist-info/entry_points.txt +2 -0
- https_checker_simple-0.1.0.dist-info/licenses/LICENSE +21 -0
- https_checker_simple-0.1.0.dist-info/top_level.txt +1 -0
- simple_http_checker/__init__.py +0 -0
- simple_http_checker/checker.py +47 -0
- simple_http_checker/cli.py +52 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: https-checker-simple
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A simple CLI tool to check the status of URLS.
|
|
5
|
+
Requires-Python: >=3.9
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: requests<3.0,>=2.28
|
|
9
|
+
Requires-Dist: click<9.0,>=8.0
|
|
10
|
+
Provides-Extra: dev
|
|
11
|
+
Requires-Dist: pytest; extra == "dev"
|
|
12
|
+
Requires-Dist: pytest-mock; extra == "dev"
|
|
13
|
+
Requires-Dist: ruff; extra == "dev"
|
|
14
|
+
Requires-Dist: black; extra == "dev"
|
|
15
|
+
Requires-Dist: mypy; extra == "dev"
|
|
16
|
+
Requires-Dist: bandit; extra == "dev"
|
|
17
|
+
Requires-Dist: types-requests; extra == "dev"
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# python for DevOps: CI/CD for Python Projects
|
|
21
|
+
This repository contains the code to learn CI/CD for future projects implementation.
|
|
22
|
+
|
|
23
|
+
## What we implement in this repository
|
|
24
|
+
|
|
25
|
+
[x] Implement the project (code files)
|
|
26
|
+
[x] Add a simple GHA workflow and make sure it runs until completion
|
|
27
|
+
[x] Add linting (ruff) and format checks (black)
|
|
28
|
+
[x] Add typing (mypy) and security checks (bandit)
|
|
29
|
+
[x] Add test automation
|
|
30
|
+
[x] Build our Python project
|
|
31
|
+
[] Publish the project to both TestPyPI and PyPI when a new released is published
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
https_checker_simple-0.1.0.dist-info/licenses/LICENSE,sha256=jrik5olTywMYotM-YO4RJdHzOTaKXA54PVdveuxJ2c0,1071
|
|
2
|
+
simple_http_checker/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
simple_http_checker/checker.py,sha256=GZZHr1-xCDAFLNwgtSvzr1mPvX9huO20HkMzV67v0-g,1319
|
|
4
|
+
simple_http_checker/cli.py,sha256=2GikungxZLgiqNuJw9lTRqxwWAhVDGKOgiXWIox51Rk,1286
|
|
5
|
+
https_checker_simple-0.1.0.dist-info/METADATA,sha256=sulMHcXMF1Ko28ngffbE__VM74jI3cPmCt1ra2v3zmk,1106
|
|
6
|
+
https_checker_simple-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
7
|
+
https_checker_simple-0.1.0.dist-info/entry_points.txt,sha256=UF_7hQD8GGstiCxqZgH6XC6YbiUxh7ZDf5o8Wg0NhDE,60
|
|
8
|
+
https_checker_simple-0.1.0.dist-info/top_level.txt,sha256=Q2N-cYyXd23OQxUK_TdugtDVBHGsKaM2V2JOF5ygKtk,20
|
|
9
|
+
https_checker_simple-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nazareno Urday
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
simple_http_checker
|
|
File without changes
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from collections.abc import Collection
|
|
3
|
+
|
|
4
|
+
import requests
|
|
5
|
+
|
|
6
|
+
logger = logging.getLogger(__name__)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def check_urls(
|
|
10
|
+
urls: Collection[str], timeout: int = 5
|
|
11
|
+
) -> dict[str, str]:
|
|
12
|
+
logger.info(
|
|
13
|
+
f"Starting check for {len(urls)} URLs with a timeout of {timeout} seconds"
|
|
14
|
+
)
|
|
15
|
+
results: dict[str, str] = {}
|
|
16
|
+
|
|
17
|
+
for url in urls:
|
|
18
|
+
status = "UNKNOWN"
|
|
19
|
+
|
|
20
|
+
try:
|
|
21
|
+
logger.debug(f"Checking URL: {url}")
|
|
22
|
+
response = requests.get(url, timeout=timeout)
|
|
23
|
+
|
|
24
|
+
if response.ok:
|
|
25
|
+
status = f"{response.status_code} OK"
|
|
26
|
+
else:
|
|
27
|
+
status = f"{response.status_code}, [{response.reason}]"
|
|
28
|
+
|
|
29
|
+
except requests.exceptions.Timeout:
|
|
30
|
+
status = "TIMEOUT"
|
|
31
|
+
logger.warning(f"Request to {url} timed out")
|
|
32
|
+
|
|
33
|
+
except requests.exceptions.ConnectionError:
|
|
34
|
+
status = "CONNECTION ERROR"
|
|
35
|
+
logger.warning(f"Connection error for {url}")
|
|
36
|
+
|
|
37
|
+
except requests.exceptions.RequestException as error:
|
|
38
|
+
status = f"ERROR: {error}"
|
|
39
|
+
logger.error(
|
|
40
|
+
f"An unexpected error occurred while checking {url}"
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
results[url] = status
|
|
44
|
+
logger.debug(f"Checked URL: {url:<40} -> {status}")
|
|
45
|
+
|
|
46
|
+
logger.info("URL check finished")
|
|
47
|
+
return results
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from collections.abc import Collection
|
|
3
|
+
|
|
4
|
+
import click
|
|
5
|
+
|
|
6
|
+
from .checker import check_urls
|
|
7
|
+
|
|
8
|
+
logging.basicConfig(
|
|
9
|
+
level=logging.INFO,
|
|
10
|
+
format="[%(asctime)s] %(levelname)-8s %(name)s: %(message)s",
|
|
11
|
+
datefmt="%Y-%m-%d %H:%M:%S",
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
logger = logging.getLogger(__name__)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@click.command()
|
|
19
|
+
@click.argument("urls", nargs=-1)
|
|
20
|
+
@click.option("--timeout", default=5, help="Timeout in seconds")
|
|
21
|
+
@click.option(
|
|
22
|
+
"--verbose", "-v", is_flag=True, help="Enable debug logging."
|
|
23
|
+
)
|
|
24
|
+
def main(urls: Collection[str], timeout: int, verbose: bool):
|
|
25
|
+
if verbose:
|
|
26
|
+
logging.getLogger().setLevel(logging.DEBUG)
|
|
27
|
+
logger.debug("Verbose logging enabled")
|
|
28
|
+
|
|
29
|
+
logger.debug(f"Received URLs: {urls}")
|
|
30
|
+
logger.debug(f"Received timeout: {timeout}")
|
|
31
|
+
logger.debug(f"Received verbose: {verbose}")
|
|
32
|
+
|
|
33
|
+
if not urls:
|
|
34
|
+
logger.warning("No URLs provided")
|
|
35
|
+
click.echo("Usage: check-urls <URL1> <URL2> ...")
|
|
36
|
+
return
|
|
37
|
+
|
|
38
|
+
logger.info(f"Starting check for {len(urls)} URLs.")
|
|
39
|
+
|
|
40
|
+
results = check_urls(list(urls), timeout)
|
|
41
|
+
|
|
42
|
+
click.echo("\n---Results---")
|
|
43
|
+
|
|
44
|
+
for url, status in results.items():
|
|
45
|
+
|
|
46
|
+
if "OK" in status:
|
|
47
|
+
fg_color = "green"
|
|
48
|
+
|
|
49
|
+
else:
|
|
50
|
+
fg_color = "red"
|
|
51
|
+
|
|
52
|
+
click.secho(f"{url:<40} -> {status}", fg=fg_color)
|