Skip to content

Commit

Permalink
Merge pull request #111 from oasis-open/final_push
Browse files Browse the repository at this point in the history
Final push
  • Loading branch information
gtback authored Jun 15, 2018
2 parents e3187d6 + 98805bf commit 5700eb5
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 16 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
CHANGELOG
=========

1.1.3 - 2018-06-08

* Fix old links for Pypi in documentation
* When running development scripts, use a higher recursion limit
* When testing - if a difference was found find the location
* Rrun validator all the time, not just when the policy is strict
* Fix extension properties and type names - they need to use -, not _ and in patterns extension properties names should be quoted if they contain a -
* Make sure external references had a source name, even if you use 'unknown'


1.1.2 - 2018-06-01

* Create read-the-docs pages
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_version():
install_requires=[
'pycountry>=1.17.8',
'stix>=1.1.1.9,<1.2.1.0',
'stix2-validator>=0.1.0',
'stix2-validator>=1.0.1',
'stixmarx>=1.0.3',
'six>=1.10.0',
'stix2'
Expand Down
30 changes: 24 additions & 6 deletions stix2elevator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
import logging

import cybox.utils.caches
from six import StringIO
from six import StringIO, binary_type
from stix2validator import ValidationError, codes, output, validate_string
from stix2validator.validator import FileValidationResults
from stix.core import STIXPackage
import stixmarx

Expand All @@ -20,6 +21,16 @@
log = logging.getLogger(__name__)


def validate_stix2_string(json_string, validator_options, file_path=None):
# Ensure the json_string is a Unicode text string. json.dumps() sometimes
# returns a byte-"str" on Python 2.
if isinstance(json_string, binary_type):
json_string = json_string.decode("utf-8")
results = validate_string(json_string, validator_options)
fvr = FileValidationResults(results.is_valid, file_path, results)
return [fvr]


def elevate_file(fn):
# TODO: combine elevate_file, elevate_string and elevate_package
global MESSAGES_GENERATED
Expand Down Expand Up @@ -50,11 +61,12 @@ def elevate_file(fn):
json_string = json.dumps(convert_package(stix_package,
get_option_value("package_created_by_id"),
get_option_value("default_timestamp")),
ensure_ascii=False,
indent=4,
separators=(',', ': '),
sort_keys=True)

validation_results = validate_string(json_string, validator_options)
validation_results = validate_stix2_string(json_string, validator_options, fn)
output.print_results(validation_results)

if get_option_value("policy") == "no_policy":
Expand Down Expand Up @@ -101,15 +113,18 @@ def elevate_string(string):
json_string = json.dumps(convert_package(stix_package,
get_option_value("package_created_by_id"),
get_option_value("default_timestamp")),
ensure_ascii=False,
indent=4,
separators=(',', ': '),
sort_keys=True)

validation_results = validate_stix2_string(json_string, validator_options)
output.print_results(validation_results)

if get_option_value("policy") == "no_policy":
return json_string
else:
validation_results = validate_string(json_string, validator_options)
output.print_results(validation_results)

if not MESSAGES_GENERATED and validation_results._is_valid:
return json_string
else:
Expand Down Expand Up @@ -151,14 +166,17 @@ def elevate_package(package):
json_string = json.dumps(convert_package(stix_package,
get_option_value("package_created_by_id"),
get_option_value("default_timestamp")),
ensure_ascii=False,
indent=4,
separators=(',', ': '),
sort_keys=True)

validation_results = validate_stix2_string(json_string, validator_options)
output.print_results(validation_results)

if get_option_value("policy") == "no_policy":
return json_string
else:
validation_results = validate_string(json_string, validator_options)
output.print_results(validation_results)
if not MESSAGES_GENERATED and validation_results._is_valid:
return json_string
else:
Expand Down
11 changes: 3 additions & 8 deletions stix2elevator/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import shlex

from six import text_type
from stix2validator import ValidationOptions
from stix2validator.scripts import stix2_validator

ALL_OPTIONS = None
Expand All @@ -19,6 +18,8 @@

# Module-level logger
log = logging.getLogger(__name__)
# temporary? hack to prevent multiple loggers from printing messages
log.propagate = False
log.addHandler(ch)

MESSAGES_GENERATED = False
Expand Down Expand Up @@ -202,13 +203,7 @@ def initialize_options(elevator_args=None):
def get_validator_options():
if ALL_OPTIONS:
"""Return a stix2validator.validators.ValidationOptions instance."""
# Parse stix-validator command-line args
validator_parser = stix2_validator._get_arg_parser(is_script=False)
validator_args = validator_parser.parse_args(
shlex.split(get_option_value("validator_args")))

validator_args.files = None
return ValidationOptions(validator_args)
return stix2_validator.parse_args(shlex.split(get_option_value("validator_args")))


def get_option_value(option_name):
Expand Down
2 changes: 1 addition & 1 deletion stix2elevator/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.1.2"
__version__ = "1.1.3"

0 comments on commit 5700eb5

Please sign in to comment.