Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
scripts.set_output_level(options)
# Validate input documents
results = scripts.run_validation(options)
# Print validation results
scripts.print_results(results, options)
# Determine exit status code and exit.
code = scripts.status_code(results)
sys.exit(code)
except scripts.ArgumentError as ex:
if ex.show_help:
parser.print_help()
scripts.error(ex)
except (errors.ValidationError, IOError) as ex:
scripts.error(
"Validation error occurred: '%s'" % str(ex),
codes.EXIT_VALIDATION_ERROR
)
except Exception:
logging.exception("Fatal error occurred")
sys.exit(codes.EXIT_FAILURE)
# Validate input documents
results = scripts.run_validation(options)
# Print validation results
scripts.print_results(results, options)
# Determine exit status code and exit.
code = scripts.status_code(results)
sys.exit(code)
except scripts.ArgumentError as ex:
if ex.show_help:
parser.print_help()
scripts.error(ex)
except (errors.ValidationError, IOError) as ex:
scripts.error(
"Validation error occurred: '%s'" % str(ex),
codes.EXIT_VALIDATION_ERROR
)
except Exception:
logging.exception("Fatal error occurred")
sys.exit(codes.EXIT_FAILURE)
try:
# Assume valid XML, prep profile for conversion
options = scripts.ValidationOptions()
options.in_profile = args.profile
# Convert the profile
_convert_profile(options)
# If no exception was thrown, then conversion was successful.
sys.exit(codes.EXIT_SUCCESS)
except scripts.ArgumentError as ex:
if ex.show_help:
parser.print_help()
scripts.error(ex)
except Exception:
logging.exception("Fatal error occurred")
sys.exit(codes.EXIT_FAILURE)
# Validate input documents
results = scripts.run_validation(options)
# Print validation results
scripts.print_results(results, options)
# Determine exit status code and exit.
code = scripts.status_code(results)
sys.exit(code)
except scripts.ArgumentError as ex:
if ex.show_help:
parser.print_help()
scripts.error(ex)
except (errors.ValidationError, IOError) as ex:
scripts.error(
"Validation error occurred: '%s'" % str(ex),
codes.EXIT_VALIDATION_ERROR
)
except Exception:
logging.exception("Fatal error occurred")
sys.exit(codes.EXIT_FAILURE)
xml = stix_package.to_xml(encoding=None)
validator_options.in_files = io.StringIO(xml)
try:
scripts.set_output_level(validator_options)
validation_results = scripts.validate_file(
validator_options.in_files,
validator_options
)
results = {stix_package.id_: validation_results}
# Print stix-validator results
scripts.print_results(results, validator_options)
except (errors.ValidationError, IOError) as ex:
scripts.error(
"Validation error occurred: '%s'" % str(ex),
codes.EXIT_VALIDATION_ERROR
)
except Exception:
log.exception("Fatal error occurred", extra={'ecode': 0})
sys.exit(codes.EXIT_FAILURE)
return xml
xml = stix_package.to_xml(encoding=None)
validator_options.in_files = io.StringIO(xml)
try:
scripts.set_output_level(validator_options)
validation_results = scripts.validate_file(
validator_options.in_files,
validator_options
)
results = {stix_package.id_: validation_results}
# Print stix-validator results
scripts.print_results(results, validator_options)
except (errors.ValidationError, IOError) as ex:
scripts.error(
"Validation error occurred: '%s'" % str(ex),
codes.EXIT_VALIDATION_ERROR
)
except Exception:
log.exception("Fatal error occurred", extra={'ecode': 0})
sys.exit(codes.EXIT_FAILURE)
return xml