-
Notifications
You must be signed in to change notification settings - Fork 186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multi threat libs #263
base: master
Are you sure you want to change the base?
Multi threat libs #263
Conversation
@@ -1405,5 +1405,5 @@ | |||
"name": "my test tm", | |||
"onDuplicates": "Action.NO_ACTION", | |||
"threatsExcluded": [], | |||
"threatsFile": "pytm/threatlib/threats.json" | |||
"threatsFile": "{'pytm/threatlib/threats.json'}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the output a string and not a list of strings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's what varStrings with only one value put out...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a bug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the immortal words of just about everybody..."works for me"!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I had a quick look and the issue is that the default to_serializable
is used.
Lines 2015 to 2018 in 9dc0f1f
@singledispatch | |
def to_serializable(val): | |
"""Used by default.""" | |
return str(val) |
This is just the same as
json.dumps(str(set(["./a.json"])))
The issue is created by
Line 2023 in 9dc0f1f
return serialize(obj, nested=True) |
Because of this check for not nested
in serialize()
.
Line 2064 in 9dc0f1f
not nested |
Lines 2035 to 2070 in 9dc0f1f
def serialize(obj, nested=False): | |
"""Used if *obj* is an instance of TM, Element, Threat or Finding.""" | |
klass = obj.__class__ | |
result = {} | |
if isinstance(obj, (Actor, Asset)): | |
result["__class__"] = klass.__name__ | |
for i in dir(obj): | |
if ( | |
i.startswith("__") | |
or callable(getattr(klass, i, {})) | |
or ( | |
isinstance(obj, TM) | |
and i in ("_sf", "_duplicate_ignored_attrs", "_threats") | |
) | |
or (isinstance(obj, Element) and i in ("_is_drawn", "uuid")) | |
or (isinstance(obj, Finding) and i == "element") | |
): | |
continue | |
value = getattr(obj, i) | |
if isinstance(obj, TM) and i == "_elements": | |
value = [e for e in value if isinstance(e, (Actor, Asset))] | |
if value is not None: | |
if isinstance(value, (Element, Data)): | |
value = value.name | |
elif isinstance(obj, Threat) and i == "target": | |
value = [v.__name__ for v in value] | |
elif i in ("levels", "sourceFiles", "assumptions"): | |
value = list(value) | |
elif ( | |
not nested | |
and not isinstance(value, str) | |
and isinstance(value, Iterable) | |
): | |
value = [v.id if isinstance(v, Finding) else v.name for v in value] | |
result[i.lstrip("_")] = value | |
return result |
This whole serialize function is a bit overloaded with special handling of member variables and might require a rewrite.
All the checks seem to be for specific classes which are all handle in the same function.
Also why is there the check for nested
?
This is basically equivalent to checking if the class is TM
.
A quick fix would be something like if instance(obj, TM) and i == "threatsFile"
but oh boy that is not nice.
Should this be a new issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds like something to be addressed. @nineinchnick , you there?
Adds capability to select which threat lib to use on the command line: