-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validate ssl related filepaths beforehand. #197
Conversation
src/crate/crash/command.py
Outdated
@@ -481,11 +481,22 @@ def main(): | |||
sys.exit(cmd.exit_code) | |||
|
|||
def _create_cmd(crate_hosts, error_trace, output_writer, is_tty, args): | |||
|
|||
# Validate paths for certificate and key files | |||
cert_file = args.cert_file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you consider using the type
functionality of argparse?
E.g. something like this:
def file_with_permissions(f):
if not os.access(f, os.R_OK):
raise Exception("foo")
return f
parser = argparse.ArgumentParser()
parser.add_argument('--file', type=file_with_permissions, required=True)
try:
parser.parse_args()
except Exception as e:
print(str(e))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no didn't know that :-) thx!
src/crate/crash/command.py
Outdated
@@ -499,5 +503,10 @@ def _create_cmd(crate_hosts, error_trace, output_writer, is_tty, args): | |||
ca_cert_file=args.ca_cert_file, | |||
username=args.username) | |||
|
|||
def file_with_permissions(path): | |||
if not os.access(path, os.R_OK): | |||
raise Exception('[' + path + '] does not exist or is not readable') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would make sense to raise a exception that is a bit more specific here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What kind of Exception? Should I create a new class like ValidationError or ParseError?
Codecov Report
@@ Coverage Diff @@
## master #197 +/- ##
==========================================
+ Coverage 82.09% 82.26% +0.16%
==========================================
Files 16 16
Lines 1910 1945 +35
==========================================
+ Hits 1568 1600 +32
- Misses 342 345 +3
Continue to review full report at Codecov.
|
54cedbd
to
f9e1d7d
Compare
No description provided.