check --ssl-cert and --ssl-key to be files

This commit is contained in:
Matthias Lehmann 2014-01-29 15:54:19 +01:00
parent 14583a2efa
commit b9d7220b10
2 changed files with 13 additions and 0 deletions

View File

@ -19,6 +19,7 @@ from .input import (Parser, AuthCredentialsArgType, KeyValueArgType,
OUT_REQ_HEAD, OUT_REQ_BODY, OUT_RESP_HEAD,
OUT_RESP_BODY, OUTPUT_OPTIONS, OUTPUT_OPTIONS_DEFAULT,
PRETTY_MAP, PRETTY_STDOUT_TTY_ONLY, SessionNameValidator)
from .utils import existing_file
class HTTPieHelpFormatter(RawDescriptionHelpFormatter):
@ -468,6 +469,7 @@ network.add_argument(
network.add_argument(
'--ssl-cert',
default=None,
type=existing_file,
help="""
You can specify a local cert to use as client side SSL certificate.
This file may either contain both private key and certificate or you may
@ -479,6 +481,7 @@ network.add_argument(
network.add_argument(
'--ssl-key',
default=None,
type=existing_file,
help="""
The private key to use with SSL. Only needed if --ssl-cert is given and the
certificate file does not contain the private key.

View File

@ -1,4 +1,5 @@
from __future__ import division
import argparse
def humanize_bytes(n, precision=2):
@ -44,3 +45,12 @@ def humanize_bytes(n, precision=2):
break
return '%.*f %s' % (precision, n / factor, suffix)
def existing_file(filename):
try:
open(filename, 'rb')
except IOError as ex:
raise argparse.ArgumentTypeError(
'%s: %s' % (filename, ex.args[1]))
return filename