Skip to content

sigstore: uniform user-agent with sigstore version #1008

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

Merged
merged 4 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions sigstore/_internal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@
Everything in these APIs is considered internal and unstable, and is not
subject to any stability guarantees.
"""

from requests import __version__ as requests_version

from sigstore import __version__ as sigstore_version

USER_AGENT = f"sigstore-python/{sigstore_version} (python-requests/{requests_version})"
6 changes: 6 additions & 0 deletions sigstore/_internal/fulcio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
)
from pydantic import BaseModel, ConfigDict, Field, field_validator

from sigstore._internal import USER_AGENT
from sigstore._internal.sct import (
UnexpectedSctCountException,
_get_precertificate_signed_certificate_timestamps,
Expand Down Expand Up @@ -338,6 +339,11 @@ def __init__(self, url: str = DEFAULT_FULCIO_URL) -> None:
_logger.debug(f"Fulcio client using URL: {url}")
self.url = url
self.session = requests.Session()
self.session.headers.update(
{
"User-Agent": USER_AGENT,
}
)

def __del__(self) -> None:
"""
Expand Down
7 changes: 6 additions & 1 deletion sigstore/_internal/rekor/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import rekor_types
import requests

from sigstore._internal import USER_AGENT
from sigstore.models import LogEntry

_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -228,7 +229,11 @@ def __init__(self, url: str) -> None:
self.url = urljoin(url, "api/v1/")
self.session = requests.Session()
self.session.headers.update(
{"Content-Type": "application/json", "Accept": "application/json"}
{
"Content-Type": "application/json",
"Accept": "application/json",
"User-Agent": USER_AGENT,
}
)

def __del__(self) -> None:
Expand Down
8 changes: 6 additions & 2 deletions sigstore/oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import requests
from pydantic import BaseModel, StrictStr

from sigstore._internal import USER_AGENT
from sigstore.errors import Error, NetworkError

DEFAULT_OAUTH_ISSUER_URL = "https://oauth2.sigstore.dev/auth"
Expand Down Expand Up @@ -255,12 +256,15 @@ def __init__(self, base_url: str) -> None:
which is then used to bootstrap the issuer's state (such
as authorization and token endpoints).
"""
self.session = requests.Session()
self.session.headers.update({"User-Agent": USER_AGENT})

oidc_config_url = urllib.parse.urljoin(
f"{base_url}/", ".well-known/openid-configuration"
)

try:
resp: requests.Response = requests.get(oidc_config_url, timeout=30)
resp: requests.Response = self.session.get(oidc_config_url, timeout=30)
except (requests.ConnectionError, requests.Timeout) as exc:
raise NetworkError from exc

Expand Down Expand Up @@ -352,7 +356,7 @@ def identity_token( # nosec: B107
)
logging.debug(f"PAYLOAD: data={data}")
try:
resp: requests.Response = requests.post(
resp = self.session.post(
self.oidc_config.token_endpoint,
data=data,
auth=auth,
Expand Down
Loading