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

Sourcery refactored master branch #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Mar 2, 2022

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from vbrozik March 2, 2022 07:35
Comment on lines -125 to +134

# logout to prevent stale sessions
print(f'Logging out of firewall')
print('Logging out of firewall')
f.get(f'https://{args.firewall}/logout', verify=False, timeout=10)

# format the data
if 'results' not in data:
print('Firewall returned no results')
sys.exit(1)

Copy link
Author

Choose a reason for hiding this comment

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

Function main refactored with the following changes:

Comment on lines -180 to +192
if header == 'ipv4_addresses': # parse list, extract ip mask for each item within the field
for x in row[header]:
for x in row[header]:
if header == 'ipv4_addresses': # parse list, extract ip mask for each item within the field
subitems.append(f"{x['ip']}/{x['cidr_netmask']}")
else: # parse list, extract q_origin_key for each item within the field
for x in row[header]:
if address_lookup and x['q_origin_key'] in address_lookup:
subitems.append(address_lookup[x['q_origin_key']])
else:
subitems.append(x['q_origin_key'])
elif address_lookup and x['q_origin_key'] in address_lookup:
subitems.append(address_lookup[x['q_origin_key']])
else:
subitems.append(x['q_origin_key'])
# join with a space, can't use comma due to csv
row_data.append(' '.join(map(str, subitems)))
row_data.append(' '.join(map(str, subitems)))
elif type(row[header]) == str:
row_data.append(row[header].replace(",", ""))
elif address_lookup and row[header] in address_lookup:
subitems.append(address_lookup[row[header]])
else:
# this field is just a string/int, simply add it to the row
if type(row[header]) == str:
row_data.append(row[header].replace(",", ""))
else:
if address_lookup and row[header] in address_lookup:
subitems.append(address_lookup[row[header]])
else:
row_data.append(row[header])
row_data.append(row[header])
Copy link
Author

Choose a reason for hiding this comment

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

Function build_csv refactored with the following changes:

This removes the following comments ( why? ):

# parse list, extract q_origin_key for each item within the field
# this field is just a string/int, simply add it to the row

Comment on lines -238 to +237
session.post(f'https://{host}/logindisclaimer',
data=f'confirm=1&redir=/ng',
session.post(
f'https://{host}/logindisclaimer',
data='confirm=1&redir=/ng',
verify=False,
timeout=10)
timeout=10,
)

Copy link
Author

Choose a reason for hiding this comment

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

Function f_login refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Mar 2, 2022

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 1.39%.

Quality metrics Before After Change
Complexity 32.20 😞 25.80 😞 -6.40 👍
Method Length 202.80 😞 200.60 😞 -2.20 👍
Working memory 15.23 ⛔ 15.29 ⛔ 0.06 👎
Quality 26.67% 😞 28.06% 😞 1.39% 👍
Other metrics Before After Change
Lines 241 237 -4
Changed files Quality Before Quality After Quality Change
fortigate2csv.py 26.67% 😞 28.06% 😞 1.39% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
fortigate2csv.py main 29 😞 661 ⛔ 18 ⛔ 15.60% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
fortigate2csv.py build_csv 37 ⛔ 177 😞 13 😞 28.29% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
fortigate2csv.py f_login 5 ⭐ 124 😞 11 😞 59.03% 🙂 Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

@vbrozik vbrozik removed their request for review May 16, 2024 07:48
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.

0 participants