Add --disable-ssl option to simple-server.py

This commit is contained in:
maxmcd 2018-06-06 12:42:07 -04:00 committed by Sebastian Dröge
parent bb56d6eab7
commit 83b9c4efd7
2 changed files with 22 additions and 24 deletions

View file

@ -5,9 +5,4 @@ RUN pip3 install --user websockets
WORKDIR /opt/ WORKDIR /opt/
COPY . /opt/ COPY . /opt/
RUN sed -i 's/sslctx.load_cert_chain(chain_pem, keyfile=key_pem)/pass/g' \ CMD python -u ./simple-server.py --disable-ssl
./simple-server.py
RUN sed -i 's/ssl=sslctx,//g' \
./simple-server.py
CMD python -u ./simple-server.py

View file

@ -22,6 +22,7 @@ parser.add_argument('--addr', default='0.0.0.0', help='Address to listen on')
parser.add_argument('--port', default=8443, type=int, help='Port to listen on') parser.add_argument('--port', default=8443, type=int, help='Port to listen on')
parser.add_argument('--keepalive-timeout', dest='keepalive_timeout', default=30, type=int, help='Timeout for keepalive (in seconds)') parser.add_argument('--keepalive-timeout', dest='keepalive_timeout', default=30, type=int, help='Timeout for keepalive (in seconds)')
parser.add_argument('--cert-path', default=os.path.dirname(__file__)) parser.add_argument('--cert-path', default=os.path.dirname(__file__))
parser.add_argument('--disable-ssl', default=False, help='Disable ssl', action='store_true')
options = parser.parse_args(sys.argv[1:]) options = parser.parse_args(sys.argv[1:])
@ -239,6 +240,8 @@ async def handler(ws, path):
finally: finally:
await remove_peer(peer_id) await remove_peer(peer_id)
sslctx = None
if not options.disable_ssl:
# Create an SSL context to be used by the websocket server # Create an SSL context to be used by the websocket server
certpath = options.cert_path certpath = options.cert_path
print('Using TLS with keys in {!r}'.format(certpath)) print('Using TLS with keys in {!r}'.format(certpath))