Skip to content
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

Some structure for the simple STIX to MISP filter - mainly cosmetics :-) #27

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

sthagen
Copy link

@sthagen sthagen commented Dec 8, 2017

Just a first communication attempt - hi :-)

Did not setup a travis / CI chain for the fork ... but maybe you guys find it helpful.

@coveralls
Copy link

coveralls commented Dec 8, 2017

Coverage Status

Coverage decreased (-0.6%) to 46.777% when pulling decd3e4 on sdrees:for-starters-converter-cosmetics into 8ebdb3d on MISP:master.

Copy link
Member

@FloatingGhost FloatingGhost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.

There are quite a few unnecessary stylistic changes here that go against the rest of the project, I won't be accepting on those grounds.

I like to keep a script as being a script - you should be able to read it like, well, a (theatrical) script, top to bottom. This jumps around a lot. Whilst in practice they execute the same, I personally can't stand it.

MISP_CONFIG_KEY = "MISP"
SSL_CONFIG_KEY = "SSL"
BLAST_FROM_PAST_PENALTY_SECS = 1.0
args_src = sys.argv
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean... for what reason?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the filename is bad for testing, as you cannot import it with the hyphens without tricks, but at least offer some testability, where you could import the "script" as module, and depending on test idea, overwrite the args_src module level var and call main with the list (you can always use unittest.mock, but ... or one can directly call parse_args(["some", "list"]) at least with the fix I echo pushed (because I forgot to inject into the parser.parse_args call.

log.info("Pushing to MISP...")
MISP.push(pkg)
log.info("COMPLETE")
if __name__ == '__main__':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an executable.

The only time we'd ever run this is when __name__ is "main".
Check not needed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, but the coverage is so "low" (of that project) and coveralls even suggested that by adding lines, this has lowered the coverage, so having a shield against exec might come in handy, when executing tests, that import the file content as module ...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... of course the sys.exit(main)was not my brightest idea, but there came a new commit amending the branch (I generated this before reading the above comments).

CONFIG_DEFAULT_PATH = "~/.misptostix/misp.login"
MISP_CONFIG_KEY = "MISP"
SSL_CONFIG_KEY = "SSL"
BLAST_FROM_PAST_PENALTY_SECS = 1.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tells you absolutely nothing about what its actually used for

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, just a suggestion to un-lit(t)er(al) the code, replaced only multiple copies of string literals or that funky 1 as time.sleep argument with the reverse guessed meaning. The config path with the tilde that requires expand user pre-action for usable open file path creation, directly came from my fingers ...

from misp_stix_converter.converters.convert import load_stix
from misp_stix_converter.servers import misp

LOGGER_FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda for lines 15-20

If they're constants, why bother defining them beforehand when they can be passed straight to a function without adding more lines?

It executes the same but still, seems unneeded

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is of course individual perception, but in my experience, complexity is not in the number of lines. A logger format is some public interface, and might ease adaption and use, if made visible on module level.

# TO MISP #
##########################

"""Wrapper script providing STIX to MISP conversion. """
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change this?

It's consistent throughout the project.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, interesting, newbie from planet python - thought that one liner would convey more meaning and suit pep8

MISP.push(pkg)
log.info("COMPLETE")
if __name__ == '__main__':
sys.exit(main)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config[MISP_CONFIG_KEY]["KEY"],
config[MISP_CONFIG_KEY].get(SSL_CONFIG_KEY, True)
)
planet_misp = misp.MISP(*misp_args)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This genuinely makes less sense now

f("a", "b", "c")

is understood more quickly than

x = ["a", "b", "c"]
f(*x)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it is just an offering, but I was first irritated by the "defensive" get on the SSL key lookup nearly hidden as third argument, so to me that made it more clear (also as the default of get is explicitly given). That is in your sampl, it would be a more complicated "c"

return log


def parse_args(args):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

argparse does not need to be passed sys.argv

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cf. above, but it profits for test from receiving an explicit list ...

@coveralls
Copy link

coveralls commented Dec 8, 2017

Coverage Status

Coverage decreased (-0.6%) to 46.777% when pulling 820f3ec on sdrees:for-starters-converter-cosmetics into 8ebdb3d on MISP:master.

…Hashes as some hash algos require additional length
@coveralls
Copy link

coveralls commented Dec 8, 2017

Coverage Status

Coverage increased (+1.4%) to 48.806% when pulling 93b5b6d on sdrees:for-starters-converter-cosmetics into 8ebdb3d on MISP:master.

@coveralls
Copy link

coveralls commented Dec 9, 2017

Coverage Status

Coverage increased (+1.4%) to 48.806% when pulling 7e2852f on sdrees:for-starters-converter-cosmetics into 8ebdb3d on MISP:master.

@sthagen
Copy link
Author

sthagen commented Dec 14, 2017

@FloatingGhost - I think the latest changes accommodate to your review change requests. If not please indicate to me, only if you have time, of course. Thanks.

@Rafiot
Copy link
Member

Rafiot commented Dec 21, 2017

@FloatingGhost are you cool with the changes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants