-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathExploreImage
More file actions
executable file
·79 lines (69 loc) · 3.32 KB
/
ExploreImage
File metadata and controls
executable file
·79 lines (69 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python3
import argparse
import logging
import os
from utils.ImagesScanner import scan_image
from multiprocessing import Process
from time import sleep
from utils.Log import getLogger
LOG = getLogger(__name__)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Scan a single image or a given list of DockerHub images')
parser.add_argument('-i','--image',
help='Image to scan in dockerhub in the format repository/image_name. It will be used the latest version by default.',
default=None)
parser.add_argument('-f','--file',
help='File with list of images to scan in the format repository/image_name. It will be used the latest version by default.',
default= None)
parser.add_argument('-o','--output',
help="Directory where to store matching files. Will use ./ by default.",
default=None
)
parser.add_argument('-c','--config',
help="Whispers custom config filepath. By default will use Docker Explorer whispers config.",
default='../whispers/whispers/config.yml'
)
parser.add_argument('--tmp',
help="Temporary path to dump the filesystem and perform the scan. Default is /tmp",
default='/tmp/'
)
parser.add_argument("--timeout",
help= 'Timeout in minutes for scan engine execution per image. Default 45 minutes.',
type= int,
default=45)
parser.add_argument("-p", "--processes",
help= 'Amount of parallel processes. Default is 4.',
type= int,
default=4)
options= parser.parse_args()
if options.image is None and options.file is None:
print("Provide either an image or file\n")
proc_quant= options.processes
tmp_path= options.tmp
whispers_config= options.config
LOG.debug(f"Using whisper config {os.path.abspath(whispers_config)}")
whispers_timeout=options.timeout*60
whispers_output= options.output if options.output is not None else os.getcwd()
LOG.debug(f"Using output path {whispers_output}")
try:
if options.image:
scan_image(options.image,tmp_path,whispers_config, whispers_output, whispers_timeout)
else:
images_list= open(options.file,"r")
processes=list()
for line in images_list.readlines():
if len(processes) < proc_quant:
p = Process(target=scan_image, args=(line.strip(),tmp_path,whispers_config, whispers_output, whispers_timeout,))
p.start()
processes.append(p)
while len(processes) >= proc_quant:
for proc in processes:
if not proc.is_alive():
processes.remove(proc)
sleep(5)
for proc in processes:
proc.join()
except KeyboardInterrupt:
pass
except Exception as e:
logging.exception(f"Error: {e}")