Skip to content

Commit

Permalink
Allow JWT tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
zetaab authored and scott-codecov committed Nov 3, 2023
1 parent 0112aad commit 77468b1
Show file tree
Hide file tree
Showing 21 changed files with 20 additions and 57 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ Codecov-cli supports user input. These inputs, along with their descriptions and
| :---: | :---: | :---: |
| -C, --sha, --commit-sha TEXT |Commit SHA (with 40 chars) | Required
| -r, --slug TEXT |owner/repo slug used instead of the private repo token in Self-hosted | Required
| -t, --token UUID |Codecov upload token | Required
| -t, --token TEXT |Codecov upload token | Required
| --git-service | Git provider. Options: github, gitlab, bitbucket, github_enterprise, gitlab_enterprise, bitbucket_server | Optional
| -h,--help |Show this message and exit.

Expand Down
4 changes: 1 addition & 3 deletions codecov_cli/commands/base_picking.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
import typing
import uuid

import click

Expand Down Expand Up @@ -36,7 +35,6 @@
"-t",
"--token",
help="Codecov upload token",
type=click.UUID,
envvar="CODECOV_TOKEN",
)
@click.option(
Expand All @@ -51,7 +49,7 @@ def pr_base_picking(
base_sha: str,
pr: typing.Optional[int],
slug: typing.Optional[str],
token: typing.Optional[uuid.UUID],
token: typing.Optional[str],
service: typing.Optional[str],
):
enterprise_url = ctx.obj.get("enterprise_url")
Expand Down
3 changes: 1 addition & 2 deletions codecov_cli/commands/commit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
import typing
import uuid

import click

Expand Down Expand Up @@ -42,7 +41,7 @@ def create_commit(
pull_request_number: typing.Optional[int],
branch: typing.Optional[str],
slug: typing.Optional[str],
token: typing.Optional[uuid.UUID],
token: typing.Optional[str],
git_service: typing.Optional[str],
fail_on_error: bool,
):
Expand Down
5 changes: 1 addition & 4 deletions codecov_cli/commands/create_report_result.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import logging
import uuid

import click

from codecov_cli.fallbacks import CodecovOption, FallbackFieldEnum
from codecov_cli.helpers.git import GitService
from codecov_cli.helpers.options import global_options
from codecov_cli.services.report import create_report_results_logic

Expand All @@ -23,7 +20,7 @@ def create_report_results(
code: str,
slug: str,
git_service: str,
token: uuid.UUID,
token: str,
fail_on_error: bool,
):
enterprise_url = ctx.obj.get("enterprise_url")
Expand Down
3 changes: 1 addition & 2 deletions codecov_cli/commands/empty_upload.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
import typing
import uuid

import click

Expand All @@ -19,7 +18,7 @@ def empty_upload(
ctx,
commit_sha: str,
slug: typing.Optional[str],
token: typing.Optional[uuid.UUID],
token: typing.Optional[str],
git_service: typing.Optional[str],
fail_on_error: typing.Optional[bool],
):
Expand Down
3 changes: 1 addition & 2 deletions codecov_cli/commands/get_report_results.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import uuid

import click

Expand All @@ -24,7 +23,7 @@ def get_report_results(
code: str,
slug: str,
git_service: str,
token: uuid.UUID,
token: str,
fail_on_error: bool,
):
enterprise_url = ctx.obj.get("enterprise_url")
Expand Down
5 changes: 1 addition & 4 deletions codecov_cli/commands/report.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import logging
import uuid

import click

from codecov_cli.fallbacks import CodecovOption, FallbackFieldEnum
from codecov_cli.helpers.git import GitService
from codecov_cli.helpers.options import global_options
from codecov_cli.services.report import create_report_logic

Expand All @@ -23,7 +20,7 @@ def create_report(
code: str,
slug: str,
git_service: str,
token: uuid.UUID,
token: str,
fail_on_error: bool,
):
enterprise_url = ctx.obj.get("enterprise_url")
Expand Down
3 changes: 1 addition & 2 deletions codecov_cli/commands/send_notifications.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
import typing
import uuid

import click

Expand All @@ -19,7 +18,7 @@ def send_notifications(
ctx,
commit_sha: str,
slug: typing.Optional[str],
token: typing.Optional[uuid.UUID],
token: typing.Optional[str],
git_service: typing.Optional[str],
fail_on_error: bool,
):
Expand Down
3 changes: 1 addition & 2 deletions codecov_cli/commands/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
import pathlib
import typing
import uuid

import click

Expand Down Expand Up @@ -185,7 +184,7 @@ def do_upload(
coverage_files_search_explicitly_listed_files: typing.List[pathlib.Path],
disable_search: bool,
disable_file_fixes: bool,
token: typing.Optional[uuid.UUID],
token: typing.Optional[str],
plugin_names: typing.List[str],
branch: typing.Optional[str],
slug: typing.Optional[str],
Expand Down
3 changes: 1 addition & 2 deletions codecov_cli/commands/upload_process.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
import pathlib
import typing
import uuid

import click

Expand Down Expand Up @@ -38,7 +37,7 @@ def upload_process(
coverage_files_search_explicitly_listed_files: typing.List[pathlib.Path],
disable_search: bool,
disable_file_fixes: bool,
token: typing.Optional[uuid.UUID],
token: typing.Optional[str],
plugin_names: typing.List[str],
branch: typing.Optional[str],
slug: typing.Optional[str],
Expand Down
1 change: 0 additions & 1 deletion codecov_cli/helpers/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"-t",
"--token",
help="Codecov upload token",
type=click.UUID,
envvar="CODECOV_TOKEN",
),
click.option(
Expand Down
5 changes: 1 addition & 4 deletions codecov_cli/helpers/request.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import uuid
from time import sleep

import click
Expand Down Expand Up @@ -45,13 +44,11 @@ def send_post_request(
return request_result(resp)


def get_token_header_or_fail(token: uuid.UUID) -> dict:
def get_token_header_or_fail(token: str) -> dict:
if token is None:
raise click.ClickException(
"Codecov token not found. Please provide Codecov token with -t flag."
)
if not isinstance(token, uuid.UUID):
raise click.ClickException(f"Token must be UUID. Received {type(token)}")
return {"Authorization": f"token {token.hex}"}


Expand Down
3 changes: 1 addition & 2 deletions codecov_cli/services/commit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
import typing
import uuid

from codecov_cli.helpers.config import CODECOV_API_URL
from codecov_cli.helpers.encoder import encode_slug
Expand All @@ -19,7 +18,7 @@ def create_commit_logic(
pr: typing.Optional[str],
branch: typing.Optional[str],
slug: typing.Optional[str],
token: uuid.UUID,
token: str,
service: typing.Optional[str],
enterprise_url: typing.Optional[str] = None,
fail_on_error: bool = False,
Expand Down
8 changes: 2 additions & 6 deletions codecov_cli/services/report/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import json
import logging
import time
import typing
import uuid

import requests

from codecov_cli.helpers.config import CODECOV_API_URL
from codecov_cli.helpers.encoder import encode_slug
Expand All @@ -24,7 +20,7 @@ def create_report_logic(
code: str,
slug: str,
service: str,
token: uuid.UUID,
token: str,
enterprise_url: str,
fail_on_error: bool = False,
):
Expand All @@ -51,7 +47,7 @@ def create_report_results_logic(
code: str,
slug: str,
service: str,
token: uuid.UUID,
token: str,
enterprise_url: str,
fail_on_error: bool = False,
):
Expand Down
3 changes: 1 addition & 2 deletions codecov_cli/services/upload/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
import typing
import uuid
from pathlib import Path

import click
Expand Down Expand Up @@ -39,7 +38,7 @@ def do_upload_logic(
coverage_files_search_exclude_folders: typing.List[Path],
coverage_files_search_explicitly_listed_files: typing.List[Path],
plugin_names: typing.List[str],
token: uuid.UUID,
token: str,
branch: typing.Optional[str],
slug: typing.Optional[str],
pull_request_number: typing.Optional[str],
Expand Down
5 changes: 1 addition & 4 deletions codecov_cli/services/upload/legacy_upload_sender.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import logging
import typing
import uuid
from dataclasses import dataclass

import requests

from codecov_cli import __version__ as codecov_cli_version
from codecov_cli.helpers.config import LEGACY_CODECOV_API_URL
from codecov_cli.helpers.request import send_post_request, send_put_request
Expand Down Expand Up @@ -39,7 +36,7 @@ def send_upload_data(
self,
upload_data: UploadCollectionResult,
commit_sha: str,
token: uuid.UUID,
token: str,
env_vars: typing.Dict[str, str],
report_code: str = None,
name: typing.Optional[str] = None,
Expand Down
3 changes: 1 addition & 2 deletions codecov_cli/services/upload/upload_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import json
import logging
import typing
import uuid
import zlib
from typing import Any, Dict

Expand All @@ -28,7 +27,7 @@ def send_upload_data(
self,
upload_data: UploadCollectionResult,
commit_sha: str,
token: uuid.UUID,
token: str,
env_vars: typing.Dict[str, str],
report_code: str,
name: typing.Optional[str] = None,
Expand Down
2 changes: 1 addition & 1 deletion tests/commands/test_invoke_upload_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_upload_process_options(mocker):
" -C, --sha, --commit-sha TEXT Commit SHA (with 40 chars) [required]",
" -Z, --fail-on-error Exit with non-zero code in case of error",
" --git-service [github|gitlab|bitbucket|github_enterprise|gitlab_enterprise|bitbucket_server]",
" -t, --token UUID Codecov upload token",
" -t, --token TEXT Codecov upload token",
" -r, --slug TEXT owner/repo slug used instead of the private",
" repo token in Self-hosted",
" --report-code TEXT The code of the report. If unsure, leave",
Expand Down
3 changes: 1 addition & 2 deletions tests/helpers/test_legacy_upload_sender.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import uuid
from urllib import parse

import pytest
Expand All @@ -11,7 +10,7 @@
from tests.data import reports_examples

upload_collection = UploadCollectionResult(["1", "apple.py", "3"], [], [])
random_token = uuid.UUID("f359afb9-8a2a-42ab-a448-c3d267ff495b")
random_token = "f359afb9-8a2a-42ab-a448-c3d267ff495b"
random_sha = "845548c6b95223f12e8317a1820705f64beaf69e"
named_upload_data = {
"name": "name",
Expand Down
7 changes: 0 additions & 7 deletions tests/helpers/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,6 @@ def test_get_token_header_or_fail():
== "Codecov token not found. Please provide Codecov token with -t flag."
)

# Test with an invalid token type
token = "invalid_token"
with pytest.raises(Exception) as e:
get_token_header_or_fail(token)

assert str(e.value) == f"Token must be UUID. Received {type(token)}"


def test_request_retry(mocker, valid_response):
expected_response = request_result(valid_response)
Expand Down
3 changes: 1 addition & 2 deletions tests/helpers/test_upload_sender.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
import uuid
from pathlib import Path

import pytest
Expand All @@ -13,7 +12,7 @@
from tests.data import reports_examples

upload_collection = UploadCollectionResult(["1", "apple.py", "3"], [], [])
random_token = uuid.UUID("f359afb9-8a2a-42ab-a448-c3d267ff495b")
random_token = "f359afb9-8a2a-42ab-a448-c3d267ff495b"
random_sha = "845548c6b95223f12e8317a1820705f64beaf69e"
named_upload_data = {
"report_code": "report_code",
Expand Down

0 comments on commit 77468b1

Please sign in to comment.