Skip to content

Commit b09aec5

Browse files
committed
chore: address lint problems
1 parent 987ea42 commit b09aec5

29 files changed

Lines changed: 489 additions & 55 deletions

docs/conf.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
# Configuration file for the Sphinx documentation builder.
2-
# For the full list of built-in configuration values, see the documentation:
3-
# https://www.sphinx-doc.org/en/master/usage/configuration.html
1+
"""
2+
Configuration file for the Sphinx documentation builder.
3+
4+
For the full list of built-in configuration values, see the documentation:
5+
https://www.sphinx-doc.org/en/master/usage/configuration.html
6+
"""
47

58
import os
69
import sys

mitreattack/__init__.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1-
from .attackToExcel import *
2-
from .collections import *
3-
from .navlayers import *
1+
# from .attackToExcel import *
2+
# from .collections import *
3+
# from .navlayers import *
4+
5+
from . import attackToExcel, collections, navlayers
6+
7+
__all__ = [
8+
"attackToExcel",
9+
"collections",
10+
"navlayers",
11+
]

mitreattack/attackToExcel/stixToDf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -842,15 +842,15 @@ def matricesToDf(src, domain):
842842
for column in matrix_grid:
843843
longest_column = max(len(column), longest_column)
844844
for column in matrix_grid:
845-
for i in range((longest_column - len(column))):
845+
for _ in range((longest_column - len(column))):
846846
column.append("")
847847

848848
for submatrix in sub_matrices_grid:
849849
mg = sub_matrices_grid[submatrix]
850850
for column in mg:
851851
longest_column = max(len(column), longest_column)
852852
for column in mg:
853-
for i in range((longest_column - len(column))):
853+
for _ in range((longest_column - len(column))):
854854
column.append("")
855855
# matrix is now squared
856856

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
from .collection_to_index import *
2-
from .index_to_markdown import *
1+
from .collection_to_index import CollectionToIndex
2+
from .index_to_markdown import IndexToMarkdown
3+
4+
__all__ = [
5+
"CollectionToIndex",
6+
"IndexToMarkdown",
7+
]

mitreattack/diffStix/changelog_helper.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class AttackObjectVersion:
4444
minor: int
4545

4646
def __repr__(self):
47+
"""Return a string representation of the ATT&CK object version."""
4748
return f"{self.major}.{self.minor}"
4849

4950

@@ -65,7 +66,7 @@ class DiffStix(object):
6566

6667
def __init__(
6768
self,
68-
domains: List[str] = ["enterprise-attack", "mobile-attack", "ics-attack"],
69+
domains: Optional[List[str]] = None,
6970
layers: Optional[List[str]] = None,
7071
unchanged: bool = False,
7172
old: Optional[str] = "old",
@@ -101,6 +102,8 @@ def __init__(
101102
include_contributors : bool, optional
102103
Include contributor information for new contributors, by default False
103104
"""
105+
if domains is None:
106+
domains = ["enterprise-attack", "mobile-attack", "ics-attack"]
104107
self.domains = domains
105108
self.layers = layers
106109
self.unchanged = unchanged
@@ -2024,7 +2027,7 @@ def get_parsed_args():
20242027

20252028

20262029
def get_new_changelog_md(
2027-
domains: List[str] = ["enterprise-attack", "mobile-attack", "ics-attack"],
2030+
domains: Optional[List[str]] = None,
20282031
layers: List[str] = layer_defaults,
20292032
unchanged: bool = False,
20302033
old: Optional[str] = None,
@@ -2080,6 +2083,8 @@ def get_new_changelog_md(
20802083
A Markdown string representation of differences between two ATT&CK versions.
20812084
"""
20822085
# the default loguru logger logs up to Debug by default
2086+
if domains is None:
2087+
domains = ["enterprise-attack", "mobile-attack", "ics-attack"]
20832088
logger.remove()
20842089
if verbose:
20852090
logger.add(lambda msg: tqdm.write(msg, end=""), colorize=True)

mitreattack/navlayers/__init__.py

Lines changed: 97 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,97 @@
1-
from .core import *
2-
from .exporters import *
3-
from .generators import *
4-
from .manipulators import *
1+
from .core import (
2+
UNSETVALUE,
3+
BadInput,
4+
BadType,
5+
Filter,
6+
Gradient,
7+
Layer,
8+
Layout,
9+
LegendItem,
10+
Link,
11+
LinkDiv,
12+
Metadata,
13+
MetaDiv,
14+
MissingParameters,
15+
Technique,
16+
UninitializedLayer,
17+
UnknownLayerProperty,
18+
UnknownTechniqueProperty,
19+
Versions,
20+
_LayerObj,
21+
categoryChecker,
22+
handle_object_placement,
23+
handler,
24+
loadChecker,
25+
typeChecker,
26+
typeCheckerArray,
27+
)
28+
from .exporters import (
29+
ExcelTemplates,
30+
MatrixGen,
31+
SVGConfig,
32+
SvgTemplates,
33+
ToExcel,
34+
ToSvg,
35+
)
36+
from .generators import (
37+
OverviewLayerGenerator,
38+
UsageLayerGenerator,
39+
build_data_strings,
40+
construct_relationship_mapping,
41+
get_attack_id,
42+
remove_revoked_depreciated,
43+
)
44+
from .manipulators import (
45+
BadLambda,
46+
InvalidFormat,
47+
LayerOps,
48+
MismatchedDomain,
49+
)
50+
51+
__all__ = [
52+
# core
53+
"UNSETVALUE",
54+
"BadInput",
55+
"BadType",
56+
"UninitializedLayer",
57+
"UnknownLayerProperty",
58+
"UnknownTechniqueProperty",
59+
"MissingParameters",
60+
"handler",
61+
"typeChecker",
62+
"typeCheckerArray",
63+
"categoryChecker",
64+
"loadChecker",
65+
"Filter",
66+
"Gradient",
67+
"handle_object_placement",
68+
"Layer",
69+
"_LayerObj",
70+
"Layout",
71+
"LegendItem",
72+
"Metadata",
73+
"MetaDiv",
74+
"Link",
75+
"LinkDiv",
76+
"Technique",
77+
"Versions",
78+
# exporters
79+
"ExcelTemplates",
80+
"MatrixGen",
81+
"SvgTemplates",
82+
"ToExcel",
83+
"SVGConfig",
84+
"ToSvg",
85+
# generators
86+
"remove_revoked_depreciated",
87+
"construct_relationship_mapping",
88+
"get_attack_id",
89+
"build_data_strings",
90+
"OverviewLayerGenerator",
91+
"UsageLayerGenerator",
92+
# manipulators
93+
"LayerOps",
94+
"InvalidFormat",
95+
"BadLambda",
96+
"MismatchedDomain",
97+
]
Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1-
from .exceptions import *
1+
from .exceptions import (
2+
UNSETVALUE,
3+
BadInput,
4+
BadType,
5+
MissingParameters,
6+
UninitializedLayer,
7+
UnknownLayerProperty,
8+
UnknownTechniqueProperty,
9+
categoryChecker,
10+
handler,
11+
loadChecker,
12+
typeChecker,
13+
typeCheckerArray,
14+
)
215
from .filter import Filter
316
from .gradient import Gradient
4-
from .helpers import *
17+
from .helpers import handle_object_placement
518
from .layer import Layer
619
from .layerobj import _LayerObj
720
from .layout import Layout
@@ -10,3 +23,31 @@
1023
from .objlink import Link, LinkDiv
1124
from .technique import Technique
1225
from .versions import Versions
26+
27+
__all__ = [
28+
"UNSETVALUE",
29+
"BadInput",
30+
"BadType",
31+
"UninitializedLayer",
32+
"UnknownLayerProperty",
33+
"UnknownTechniqueProperty",
34+
"MissingParameters",
35+
"handler",
36+
"typeChecker",
37+
"typeCheckerArray",
38+
"categoryChecker",
39+
"loadChecker",
40+
"Filter",
41+
"Gradient",
42+
"handle_object_placement",
43+
"Layer",
44+
"_LayerObj",
45+
"Layout",
46+
"LegendItem",
47+
"Metadata",
48+
"MetaDiv",
49+
"Link",
50+
"LinkDiv",
51+
"Technique",
52+
"Versions",
53+
]

mitreattack/navlayers/core/layer.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
class Layer:
1111
"""A Layer object."""
1212

13-
def __init__(self, init_data={}, name=None, domain=None, strict=True):
13+
def __init__(self, init_data=None, name=None, domain=None, strict=True):
1414
"""Initialize - create a new Layer object.
1515
1616
:param init_data: Optionally provide base Layer json or string data on initialization
1717
"""
18+
if init_data is None:
19+
init_data = {}
1820
self.__layer = None
1921
self.strict = strict
2022
if isinstance(name, str) and isinstance(domain, str):
@@ -65,7 +67,7 @@ def from_file(self, filename):
6567
with open(filename, "r", encoding="utf-16") as fio:
6668
try:
6769
raw = fio.read()
68-
except UnicodeError or UnicodeDecodeError:
70+
except (UnicodeError, UnicodeDecodeError):
6971
fallback = True
7072
if fallback:
7173
with open(filename, "r") as fio:
@@ -88,7 +90,7 @@ def _build(self):
8890
"""Load the data stored in self.data into a LayerObj (self.layer)."""
8991
try:
9092
self.__layer = _LayerObj(self.__data["name"], self.__data["domain"])
91-
except BadType or BadInput as e:
93+
except (BadType, BadInput) as e:
9294
handler(type(self).__name__, f"Layer is malformed: {e}. Unable to load.")
9395
self.__layer = None
9496
return

mitreattack/navlayers/exporters/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,12 @@
33
from .svg_templates import SvgTemplates
44
from .to_excel import ToExcel
55
from .to_svg import SVGConfig, ToSvg
6+
7+
__all__ = [
8+
"ExcelTemplates",
9+
"MatrixGen",
10+
"SvgTemplates",
11+
"ToExcel",
12+
"SVGConfig",
13+
"ToSvg",
14+
]

mitreattack/navlayers/exporters/excel_templates.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(self, source="local", resource=None, domain="enterprise"):
3434
else:
3535
raise BadTemplateException
3636

37-
def _build_raw(self, showName=True, showID=False, sort=0, scores=[], subtechs=[], exclude=[]):
37+
def _build_raw(self, showName=True, showID=False, sort=0, scores=None, subtechs=None, exclude=None):
3838
"""Build a raw, not-yet-marked-up excel document based on the specifications.
3939
4040
:param showName: Whether or not to display names for each entry
@@ -44,6 +44,12 @@ def _build_raw(self, showName=True, showID=False, sort=0, scores=[], subtechs=[]
4444
:param exclude: List of of techniques to exclude from the matrix
4545
:return: a openpyxl workbook object containing the raw matrix
4646
"""
47+
if scores is None:
48+
scores = []
49+
if subtechs is None:
50+
subtechs = []
51+
if exclude is None:
52+
exclude = []
4753
self.codex = self.h._adjust_ordering(self.codex, sort, scores)
4854
template, joins = self.h._construct_panop(self.codex, subtechs, exclude)
4955
self.template = template
@@ -107,7 +113,7 @@ def _build_raw(self, showName=True, showID=False, sort=0, scores=[], subtechs=[]
107113

108114
return wb
109115

110-
def export(self, showName, showID, filters=None, sort=0, scores=[], subtechs=[], exclude=[]):
116+
def export(self, showName, showID, filters=None, sort=0, scores=None, subtechs=None, exclude=None):
111117
"""Export a raw customized excel template.
112118
113119
:param showName: Whether or not to display names for each entry
@@ -119,6 +125,12 @@ def export(self, showName, showID, filters=None, sort=0, scores=[], subtechs=[],
119125
:param exclude: List of of techniques to exclude from the matrix
120126
return: a openpyxl workbook object containing the raw matrix
121127
"""
128+
if scores is None:
129+
scores = []
130+
if subtechs is None:
131+
subtechs = []
132+
if exclude is None:
133+
exclude = []
122134
self.codex = self.h.get_matrix(self.mode, filters=filters)
123135
return self._build_raw(showName, showID, sort, scores, subtechs, exclude)
124136

0 commit comments

Comments
 (0)