Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
HORSE
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Iulisloi Zacarias
HORSE
Commits
9f1f7c53
Commit
9f1f7c53
authored
1 year ago
by
Chukwuemeka Michael Muonagor
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
12f511e6
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
delete_intents.py
+74
-0
74 additions, 0 deletions
delete_intents.py
with
74 additions
and
0 deletions
delete_intents.py
0 → 100644
+
74
−
0
View file @
9f1f7c53
from
__future__
import
print_function
,
unicode_literals
from
PyInquirer
import
style_from_dict
,
Token
,
prompt
import
pandas
as
pd
import
sys
import
delete_command
#IP address of the machine on which the IBI is running
ip
=
sys
.
argv
[
1
]
#ip = "192.168.56.1"
workflow_url
=
"
http://
"
+
ip
+
"
:7778/workflows
"
#function for deleting intents
def
select_delete_fun
():
style
=
style_from_dict
({
Token
.
QuestionMark
:
'
#E91E63 bold
'
,
Token
.
Selected
:
'
#673AB7 bold
'
,
Token
.
Instruction
:
''
,
# default
Token
.
Answer
:
'
#2196f3 bold
'
,
Token
.
Question
:
''
,
})
print
(
'
to delete intent
'
)
df
=
pd
.
read_csv
(
'
intent_store.csv
'
)
#array of intent_ids
intent_id_list
=
[]
#array of the whole intents from which to choose which one to delete
intent_choices_delete
=
[]
for
ind
in
df
.
index
:
#add the IDs of the whole intents in the intent store to intent_id_list
intent_id_list
.
append
(
df
[
'
intent_id
'
][
ind
])
empty_dict
=
{}
# join the intent parameters as string, put inside a dictionary and add to intent_choices_delete array
delete_string
=
df
[
'
intent_type
'
][
ind
]
+
'
'
+
df
[
'
threat
'
][
ind
]
+
'
'
+
str
(
df
[
'
host
'
][
ind
])
\
+
'
'
+
df
[
'
action
'
][
ind
]
+
'
'
+
str
(
df
[
'
time_frame
'
][
ind
])
+
'
'
+
df
[
'
intent_id
'
][
ind
]
empty_dict
[
'
name
'
]
=
delete_string
intent_choices_delete
.
append
(
empty_dict
)
#prompts on the terminal for one to select which intent(s) to delete
question_delete
=
[
{
'
type
'
:
'
checkbox
'
,
'
qmark
'
:
''
,
'
name
'
:
'
delete
'
,
'
message
'
:
'
Select Intent(s) to Delete:
'
,
'
choices
'
:
intent_choices_delete
}
]
answer_delete
=
prompt
(
question_delete
,
style
=
style
)
#answer_delete_arr is an array of selected intents to delete
answer_delete_arr
=
answer_delete
[
'
delete
'
]
for
i
in
range
(
len
(
answer_delete_arr
)):
for
ind
in
range
(
len
(
df
.
index
)):
if
ind
<
len
(
df
.
index
)
and
not
df
.
empty
:
#join the intents as string again
delete_string
=
df
[
'
intent_type
'
][
ind
]
+
'
'
+
df
[
'
threat
'
][
ind
]
+
'
'
+
str
(
df
[
'
host
'
][
ind
])
\
+
'
'
+
df
[
'
action
'
][
ind
]
+
'
'
+
str
(
df
[
'
time_frame
'
][
ind
])
+
'
'
+
df
[
'
intent_id
'
][
ind
]
#if any joined string of intents corresponds with any string in answer_delete_arr
#then that intent would be deleted
if
delete_string
==
answer_delete_arr
[
i
]:
#call the delete_intents_fun function which sends a json with ID of intent to delete to the RTR
delete_command
.
delete_intents_fun
(
df
[
'
intent_id
'
][
ind
],
workflow_url
)
# remove this intent to be deleted from the intent store and reshuffle the intent store
df
=
df
.
drop
(
df
.
index
[
ind
])
df
=
df
.
reset_index
(
drop
=
True
)
# write the modified dataframe to the intent store
df
.
to_csv
(
'
intent_store.csv
'
,
index
=
False
)
select_delete_fun
()
\ 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