Skip to content

Commit cb7ecc7

Browse files
reinoudReinoud van Leeuwen
andauthored
Add Dockerfile; add command line parsing (#182)
* add a Dockerfile * added command-line parsing * updated documentation --------- Co-authored-by: Reinoud van Leeuwen <reinoud.van.leeuwen@itcreation.nl>
1 parent fd277ef commit cb7ecc7

File tree

3 files changed

+62
-5
lines changed

3 files changed

+62
-5
lines changed

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Use an official Python runtime as a parent image
2+
FROM python:3.11-slim-buster
3+
4+
COPY . /
5+
6+
# Install ssllabsscan module
7+
RUN pip3 install .
8+
COPY sample/styles.css /usr/local/lib/python3.11/site-packages/ssllabsscan/styles.css
9+
10+
ENTRYPOINT [ "ssllabs-scan" ]

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,23 @@ pip install -e .
6565
ssllabs-scan sample\SampleServerList.txt
6666
```
6767

68+
### Docker
69+
```
70+
# Build docker image
71+
docker build . --tag=ssllabsscan
72+
```
73+
Running Docker from commandline:
74+
```
75+
# create directory for input and output
76+
mkdir out
77+
# put serverlist in directory
78+
cp SampleServerlist.txt out
79+
# Run docker image with created directory mounted as /tmp
80+
# use -t option to prevent output buffering
81+
docker run --mount type=bind,source=./out,target=/tmp ssllabsscan -o /tmp/output.html -s /tmp/output.csv /tmp/SampleServerList.txt
82+
# all html, csv, json output is in the out directory
83+
```
84+
6885
### Example console output
6986
```
7087
$ ssllabs-scan sample/SampleServerList.txt

ssllabsscan/main.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
App's main
33
"""
4+
import argparse
45
import csv
56
import os
67
import shutil
@@ -57,7 +58,7 @@ def process(
5758
content = f.readlines()
5859
servers = [x.strip() for x in content if x.strip()]
5960

60-
with open(SUMMARY_CSV, "w") as outfile:
61+
with open(summary_csv, "w") as outfile:
6162
# write column names to file
6263
outfile.write("#{}\n".format(",".join(str(s) for s in SUMMARY_COL_NAMES)))
6364

@@ -72,15 +73,44 @@ def process(
7273
output_summary_html(summary_csv, summary_html)
7374
return ret
7475

76+
def parse_args():
77+
"""
78+
Parse command line arguments.
79+
"""
80+
parser = argparse.ArgumentParser(description="SSL Labs Scan")
81+
parser.add_argument(
82+
"inputfile",
83+
help="Input file containing list of servers to scan",
84+
)
85+
parser.add_argument(
86+
"-o",
87+
"--output",
88+
dest="output",
89+
default=SUMMARY_HTML,
90+
help="Output file containing summary of scan results",
91+
)
92+
parser.add_argument(
93+
"-s",
94+
"--summary",
95+
dest="summary",
96+
default=SUMMARY_CSV,
97+
help="Output file containing summary of scan results",
98+
)
99+
parser.add_argument(
100+
"-p",
101+
"--progress",
102+
dest="progress",
103+
default=30,
104+
help="Progress check interval in seconds",
105+
)
106+
return parser.parse_args()
75107

76108
def main():
77109
"""
78110
Entry point of the app.
79111
"""
80-
if len(sys.argv) != 2:
81-
print(f"{sys.argv[0]} [SERVER_LIST_FILE]")
82-
return 1
83-
return process(server_list_file=sys.argv[1])
112+
args = parse_args()
113+
return process(server_list_file=args.inputfile, check_progress_interval_secs=args.progress, summary_csv=args.summary, summary_html=args.output)
84114

85115

86116
if __name__ == "__main__":

0 commit comments

Comments
 (0)