- Notifications
You must be signed in to change notification settings - Fork2.5k
zap-api-scan.py: refactoring attempt#6410
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -66,6 +66,7 @@ | ||
| class NoUrlsException(Exception): | ||
| pass | ||
| SUPPORTED_FORMATS = ["openapi", "soap", "graphql"] | ||
| config_dict = {} | ||
| config_msg = {} | ||
| @@ -241,8 +242,8 @@ def main(argv): | ||
| if len(target) == 0: | ||
| usage() | ||
| sys.exit(3) | ||
| if formatnot in SUPPORTED_FORMATS: | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. here and log levels can be validated by switching from | ||
| logging.warning('Format must beone of %r', SUPPORTED_FORMATS) | ||
| usage() | ||
| sys.exit(3) | ||
| @@ -261,7 +262,7 @@ def main(argv): | ||
| sys.exit(3) | ||
| target_file = '' | ||
| if target.startswith(('http://','https://')): | ||
| target_url = target | ||
| elif format == 'graphql': | ||
| logging.warning('Target must start with \'http://\' or \'https://\' and be a valid GraphQL endpoint.') | ||
| @@ -279,7 +280,7 @@ def main(argv): | ||
| schema_file = '' | ||
| if schema and format == 'graphql': | ||
| if schema.startswith(('http://','https://')): | ||
| schema_url = schema | ||
| else: | ||
| # assume its a file | ||
| @@ -295,7 +296,7 @@ def main(argv): | ||
| if port == 0: | ||
| port = get_free_port() | ||
| logging.debug('Using port:%s',port) | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. the logger takes care callingstr orrepr depending on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Any reason why not using f-string syntax ? ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I used to create strings only if logs are actually printed. Probably in this case it is ok using f-string. | ||
| if config_file: | ||
| # load config file from filestore | ||
| @@ -445,7 +446,7 @@ def main(argv): | ||
| res = zap.graphql.import_file(target, base_dir + schema) if schema_file else zap.graphql.import_url(target, schema_url) | ||
| else: | ||
| res = zap.graphql.import_url(target) | ||
| logging.info('About%r requests sent.',zap.core.number_of_messages()) | ||
| urls = zap.core.urls() | ||
| logging.debug('Import warnings: ' + str(res)) | ||
| @@ -518,7 +519,7 @@ def main(argv): | ||
| f.write('# Only the rule identifiers are used - the names are just for info\n') | ||
| f.write('# You can add your own messages to each rule by appending them after a tab on each line.\n') | ||
| for key, rule in sorted(all_dict.items()): | ||
| f.write(f'{key}\tWARN\t({rule})\n') | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. python 3.6 will be out of support from 2021-12. If we want to retain it, we can't use f-strings. Have your say. | ||
| # print out the passing rules | ||
| pass_dict = {} | ||
| @@ -601,13 +602,13 @@ def main(argv): | ||
| except IOError as e: | ||
| exception_raised = True | ||
| print("ERROR %s" % e) | ||
| logging.warning('I/O error:%s', e) | ||
| dump_log_file(cid) | ||
| except: | ||
| exception_raised = True | ||
| print("ERROR " + str(sys.exc_info()[0])) | ||
| logging.warning('Unexpected error:%r',sys.exc_info()[0]) | ||
| dump_log_file(cid) | ||
| if not running_in_docker(): | ||