Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def scan():
spec_path = settings["spec_path"]
try:
api_spec = load_config_file(spec_path)
except FileNotFoundError as e:
error_message = f"Could not find API spec file: {spec_path}. {str(e)}"
logger.error(error_message)
raise SystemExit(ExitCode.USAGE_ERROR)
except EmptyConfigFileError as e:
error_message = f"API spec file is empty. {str(e)}"
logger.error(error_message)
raise SystemExit(ExitCode.USAGE_ERROR)
except (yaml.YAMLError, FileFormatNotSupportedError) as e:
logger.error(e)
raise SystemExit(ExitCode.USAGE_ERROR)
try:
if API_KEY not in api_spec:
raise MissingMandatoryKeyError({API_KEY}, ROOT_SCOPE)
root_node = EndpointNode(api_spec[API_KEY])
results = root_node.run()
except (
def exit(self):
if self.errors:
sys.exit(ExitCode.TESTS_ERROR)
if self.failures:
sys.exit(ExitCode.TESTS_FAILED)
sys.exit(self.exit_code)
if API_KEY not in api_spec:
raise MissingMandatoryKeyError({API_KEY}, ROOT_SCOPE)
root_node = EndpointNode(api_spec[API_KEY])
results = root_node.run()
except (
InvalidKeyError,
MissingMandatoryKeyError,
KeyError,
InvalidPythonCodeError,
) as e:
error_message = "Error loading API spec."
error_message = "{} {}".format(error_message, str(e))
logger.error(error_message)
raise SystemExit(ExitCode.USAGE_ERROR)
try:
write_report(results)
except (BadConfigurationError, InvalidPythonCodeError) as e:
logger.error(e)
raise SystemExit(ExitCode.USAGE_ERROR)
session.exit()
def run(self):
for request in self._get_requests():
try:
yield request.run()
except Exception as e:
error_message = (
f"\nError to make request `{request.full_url_path}`. \n{str(e)}\n"
)
logger.error(error_message)
session.exit_code = ExitCode.REQUEST_ERROR
continue
def __init__(self):
self.successes = 0
self.failures = 0
self.errors = 0
self.exit_code = ExitCode.OK