CiscoDevNet / devnet-express-security-issues

Suggested changes to the content of the learning labs for Devnet Express for Security
0 stars 0 forks source link

ThreatGrid Code Needs Refactoring & Learning Lab Content Needs to be Updated #53

Open cmlccie opened 5 years ago

cmlccie commented 5 years ago

The scripts that were added after the last update (intro-threatgrid/maldomain.py and intro-threatgrid/mission/thgrid_mission.py) need consistency refactoring. They don't follow the code styling and structuring that were to be made consistent in the last refactoring effort.

Flake8 Report:

flake8 intro-threatgrid/                                                                        1651ms  Wed Sep 18 10:01:04 2019
intro-threatgrid/threatgrid_ioc_query.py:100:5: E265 block comment should start with '# '
intro-threatgrid/threatgrid_ioc_query.py:109:5: E265 block comment should start with '# '
intro-threatgrid/threatgrid_search_submissions.py:64:1: W293 blank line contains whitespace
intro-threatgrid/maldomain.py:26:1: F401 'json' imported but unused
intro-threatgrid/maldomain.py:28:1: F401 'datetime.datetime' imported but unused
intro-threatgrid/maldomain.py:28:1: F401 'datetime.timedelta' imported but unused
intro-threatgrid/maldomain.py:32:1: F401 'crayons.blue' imported but unused
intro-threatgrid/maldomain.py:32:1: F401 'crayons.green' imported but unused
intro-threatgrid/maldomain.py:32:1: F401 'crayons.white' imported but unused
intro-threatgrid/maldomain.py:47:80: E501 line too long (175 > 79 characters)
intro-threatgrid/maldomain.py:49:6: E211 whitespace before '('
intro-threatgrid/maldomain.py:49:17: W292 no newline at end of file
intro-threatgrid/mission/thgrid_mission.py:35:1: F401 'crayons.green' imported but unused
intro-threatgrid/mission/thgrid_mission.py:35:1: F401 'crayons.red' imported but unused
intro-threatgrid/mission/thgrid_mission.py:51:1: E402 module level import not at top of file
intro-threatgrid/mission/thgrid_mission.py:52:1: E402 module level import not at top of file
intro-threatgrid/mission/thgrid_mission.py:58:1: E265 block comment should start with '# '
intro-threatgrid/mission/thgrid_mission.py:60:1: E265 block comment should start with '# '
intro-threatgrid/mission/thgrid_mission.py:62:12: E225 missing whitespace around operator
intro-threatgrid/mission/thgrid_mission.py:63:1: E302 expected 2 blank lines, found 0
intro-threatgrid/mission/thgrid_mission.py:64:14: E211 whitespace before '('
intro-threatgrid/mission/thgrid_mission.py:82:5: E265 block comment should start with '# '
intro-threatgrid/mission/thgrid_mission.py:88:1: C901 'find_Obervables' is too complex (14)
intro-threatgrid/mission/thgrid_mission.py:91:5: E265 block comment should start with '# '
intro-threatgrid/mission/thgrid_mission.py:92:16: E711 comparison to None should be 'if cond is None:'
intro-threatgrid/mission/thgrid_mission.py:104:80: E501 line too long (82 > 79 characters)
intro-threatgrid/mission/thgrid_mission.py:110:12: E225 missing whitespace around operator
intro-threatgrid/mission/thgrid_mission.py:114:19: E225 missing whitespace around operator
intro-threatgrid/mission/thgrid_mission.py:119:22: E225 missing whitespace around operator
intro-threatgrid/mission/thgrid_mission.py:120:80: E501 line too long (135 > 79 characters)
intro-threatgrid/mission/thgrid_mission.py:125:5: E265 block comment should start with '# '
intro-threatgrid/mission/thgrid_mission.py:128:80: E501 line too long (84 > 79 characters)
intro-threatgrid/mission/thgrid_mission.py:140:1: E302 expected 2 blank lines, found 1
intro-threatgrid/mission/thgrid_mission.py:142:15: E711 comparison to None should be 'if cond is None:'
intro-threatgrid/mission/thgrid_mission.py:142:15: E225 missing whitespace around operator
intro-threatgrid/mission/thgrid_mission.py:151:1: E303 too many blank lines (3)
intro-threatgrid/mission/thgrid_mission.py:157:5: E265 block comment should start with '# '
intro-threatgrid/mission/thgrid_mission.py:157:80: E501 line too long (95 > 79 characters)
intro-threatgrid/mission/thgrid_mission.py:160:5: E265 block comment should start with '# '
intro-threatgrid/mission/thgrid_mission.py:166:5: E265 block comment should start with '# '
intro-threatgrid/mission/thgrid_mission.py:166:80: E501 line too long (97 > 79 characters)
intro-threatgrid/mission/thgrid_mission.py:176:80: E501 line too long (102 > 79 characters)

Also, the last code refactoring updates haven't made it through to the lab instructions which still reference the old scripts:

2019-09-18_10-04-16
cmlccie commented 5 years ago

Additionally... the mixed snake-case/upper-camel-case functions naming isn't good, recommended names would be as follows:

readIocsFile() --> read_ioc_file()
get_FromThreatGrid() --> get_from_threat_grid()
find_Obervables() --> find_observables()
writer_file() --> write_file()
cmlccie commented 5 years ago

There are also bugs in the mission code, like attempting to import env_lab before the path system path has been updated (sys.path.insert(0, str(repository_root))) to enable python to locate the python files in the repository root.

...and why are we updating the path twice?

sys.path.insert(0, str(repository_root))

sys.path.insert(0, str(repository_root))