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

chore: re-work public tokens (part I) #494

Merged
merged 3 commits into from
Jun 10, 2024

Conversation

giovanni-guidini
Copy link
Contributor

ticket: https://l.codecov.dev/QLcMzU

1st part of the move to having more dedicated-tokens for certain functionality in the app.
It also now allows dedicated-tokens to come from apps (for GitHub)

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

@giovanni-guidini giovanni-guidini requested a review from a team June 6, 2024 09:29
@codecov-qa
Copy link

codecov-qa bot commented Jun 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.26%. Comparing base (49e8df9) to head (802378e).
Report is 2 commits behind head on main.

✅ All tests successful. No failed tests found.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #494      +/-   ##
==========================================
- Coverage   97.26%   97.26%   -0.01%     
==========================================
  Files         412      414       +2     
  Lines       34393    34479      +86     
==========================================
+ Hits        33453    33536      +83     
- Misses        940      943       +3     
Flag Coverage Δ
integration 97.26% <100.00%> (-0.01%) ⬇️
latest-uploader-overall 97.26% <100.00%> (-0.01%) ⬇️
unit 97.26% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 94.42% <100.00%> (+<0.01%) ⬆️
OutsideTasks 97.55% <100.00%> (+<0.01%) ⬆️
Files Coverage Δ
services/bots/helpers.py 100.00% <100.00%> (ø)
services/bots/public_bots.py 92.59% <100.00%> (+1.28%) ⬆️
services/bots/tests/test_bots.py 100.00% <ø> (ø)
services/bots/tests/test_helpers.py 100.00% <100.00%> (ø)
services/tests/test_bots.py 100.00% <ø> (ø)

... and 5 files with indirect coverage changes

@codecov-notifications
Copy link

codecov-notifications bot commented Jun 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #494      +/-   ##
==========================================
- Coverage   97.26%   97.26%   -0.01%     
==========================================
  Files         412      414       +2     
  Lines       34393    34479      +86     
==========================================
+ Hits        33453    33536      +83     
- Misses        940      943       +3     
Flag Coverage Δ
integration 97.26% <100.00%> (-0.01%) ⬇️
latest-uploader-overall 97.26% <100.00%> (-0.01%) ⬇️
unit 97.26% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 94.42% <100.00%> (+<0.01%) ⬆️
OutsideTasks 97.55% <100.00%> (+<0.01%) ⬆️
Files Coverage Δ
services/bots/helpers.py 100.00% <100.00%> (ø)
services/bots/public_bots.py 92.59% <100.00%> (+1.28%) ⬆️
services/bots/tests/test_bots.py 100.00% <ø> (ø)
services/bots/tests/test_helpers.py 100.00% <100.00%> (ø)
services/tests/test_bots.py 100.00% <ø> (ø)

... and 5 files with indirect coverage changes

Copy link

codecov-public-qa bot commented Jun 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.26%. Comparing base (49e8df9) to head (802378e).
Report is 2 commits behind head on main.

✅ All tests successful. No failed tests found ☺️

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #494      +/-   ##
==========================================
- Coverage   97.26%   97.26%   -0.01%     
==========================================
  Files         412      414       +2     
  Lines       34393    34479      +86     
==========================================
+ Hits        33453    33536      +83     
- Misses        940      943       +3     
Flag Coverage Δ
integration 97.26% <100.00%> (-0.01%) ⬇️
latest-uploader-overall 97.26% <100.00%> (-0.01%) ⬇️
unit 97.26% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 94.42% <100.00%> (+<0.01%) ⬆️
OutsideTasks 97.55% <100.00%> (+<0.01%) ⬆️
Files Coverage Δ
services/bots/helpers.py 100.00% <100.00%> (ø)
services/bots/public_bots.py 92.59% <100.00%> (+1.28%) ⬆️
services/bots/tests/test_bots.py 100.00% <ø> (ø)
services/bots/tests/test_helpers.py 100.00% <100.00%> (ø)
services/tests/test_bots.py 100.00% <ø> (ø)

... and 5 files with indirect coverage changes

Copy link

codecov bot commented Jun 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.29%. Comparing base (49e8df9) to head (802378e).
Report is 2 commits behind head on main.

Changes have been made to critical files, which contain lines commonly executed in production. Learn more

✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #494      +/-   ##
==========================================
- Coverage   97.29%   97.29%   -0.01%     
==========================================
  Files         443      445       +2     
  Lines       35122    35380     +258     
==========================================
+ Hits        34172    34423     +251     
- Misses        950      957       +7     
Flag Coverage Δ
integration 97.26% <100.00%> (-0.01%) ⬇️
latest-uploader-overall 97.26% <100.00%> (-0.01%) ⬇️
unit 97.26% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 94.51% <100.00%> (+0.03%) ⬆️
OutsideTasks 97.55% <100.00%> (+<0.01%) ⬆️
Files Coverage Δ
services/bots/helpers.py 100.00% <100.00%> (ø)
services/bots/public_bots.py 92.59% <100.00%> (+1.28%) ⬆️
services/bots/tests/test_bots.py 100.00% <ø> (ø)
services/bots/tests/test_helpers.py 100.00% <100.00%> (ø)
services/tests/test_bots.py 100.00% <ø> (ø)

... and 5 files with indirect coverage changes

This change has been scanned for critical changes. Learn more

ticket: https://l.codecov.dev/QLcMzU

1st part of the move to having more dedicated-tokens for certain functionality in the app.
It also now allows dedicated-tokens to come from apps (for GitHub)
@giovanni-guidini giovanni-guidini force-pushed the gio/map-dedicated-apps-to-tokentype branch from 60bb051 to 40d638a Compare June 6, 2024 13:08
Copy link
Contributor

@michelletran-codecov michelletran-codecov left a comment

Choose a reason for hiding this comment

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

Generally LGTM. Just a few comments.

TokenType.admin: admin_bot_token,
# [GitHub] Only legacy PATs can post statuses and comment to all public repos, so there can't be a dedicated_app for this
Copy link
Contributor

Choose a reason for hiding this comment

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

What is "PAT"? Googling the acronym gave me a lot of results. :p

Copy link
Contributor

Choose a reason for hiding this comment

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

service: str, token_type: TokenType
) -> Token | None:
# GitHub can have 'dedicated_apps', and those are preferred
dedicated_app = get_config(service, "dedicated_apps", token_type.value, default={})
Copy link
Contributor

Choose a reason for hiding this comment

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

dedicated_app object looks like it's a dict[str, Any] type. I think we should annotate it for clarity.

@@ -0,0 +1,32 @@
from shared.config import get_config
Copy link
Contributor

Choose a reason for hiding this comment

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

It took me a while to realize that get_config was actually loading from YAML configurations. from shared.config import get_config just looked a lot like it's loading application configs, not YAML (I had to dig into the code to verify that it's actually YAML). Anyways, not sure if it's a me thing, or if other people will also be confused.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

from shared.config import get_config just looked a lot like it's loading application configs

That is the case. The fact that the config lives in a YAML is just an implementation detail. For all intents and purposes it's fine to look at get_config as "getting application configs" and understand that the config logically is a map

pem_path=f"yaml+file://{service}.dedicated_apps.{token_type.value}",
)
return Token(key=actual_token, username=f"{token_type.value}_dedicated_app")

Copy link
Contributor

Choose a reason for hiding this comment

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

I know it's implicit (by not having a return statement) that we return None if we don't go through the if statement, but I think it'll be more readable if we have an explicit return None here.

Comment on lines 82 to 83
# TokenType.read has a dedicated app AND bot.
# Dedicated app is preferred.
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment will be even more useful as a docstring on the get_token_type_from_config function.

Also, for purposes of test clarity and documentation maintenance, how do you feel about turning each of these asserts into their own parametrize tests (with id annotation). If we fail this test here, we will only be notified for the first test that failed (and you'll have to rerun to get other failures/passes). It'll be more convenient to have the test status for all these checks run regardless of which one failed, especially since each of these asserts seem to be testing different usescases.

):
mock_configuration.set_params(
{
"github": {
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks almost duplicated from the params set in the next test. Can we turn this dict into a fixture? (docs for fixtures)

Copy link
Contributor

@michelletran-codecov michelletran-codecov left a comment

Choose a reason for hiding this comment

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

LGTM!

@giovanni-guidini giovanni-guidini added this pull request to the merge queue Jun 10, 2024
Merged via the queue into main with commit fa2ddab Jun 10, 2024
28 of 30 checks passed
@giovanni-guidini giovanni-guidini deleted the gio/map-dedicated-apps-to-tokentype branch June 10, 2024 14:18
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.

3 participants