The LayerOps class allows you to automate the combination of multiple ATT&CK Navigator layers using user-defined lambda functions. This is useful for merging scores, comments, or metadata across different layers.
Workflow
- Initialize: Create a
LayerOps instance by passing lambda functions for the fields you want to combine (e.g., score, comment, name, colors, metadata, desc). - Process: Call the
.process() method, passing in a list or a dictionary of Layer objects. The method applies your lambdas to the provided data to produce a new, combined Layer object.
Initialization Parameters
score, comment, enabled, colors, metadata, name, desc: Each accepts a lambda function that defines how to combine the values from the input layers.default_values (optional): A dictionary of default values to use if a technique is missing a field in the combined layers.
The .process() Method
x.process(data, default_values=None)
data: Must be a list of Layer objects or a dict of {key: Layer} pairs.default_values (optional): Overrides the default values provided during initialization for this specific operation.
from mitreattack.navlayers.manipulators.layerops import LayerOps
from mitreattack.navlayers.core.layer import Layer
# Setup layers
demo = Layer()
demo.from_file("layer1.json")
demo2 = Layer()
demo2.from_file("layer2.json")
# Example 1: Average scores across a list of layers
lo = LayerOps(score=lambda x: sum(x) / len(x),
name=lambda x: x[1],
desc=lambda x: "This is a list example")
out_layer = lo.process([demo, demo2])
out_layer.to_file("averaged_layer.json")
# Example 2: Combine scores using a dictionary of layers
lo2 = LayerOps(score=lambda x: sum([x[y] for y in x]) / len([x[y] for y in x]),
colors=lambda x: x['b'],
desc=lambda x: "This is a dict example")
out_layer3 = lo2.process({'a': demo, 'b': demo2})