Skip to content
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

Merged
merged 1 commit into from
Jul 4, 2017
Merged

Conversation

matriv
Copy link
Contributor

@matriv matriv commented Jul 3, 2017

No description provided.

@matriv matriv requested a review from chaudum July 3, 2017 13:38
@@ -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
Copy link
Member

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))

Copy link
Contributor Author

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!

@coveralls
Copy link

coveralls commented Jul 3, 2017

Coverage Status

Coverage decreased (-0.4%) to 81.646% when pulling ad15641 on mt/validate-file-paths into d24d121 on master.

@@ -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')
Copy link
Member

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

Copy link
Contributor Author

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?

@matriv matriv removed the request for review from chaudum July 3, 2017 14:22
@coveralls
Copy link

coveralls commented Jul 3, 2017

Coverage Status

Coverage decreased (-1.0%) to 81.14% when pulling 894f95d on mt/validate-file-paths into d24d121 on master.

@coveralls
Copy link

coveralls commented Jul 3, 2017

Coverage Status

Coverage decreased (-0.8%) to 81.26% when pulling 0ca9dd2 on mt/validate-file-paths into d24d121 on master.

@coveralls
Copy link

coveralls commented Jul 3, 2017

Coverage Status

Coverage increased (+0.2%) to 82.262% when pulling 54cedbd on mt/validate-file-paths into d24d121 on master.

@codecov-io
Copy link

Codecov Report

Merging #197 into master will increase coverage by 0.16%.
The diff coverage is 93.61%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
src/crate/crash/test_command.py 98.33% <100%> (+0.14%) ⬆️
src/crate/crash/command.py 83.78% <75%> (-0.7%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d24d121...54cedbd. Read the comment docs.

@matriv matriv merged commit f9e1d7d into master Jul 4, 2017
@matriv matriv deleted the mt/validate-file-paths branch July 4, 2017 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants