MCPcopy
hub / github.com/apache/caldera / AdversarySchema

Class AdversarySchema

app/objects/c_adversary.py:12–51  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10
11
12class AdversarySchema(ma.Schema):
13
14 class Meta:
15 unknown = ma.EXCLUDE
16
17 adversary_id = ma.fields.String()
18 name = ma.fields.String()
19 description = ma.fields.String()
20 atomic_ordering = ma.fields.List(ma.fields.String())
21 objective = ma.fields.String()
22 tags = ma.fields.List(ma.fields.String(), allow_none=True)
23 has_repeatable_abilities = ma.fields.Boolean(dump_only=True)
24 plugin = ma.fields.String(load_default=None)
25
26 @ma.pre_load
27 def fix_id(self, adversary, **_):
28 if 'id' in adversary:
29 adversary['adversary_id'] = adversary.pop('id')
30 return adversary
31
32 @ma.pre_load
33 def phase_to_atomic_ordering(self, adversary, **_):
34 """
35 Convert legacy adversary phases to atomic ordering
36 """
37 if 'phases' in adversary and 'atomic_ordering' in adversary:
38 raise ma.ValidationError('atomic_ordering and phases cannot be used at the same time', 'phases', adversary)
39 elif 'phases' in adversary:
40 adversary['atomic_ordering'] = [ab_id for phase in adversary.get('phases', {}).values() for ab_id in phase]
41 del adversary['phases']
42 return adversary
43
44 @ma.pre_load
45 def remove_properties(self, data, **_):
46 data.pop('has_repeatable_abilities', None)
47 return data
48
49 @ma.post_load
50 def build_adversary(self, data, **kwargs):
51 return None if kwargs.get('partial') is True else Adversary(**data)
52
53
54class Adversary(FirstClassObjectInterface, BaseObject):

Callers 6

OperationSchemaClass · 0.90
test_adversaryFunction · 0.90
test_operationFunction · 0.90
test_adversaryFunction · 0.90
AdversaryClass · 0.85

Calls

no outgoing calls

Tested by 3

test_adversaryFunction · 0.72
test_operationFunction · 0.72
test_adversaryFunction · 0.72