Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
DynamicRiskManagementforSSC
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Iversen
DynamicRiskManagementforSSC
Commits
5a721ea3
Commit
5a721ea3
authored
1 year ago
by
martiivGylden
Browse files
Options
Downloads
Patches
Plain Diff
Working on metrics definitions
parent
65a0ccfe
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
dynamics.py
+26
-26
26 additions, 26 deletions
dynamics.py
main.py
+16
-1
16 additions, 1 deletion
main.py
with
42 additions
and
27 deletions
dynamics.py
+
26
−
26
View file @
5a721ea3
import
logging
as
log
from
enum
import
Enum
#Dynamics class parent class for all dynamic components in the diagram
class
Dynamics
:
def
__init__
(
self
,
id
,
matrixRow
)
->
None
:
def
__init__
(
self
,
id
)
->
None
:
self
.
id
=
id
self
.
metrics
=
[
]
self
.
matrixRow
=
matrixRow
self
.
metrics
=
[
Metric
]
#List of metrics for the dynamic
#String only returns necessary info
def
__str__
(
self
)
->
str
:
...
...
@@ -14,6 +15,8 @@ class Dynamics:
#Simple contains function to check if metric already exists
def
containsMetric
(
metrics
,
metric
):
if
len
(
metrics
)
==
0
:
return
False
for
i
in
metrics
:
if
i
.
name
==
metric
:
return
True
...
...
@@ -21,48 +24,45 @@ class Dynamics:
# Function used to add a metric to the dynamics list
# The function will check if the metric already exists in the global list, if it does it will not be added to the global list
def
addMetrics
(
self
,
localMetricList
,
newMetric
,
description
):
metric
=
Metric
(
newMetric
,
description
)
#Create a new metric
def
addMetrics
(
self
,
globalMetricList
,
newMetric
,
description
,
metricType
):
metric
=
Metric
(
newMetric
,
description
,
metricType
)
#Check if metric is already in the global metrics list if it is the metric will not be added to the global list
if
Dynamics
.
containsMetric
(
self
.
m
etric
s
,
newMetric
)
==
False
:
self
.
metrics
=
self
.
m
etric
s
.
append
(
metric
)
if
Dynamics
.
containsMetric
(
globalM
etric
List
,
newMetric
)
==
False
:
globalMetricList
=
globalM
etric
List
.
append
(
metric
)
log
.
info
(
f
"
Added metric
{
newMetric
}
to GLOBAL dynamics list with ID:
{
self
.
id
}
"
)
else
:
log
.
info
(
f
"
Metric
{
newMetric
}
already exists in GLOBAL dynamics list with ID:
{
self
.
id
}
"
)
localM
etric
List
.
append
(
metric
)
self
.
m
etric
s
.
append
(
metric
)
log
.
info
(
f
"
Added metric
{
newMetric
}
to LOCAL dynamics list with ID:
{
self
.
id
}
"
)
#Threat dynamic entity, will be linked to the different threats and the dynamic matrix
class
ThreatDynamics
(
Dynamics
):
def
__init__
(
self
,
id
,
metrics
,
matrixRow
,
threat
)
->
None
:
super
().
__init__
(
id
,
metrics
,
matrixRow
)
self
.
threat
=
threat
self
.
localMetrics
=
[]
def
__init__
(
self
,
id
,
threatID
)
->
None
:
super
().
__init__
(
id
)
self
.
threatID
=
threatID
def
__str__
(
self
)
->
str
:
return
f
"
ThreatDynamic:
{
self
.
id
}
,
{
self
.
metrics
}
,
{
self
.
threat
}
"
return
f
"
ThreatDynamic:
{
self
.
id
}
,
{
self
.
threat
ID
}
"
#Consequence dynamic will also be linked to the different consequences and the dynamic matrix
class
ConsequenceDynamics
(
Dynamics
):
def
__init__
(
self
,
id
,
metrics
,
matrixRow
,
consequence
)
->
None
:
super
().
__init__
(
id
,
metrics
,
matrixRow
)
self
.
consequence
=
consequence
self
.
localMetrics
=
[]
def
__init__
(
self
,
id
,
consequenceID
)
->
None
:
super
().
__init__
(
id
)
self
.
consequenceID
=
consequenceID
def
__str__
(
self
)
->
str
:
return
f
"
ConsequenceDynamic:
{
self
.
id
}
,
{
self
.
metrics
}
,
{
self
.
consequence
}
"
return
f
"
ConsequenceDynamic:
{
self
.
id
}
,
{
self
.
consequence
ID
}
"
#Metric class, will be used for all dynamics
class
Metric
:
def
__init__
(
self
,
name
,
type
)
->
None
:
self
.
name
=
name
self
.
type
=
type
def
__init__
(
self
,
name
,
type
,
description
)
->
None
:
self
.
name
=
name
# Name of the metric
self
.
description
=
description
# Description of the metric
self
.
type
=
type
# Four types of dynamic metrics: process, devteam, opensource and vendor
def
__str__
(
self
)
->
str
:
return
f
"
Metric:
{
self
.
name
}
,
{
self
.
description
}
"
\ No newline at end of file
\ No newline at end of file
This diff is collapsed.
Click to expand it.
main.py
+
16
−
1
View file @
5a721ea3
import
dynamics
as
dyn
def
main
():
dynamicMetrics
=
[]
threat
=
dyn
.
ThreatDynamics
(
1
,
"
Threat1
"
)
print
(
threat
)
threat
.
addMetrics
(
dynamicMetrics
,
"
Metric1
"
,
"
Description1
"
,
"
opensource
"
)
threat
.
addMetrics
(
dynamicMetrics
,
"
Metric2
"
,
"
Description2
"
,
"
opensource
"
)
threat
.
addMetrics
(
dynamicMetrics
,
"
Metric3
"
,
"
Description3
"
,
"
opensource
"
)
print
(
"
Threat object:
"
,
threat
)
print
(
"
Metrics:
"
,
dynamicMetrics
)
if
__name__
==
"
__main__
"
:
main
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment