Skip to content

Commit

Permalink
matches current main Incident doc
Browse files Browse the repository at this point in the history
  • Loading branch information
rpiazza committed Dec 4, 2024
1 parent cc40071 commit 4a29fc7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 57 deletions.
32 changes: 5 additions & 27 deletions incident-ef7/src/incident/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,42 @@

import stix2
from stix2.exceptions import ObjectConfigurationError
from stix2.properties import (BooleanProperty, EnumProperty, ListProperty,
from stix2.properties import (EmbeddedObjectProperty, EnumProperty, ListProperty,
OpenVocabProperty, ReferenceProperty,
StringProperty, TimestampProperty)
from stix2.v21.base import _STIXBase21

import incident.vocab as vocab
from incident.common import StateChange
from incident.util import validate_event_sequence
import vocab as vocab
from .common import StateChange

# Event Extension Data
EVENT_EXTENSION_DEFINITION_ID = 'extension-definition--4ca6de00-5b0d-45ef-a1dc-ea7279ea910e'


class EventSequenceEntry(_STIXBase21):
_properties = OrderedDict([
# required properties
('event_ref', ReferenceProperty(valid_types='event', required=True)),
('condition_type', EnumProperty(vocab.ACTIVITY_CONDITION, required=True)),
('transition_type', EnumProperty(vocab.ACTIVITY_TRANSITION, required=True))
])


class EventEntry(_STIXBase21):
_properties = OrderedDict([
# required properties
('event_ref', ReferenceProperty(valid_types='event', required=True)),
# optional properties
('next_steps', ListProperty(EventSequenceEntry)),
('sequence_start', BooleanProperty(default=lambda: True))
])


@stix2.v21.CustomObject(
'event',
[
# required properties
('status', EnumProperty(vocab.EVENT_STATUS, required=True)),
# optional properties
('changed_objects', ListProperty(StateChange)),
('changed_objects', ListProperty(EmbeddedObjectProperty(type=StateChange))),
('description', StringProperty()),
('end_time', TimestampProperty()),
('end_time_fidelity', EnumProperty(vocab.TIMESTAMP_FIDELITY)),
('event_types', ListProperty(OpenVocabProperty(vocab.EVENT_TYPE))),
('goal', StringProperty()),
('name', StringProperty()),
('next_event_ref', ListProperty(ReferenceProperty(valid_types='event'))),
('sighting_refs', ListProperty(ReferenceProperty(valid_types='sighting'))),
('start_time', TimestampProperty()),
('start_time_fidelity', EnumProperty(vocab.TIMESTAMP_FIDELITY)),
('subevents', ListProperty(EventEntry)),
],
EVENT_EXTENSION_DEFINITION_ID
)
class Event:
def _check_object_constraints(self):
super()._check_object_constraints()

validate_event_sequence(self.get("subevents"))

start_time = self.get('start_time')
end_time = self.get('end_time')

Expand Down
6 changes: 3 additions & 3 deletions incident-ef7/src/incident/impact.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
ReferenceProperty, StringProperty,
TimestampProperty)

import incident.vocab as vocab
from incident.common import EntityCountProperty
from incident.util import check_open_bounds
import vocab as vocab
from .common import EntityCountProperty
from .util import check_open_bounds


@stix2.CustomExtension(
Expand Down
33 changes: 6 additions & 27 deletions incident-ef7/src/incident/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,14 @@
TimestampProperty)
from stix2.v21 import _STIXBase21

import incident.util as util
import incident.vocab as vocab
from incident.common import EntityCountProperty, StateChange
import util as util
import vocab as vocab
from common import EntityCountProperty, StateChange

# Event Extension Data
TASK_EXTENSION_DEFINITION_ID = 'extension-definition--2074a052-8be4-4932-849e-f5e7798e0030'


class TaskSequenceEntry(_STIXBase21):
_properties = OrderedDict([
# required properties
('task_ref', ReferenceProperty(valid_types='task', required=True)),
('condition_type', EnumProperty(vocab.ACTIVITY_CONDITION, required=True)),
('transition_type', EnumProperty(vocab.ACTIVITY_TRANSITION, required=True))
])


class TaskEntry(_STIXBase21):
_properties = OrderedDict([
# required properties
('task_ref', ReferenceProperty(valid_types='task', required=True)),
# optional properties
('next_steps', ListProperty(TaskSequenceEntry)),
('sequence_start', BooleanProperty(default=lambda: True))
])


@stix2.v21.CustomObject(
'task',
[
Expand All @@ -47,21 +28,19 @@ class TaskEntry(_STIXBase21):
('end_time', TimestampProperty()),
('end_time_fidelity', EnumProperty(vocab.TIMESTAMP_FIDELITY)),
('error', StringProperty()),
('impacted_entity_types', EntityCountProperty(spec_version='2.1')),
('impacted_entity_counts', EntityCountProperty(valid_types=[IntegerProperty, FloatProperty], spec_version='2.1')),
('name', StringProperty()),
('next_task_ref', ListProperty(ReferenceProperty(valid_types='task'))),
('priority', IntegerProperty(min=0, max=100)),
('start_time', TimestampProperty()),
('start_time_fidelity', EnumProperty(vocab.TIMESTAMP_FIDELITY)),
('subtasks', ListProperty(TaskEntry))
('start_time_fidelity', EnumProperty(vocab.TIMESTAMP_FIDELITY))
],
TASK_EXTENSION_DEFINITION_ID
)
class Task:
def _check_object_constraints(self):
super()._check_object_constraints()

util.validate_task_sequence(self.get("subtasks"))

start_time = self.get('start_time')
end_time = self.get('end_time')

Expand Down

0 comments on commit 4a29fc7

Please sign in to comment.