Skip to content

Sourcery refactored master branch - #1

Open
sourcery-ai[bot] wants to merge 1 commit into
masterfrom
sourcery/master
Open

sourcery-ai[bot] wants to merge 1 commit into
masterfrom
sourcery/master

Conversation

@sourcery-ai

@sourcery-ai sourcery-ai Bot commented Apr 22, 2022

Copy link
Copy Markdown

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 daniel-butler April 22, 2022 03:27
Comment thread intuitlib/utils.py
Comment on lines -67 to +75

if 'id_token' in response_json:
if response_json['id_token'] is not None:
is_valid = validate_id_token(response_json['id_token'], obj.client_id, obj.issuer_uri, obj.jwks_uri)
if is_valid:
obj.id_token = response_json['id_token']

if 'id_token' in response_json and response_json['id_token'] is not None:
if is_valid := validate_id_token(
response_json['id_token'],
obj.client_id,
obj.issuer_uri,
obj.jwks_uri,
):
obj.id_token = response_json['id_token']

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function set_attributes refactored with the following changes:

Comment thread intuitlib/utils.py
Comment on lines -139 to +142
return ''.join(random.choice(allowed_chars) for i in range(length))
return ''.join(random.choice(allowed_chars) for _ in range(length))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function generate_token refactored with the following changes:

Comment thread intuitlib/utils.py
Comment on lines -159 to +175
if id_token_payload['iss'] != intuit_issuer:
if (
id_token_payload['iss'] != intuit_issuer
or id_token_payload['aud'][0] != client_id
):
return False
elif id_token_payload['aud'][0] != client_id:
return False

current_time = (datetime.utcnow() - datetime(1970, 1, 1)).total_seconds()
if id_token_payload['exp'] < current_time:
return False

message = id_token_parts[0] + '.' + id_token_parts[1]
message = f'{id_token_parts[0]}.{id_token_parts[1]}'
keys_dict = get_jwk(id_token_header['kid'], jwk_uri)

public_key = jwk.construct(keys_dict)
is_signature_valid = public_key.verify(message.encode('utf-8'), id_token_signature)
return is_signature_valid
return public_key.verify(message.encode('utf-8'), id_token_signature)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function validate_id_token refactored with the following changes:

Comment thread intuitlib/utils.py
Comment on lines -189 to +191
keys = next(key for key in data["keys"] if key['kid'] == kid)
return keys
return next(key for key in data["keys"] if key['kid'] == kid)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function get_jwk refactored with the following changes:

@sourcery-ai

sourcery-ai Bot commented Apr 22, 2022

Copy link
Copy Markdown
Author

Sourcery Code Quality Report

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

Quality metrics Before After Change
Complexity 4.53 ⭐ 4.25 ⭐ -0.28 👍
Method Length 53.70 ⭐ 52.90 ⭐ -0.80 👍
Working memory 8.01 🙂 8.00 🙂 -0.01 👍
Quality 73.03% 🙂 73.62% 🙂 0.59% 👍
Other metrics Before After Change
Lines 175 176 1
Changed files Quality Before Quality After Quality Change
intuitlib/utils.py 73.03% 🙂 73.62% 🙂 0.59% 👍

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

File Function Complexity Length Working Memory Quality Recommendation
intuitlib/utils.py validate_id_token 4 ⭐ 136 😞 11 😞 58.59% 🙂 Try splitting into smaller methods. Extract out complex expressions
intuitlib/utils.py send_request 5 ⭐ 78 🙂 12 😞 63.56% 🙂 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!

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