Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Paas CI
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
INFN Cloud
Paas CI
Commits
4465c5cc
Commit
4465c5cc
authored
1 year ago
by
Gioacchino Vino
Browse files
Options
Downloads
Patches
Plain Diff
Reviewed scan python code
parent
0fd5bed3
No related branches found
No related tags found
1 merge request
!108
Updated Python scan code
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
files/gvm_library.py
+15
-15
15 additions, 15 deletions
files/gvm_library.py
with
15 additions
and
15 deletions
files/gvm_library.py
+
15
−
15
View file @
4465c5cc
...
...
@@ -297,14 +297,14 @@ class GVMClient():
res
.
append
(
o
)
return
res
def
create_port_list
(
self
,
name
:
str
,
ports
:
List
[
str
])
->
PortList
:
def
create_port_list
(
self
,
name
:
str
,
ports
:
List
[
str
])
->
Optional
[
str
]
:
res
=
self
.
client
.
create_port_list
(
name
,
'
,
'
.
join
(
ports
))
status
=
res
.
xpath
(
'
@status
'
)[
0
]
status_text
=
res
.
xpath
(
'
@status_text
'
)[
0
]
if
status
==
"
201
"
:
id
=
res
.
xpath
(
'
@id
'
)[
0
]
pl_
id
=
str
(
res
.
xpath
(
'
@id
'
)[
0
]
)
logging
.
debug
(
f
'
Created port list obj. Name:
{
name
}
, id:
{
id
}
, ports:
{
ports
}
'
)
return
PortList
(
name
=
name
,
id
=
id
)
return
pl_id
else
:
logging
.
error
(
f
"
ERROR during Port list creation. Status code:
{
status
}
, msg:
{
status_text
}
"
)
msg
=
f
"
ERROR during Port list creation. Status code:
{
status
}
, msg:
{
status_text
}
"
...
...
@@ -322,15 +322,15 @@ class GVMClient():
def
get_or_create_port_list
(
self
,
pl_name
:
str
,
ports
:
List
[
str
])
->
PortList
:
res
=
self
.
get_port_lists
(
pl_name
)
if
len
(
res
)
==
0
:
pl
=
self
.
create_port_list
(
pl_name
,
ports
)
return
self
.
get_port_lists
(
pl
.
id
)[
0
]
pl
_id
=
self
.
create_port_list
(
pl_name
,
ports
)
return
self
.
get_port_lists
(
pl
_
id
)[
0
]
elif
len
(
res
)
==
1
:
return
res
[
0
]
else
:
logging
.
warning
(
f
"
Found
{
len
(
res
)
}
results.
"
)
return
res
def
create_target
(
self
,
name
:
str
,
ip
:
str
,
pl
:
PortList
)
->
Optional
[
Target
]:
def
create_target
(
self
,
name
:
str
,
ip
:
str
,
pl
:
PortList
)
->
Optional
[
str
]:
res
=
self
.
client
.
create_target
(
name
=
name
,
comment
=
""
,
...
...
@@ -341,8 +341,8 @@ class GVMClient():
status
=
res
.
xpath
(
'
@status
'
)[
0
]
status_text
=
res
.
xpath
(
'
@status_text
'
)[
0
]
if
status
==
"
201
"
:
id
=
res
.
xpath
(
'
@id
'
)[
0
]
return
T
arget
(
name
=
name
,
id
=
id
)
target_
id
=
str
(
res
.
xpath
(
'
@id
'
)[
0
]
)
return
t
arget
_id
else
:
msg
=
f
"
ERROR during Target creation. Status code:
{
status
}
, msg:
{
status_text
}
"
raise
Exception
(
msg
)
...
...
@@ -371,8 +371,8 @@ class GVMClient():
def
get_or_create_target
(
self
,
name
:
str
,
ip
:
str
,
port_list
:
PortList
)
->
Target
:
res
=
self
.
get_targets
(
name
)
if
len
(
res
)
==
0
:
t
=
self
.
create_target
(
name
,
ip
,
port_list
)
return
self
.
get_targets
(
t
.
id
)[
0
]
t
_id
=
self
.
create_target
(
name
,
ip
,
port_list
)
return
self
.
get_targets
(
t
_
id
)[
0
]
elif
len
(
res
)
==
1
:
res
[
0
].
port_list
=
port_list
return
res
[
0
]
...
...
@@ -392,7 +392,7 @@ class GVMClient():
for
target
in
targets
:
self
.
delete_target
(
target
)
def
create_task
(
self
,
name
:
str
,
target
:
Target
)
->
Optional
[
Task
]:
def
create_task
(
self
,
name
:
str
,
target
:
Target
)
->
Optional
[
str
]:
res
=
self
.
client
.
create_task
(
name
=
name
,
config_id
=
Configs
.
config
,
...
...
@@ -401,8 +401,8 @@ class GVMClient():
status
=
res
.
xpath
(
'
@status
'
)[
0
]
status_text
=
res
.
xpath
(
'
@status_text
'
)[
0
]
if
status
==
"
201
"
:
id
=
res
.
xpath
(
'
@id
'
)[
0
]
return
T
ask
(
name
=
name
,
id
=
id
)
task_
id
=
str
(
res
.
xpath
(
'
@id
'
)[
0
]
)
return
t
ask
_id
else
:
msg
=
f
"
ERROR during Task creation. Status code:
{
status
}
, msg:
{
status_text
}
"
raise
Exception
(
msg
)
...
...
@@ -427,8 +427,8 @@ class GVMClient():
def
get_or_create_task
(
self
,
task_name
:
str
,
target
:
Target
)
->
Task
:
res
=
self
.
get_tasks
(
task_name
)
if
len
(
res
)
==
0
:
t
=
self
.
create_task
(
task_name
,
target
)
return
self
.
get_tasks
(
t
.
id
)[
0
]
t
_id
=
self
.
create_task
(
task_name
,
target
)
return
self
.
get_tasks
(
t
_
id
)[
0
]
elif
len
(
res
)
==
1
:
res
[
0
].
target
=
target
return
res
[
0
]
...
...
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