Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
from cli.bin.airgap import download_scripts, download_compliance_scripts, upload_scripts, upload_compliance_scripts
from cbw_cli.bin.airgap import download_scripts, download_compliance_scripts, upload_scripts, upload_compliance_scripts

def help():
print("Usage : cyberwatch-cli airgap [COMMAND] [ARGS]")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from os.path import abspath, join
import os
from cli.bin import os as cbw_os
from cbw_cli.bin import os as cbw_os
import argparse
import sys
import shutil
Expand Down
File renamed without changes.
File renamed without changes.
90 changes: 90 additions & 0 deletions cbw_cli/cyberwatch_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env python

from cyberwatch_api import Cyberwatch_Pyhelper
import sys
from cbw_cli.bin import os, airgap
import requests
from urllib3.exceptions import InsecureRequestWarning

# Disable certificate check warnings
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)

def help():
print("Usage : cyberwatch-cli [OPTIONS] [COMMAND] [ARGS]")
print("---")
print("Cli to interact with Cyberwatch API.\n")
print("\n")
print("\t{: <15} \t {}".format("OPTIONS", "DESCRIPTION"))
print("\t{: <15} \t {}".format("---", "---"))
print("\t{: <15} \t {}".format("--verify-ssl", "Using this options, SSL verification will be done"))
print("\t{: <15} \t {}".format("--api-url", "Set the URL of the Cyberwatch API"))
print("\t{: <15} \t {}".format("--api-key", "Set the KEY of the Cyberwatch API"))
print("\t{: <15} \t {}".format("--api-secret", "Set the SECRET KEY of the Cyberwatch API"))
print("\n")
print("{: >15} \t {}".format("COMMAND", "DESCRIPTION"))
print("{: >15} \t {}".format("---", "---"))
print("{: >15} \t {}".format("os", "Manage cyberwatch operating systems"))
print("{: >15} \t {}".format("airgap", "Interact with the airgap interface"))
print("{: >15} \t {}".format("ping", "Ping the Cyberwatch API to validate the connexion"))
print("\n")

def ping(CBW_API, verify_ssl=False, verbose=False):
apiResponse = CBW_API.request(
method="GET",
endpoint="/api/v3/ping",
verify_ssl=verify_ssl
)
if verbose:
print("Trying to ping Cyberwatch API...")
response = next(apiResponse).json()
if verbose:
print(response)
if response.get("error") is not None:
print("Failed ping to Cyberwatch API, exiting...")
sys.exit(1)

def main():
arguments = sys.argv[1:]

try:
# Check if we should verify the SSL Certificate
VERIFY_SSL = False
if "--verify-ssl" in arguments:
VERIFY_SSL = True
arguments.remove("--verify-ssl")

# Initializing API Client
try:
# Parsing API DATA if specified in command line
API_DATA = [None, None, None]
for index, data in enumerate(["--api-url", "--api-key", "--api-secret"]):
if data in arguments and len(arguments) > arguments.index(data) + 1:
API_DATA[index] = arguments[arguments.index(data) + 1]
arguments.remove(data)
arguments.remove(API_DATA[index])
# Creating API Client
CBW_API = Cyberwatch_Pyhelper(api_url = API_DATA[0], api_key = API_DATA[1], api_secret = API_DATA[2])
except Exception as e: # Catching error raised by API Client if not api data is found (via arguments, api.conf or environnement variables)
help()
print("[-] ERROR : " + str(e))
sys.exit(1)

if not arguments or arguments[0] == "help":
help()
elif arguments[0] == "ping":
ping(CBW_API, VERIFY_SSL, True)
elif arguments[0] == "os":
ping(CBW_API, VERIFY_SSL)
os.manager(arguments[1:], CBW_API, VERIFY_SSL)
elif arguments[0] == "airgap":
ping(CBW_API, VERIFY_SSL)
airgap.manager(arguments[1:], CBW_API, VERIFY_SSL)
else:
print("ERROR : '" + str(arguments[0]) + "' is not a valid command\n---", file=sys.stderr)
help()
except Exception as exception:
print(exception)
sys.exit(1)

if __name__ == "__main__":
main()
84 changes: 0 additions & 84 deletions cli/cyberwatch-cli

This file was deleted.

26 changes: 26 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
[build-system]
requires = ["setuptools>=61.0", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "cyberwatch_api"
version = "0.3.2"
description = "Python Api client for the Cyberwatch software"
readme = "README.md"
license = "MIT"
authors = [{name = "CyberWatch SAS"}]
requires-python = ">=3.6"
dependencies = [
"requests>=2.20.1",
"chardet"
]

[project.scripts]
cyberwatch-cli = "cbw_cli.cyberwatch_cli:main"

[tool.setuptools]
py-modules = ["cyberwatch_api"]

[tool.setuptools.packages.find]
include = ["cbw_cli*", "*"]

[tool.ruff]
line-length = 120
18 changes: 0 additions & 18 deletions setup.py

This file was deleted.