Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Draft
ioggstream wants to merge1 commit intozaproxy:main
base:main
Choose a base branch
Loading
fromioggstream:ioggstream-small-fixes
Draft
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletionsdocker/zap-api-scan.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -66,6 +66,7 @@
class NoUrlsException(Exception):
pass

SUPPORTED_FORMATS = ["openapi", "soap", "graphql"]

config_dict = {}
config_msg = {}
Expand DownExpand Up@@ -241,8 +242,8 @@ def main(argv):
if len(target) == 0:
usage()
sys.exit(3)
if format!= 'openapi' and format != 'soap' and format != 'graphql':
logging.warning('Format must beeither \'openapi\', \'soap\', or \'graphql\'')
if formatnot in SUPPORTED_FORMATS:
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

here and log levels can be validated by switching fromgetopt ->ArgumentParser. In python2, Argument parser was not in the PSL, while in python3 you have it already and you don't need to install it anymore.

logging.warning('Format must beone of %r', SUPPORTED_FORMATS)
usage()
sys.exit(3)

Expand All@@ -261,7 +262,7 @@ def main(argv):
sys.exit(3)

target_file = ''
if target.startswith('http://') or target.startswith('https://'):
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.')
Expand All@@ -279,7 +280,7 @@ def main(argv):

schema_file = ''
if schema and format == 'graphql':
if schema.startswith('http://') or schema.startswith('https://'):
if schema.startswith(('http://','https://')):
schema_url = schema
else:
# assume its a file
Expand All@@ -295,7 +296,7 @@ def main(argv):
if port == 0:
port = get_free_port()

logging.debug('Using port:' + str(port))
logging.debug('Using port:%s',port)
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

the logger takes care callingstr orrepr depending on%s or%r

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Any reason why not using f-string syntax ?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The 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
Expand DownExpand Up@@ -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' + str(zap.core.number_of_messages()) + ' requests sent.')
logging.info('About%r requests sent.',zap.core.number_of_messages())
urls = zap.core.urls()

logging.debug('Import warnings: ' + str(res))
Expand DownExpand Up@@ -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(key + '\tWARN\t(' +rule + ')\n')
f.write(f'{key}\tWARN\t({rule})\n')
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The 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 = {}
Expand DownExpand Up@@ -601,13 +602,13 @@ def main(argv):
except IOError as e:
exception_raised = True
print("ERROR %s" % e)
logging.warning('I/O error:' + str(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:' + str(sys.exc_info()[0]))
logging.warning('Unexpected error:%r',sys.exc_info()[0])
dump_log_file(cid)

if not running_in_docker():
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp