Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
BioHPC
clair-singularity
Commits
405ece3c
Commit
405ece3c
authored
Aug 24, 2017
by
David Trudgian
Browse files
Merge branch 'master' of github.com:dctrud/clair-singularity
parents
9733f723
fc052514
Changes
2
Hide whitespace changes
Inline
Side-by-side
clair_singularity/clair.py
View file @
405ece3c
...
...
@@ -2,7 +2,10 @@ from __future__ import print_function
import
requests
import
sys
from
.util
import
pretty_json
,
err_and_exit
class
ClairException
(
Exception
):
pass
def
check_clair
(
API_URI
,
quiet
):
...
...
@@ -16,7 +19,7 @@ def check_clair(API_URI, quiet):
if
not
quiet
:
sys
.
stderr
.
write
(
"Found Clair server with %d namespaces
\n
"
%
namespace_count
)
except
Exception
as
e
:
err_and_exit
(
"Error - couldn't access Clair v1 API at %s
\n
%s
\n
"
%
(
API_URI
,
e
.
message
)
,
1
)
raise
ClairException
(
"Error - couldn't access Clair v1 API at %s
\n
%s
\n
"
%
(
API_URI
,
e
.
message
))
return
True
...
...
@@ -35,10 +38,10 @@ def post_layer(API_URI, image_name, image_uri, quiet):
if
not
quiet
:
sys
.
stderr
.
write
(
"Image registered as layer with Clair
\n
"
)
else
:
err_and_exit
(
"Failed registering image with Clair
\n
%s
\n
"
%
pretty_json
(
r
)
,
1
)
raise
ClairException
(
"Failed registering image with Clair
\n
%s
\n
"
%
pretty_json
(
r
))
except
Exception
as
e
:
err_and_exit
(
"Error - couldn't send image to Clair - %s
\n
"
%
(
e
)
,
1
)
raise
ClairException
(
"Error - couldn't send image to Clair - %s
\n
"
%
(
e
))
def
get_report
(
API_URI
,
image_name
):
...
...
@@ -50,10 +53,10 @@ def get_report(API_URI, image_name):
if
r
.
status_code
==
requests
.
codes
.
ok
:
return
r
.
json
()
else
:
err_and_exit
(
"Failed retrieving report from Clair
\n
%s
\n
"
%
pretty_json
(
r
)
,
1
)
raise
ClairException
(
"Failed retrieving report from Clair
\n
%s
\n
"
%
pretty_json
(
r
))
except
Exception
as
e
:
err_and_exit
(
"Error - couldn't retrieve report from Clair - %s
\n
"
%
(
e
)
,
1
)
raise
ClairException
(
"Error - couldn't retrieve report from Clair - %s
\n
"
%
(
e
))
def
format_report_text
(
report
):
...
...
clair_singularity/cli.py
View file @
405ece3c
...
...
@@ -5,7 +5,7 @@ import shutil
from
multiprocessing
import
Process
from
.
import
VERSION
from
.clair
import
check_clair
,
post_layer
,
get_report
,
format_report_text
from
.clair
import
check_clair
,
post_layer
,
get_report
,
format_report_text
,
ClairException
from
.util
import
sha256
,
wait_net_service
,
err_and_exit
from
.image
import
check_image
,
image_to_tgz
,
http_server
...
...
@@ -36,7 +36,10 @@ def cli(image, clair_uri, text_output, json_output, bind_ip, bind_port, quiet):
click
.
echo
(
"Image has SHA256: %s"
%
image_name
,
err
=
True
)
# Make sure we can talk to Clair OK
check_clair
(
API_URI
,
quiet
)
try
:
check_clair
(
API_URI
,
quiet
)
except
ClairException
as
e
:
err_and_exit
(
e
.
message
)
# Start an HTTP server to serve the .tar.gz from our temporary directory
# so that Clair can retrieve it
...
...
@@ -47,12 +50,18 @@ def cli(image, clair_uri, text_output, json_output, bind_ip, bind_port, quiet):
httpd_ready
=
wait_net_service
(
bind_ip
,
bind_port
,
30
)
if
not
httpd_ready
:
httpd
.
terminate
()
err_and_exit
(
"HTTP server did not become ready
\n
"
,
1
)
shutil
.
rmtree
()
err_and_exit
(
"Error: HTTP server did not become ready
\n
"
,
1
)
image_uri
=
'http://%s:%d/%s'
%
(
bind_ip
,
bind_port
,
path
.
basename
(
tar_file
))
# Register the iamge with Clair as a docker layer that has no parent
post_layer
(
API_URI
,
image_name
,
image_uri
,
quiet
)
try
:
post_layer
(
API_URI
,
image_name
,
image_uri
,
quiet
)
except
ClairException
as
e
:
httpd
.
terminate
()
shutil
.
rmtree
()
err_and_exit
(
e
.
message
,
1
)
# Done with the .tar.gz so stop serving it and remove the temp dir
httpd
.
terminate
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment