PyVulnerabilityLookup/pyvulnerabilitylookup/__init__.py

34 lines
1,009 B
Python
Raw Normal View History

2024-01-17 11:41:24 +00:00
from __future__ import annotations
2023-05-19 13:21:11 +00:00
import argparse
import json
import sys
2024-01-17 11:41:24 +00:00
from typing import Any
2023-05-19 13:21:11 +00:00
from .api import PyVulnerabilityLookup
2024-01-17 11:41:24 +00:00
__all__ = ['PyVulnerabilityLookup']
2023-05-19 13:21:11 +00:00
2024-01-17 11:41:24 +00:00
def main() -> None:
2023-05-19 13:21:11 +00:00
parser = argparse.ArgumentParser(description='Query a thing.')
parser.add_argument('--url', type=str, required=True, help='URL of the instance.')
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('--redis_up', action='store_true', help='Check if redis is up.')
group.add_argument('--vulnerability', type=str, help='Get a vulnerability.')
args = parser.parse_args()
client = PyVulnerabilityLookup(args.url)
2024-01-17 11:41:24 +00:00
response: bool | dict[str, Any]
2023-05-19 13:21:11 +00:00
if not client.is_up:
print(f'Unable to reach {client.root_url}. Is the server up?')
sys.exit(1)
if args.redis_up:
response = client.redis_up()
elif args.vulnerability:
response = client.get_vulnerability(args.vulnerability)
print(json.dumps(response, indent=2))