Skip to content

Commit

Permalink
Miscellaneous cleanup (#149)
Browse files Browse the repository at this point in the history
* Miscellaneous cleanup

Signed-off-by: William Woodruff <[email protected]>

* ambient: missing annotations import

Signed-off-by: William Woodruff <[email protected]>

---------

Signed-off-by: William Woodruff <[email protected]>
  • Loading branch information
woodruffw authored Dec 13, 2023
1 parent 74c3fe0 commit fedbdb4
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 35 deletions.
10 changes: 0 additions & 10 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
version: 2

updates:
- package-ecosystem: pip
directory: "/install"
schedule:
interval: daily
open-pull-requests-limit: 99
allow:
- dependency-type: direct
- dependency-type: indirect
rebase-strategy: "disabled"

- package-ecosystem: pip
directory: /
schedule:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
- name: publish
uses: pypa/gh-action-pypi-publish@2f6f737ca5f74c637829c0f5c3acd0e29ea5e8bf # v1.8.11
with:
packages_dir: built-packages/
packages-dir: built-packages/

release-github:
needs: [build, generate-provenance]
Expand Down
6 changes: 3 additions & 3 deletions id/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from __future__ import annotations

from typing import Callable, List, Optional
from typing import Callable

__version__ = "1.2.1"

Expand Down Expand Up @@ -49,7 +49,7 @@ class GitHubOidcPermissionCredentialError(AmbientCredentialError):
pass


def detect_credential(audience: str) -> Optional[str]:
def detect_credential(audience: str) -> str | None:
"""
Try each ambient credential detector, returning the first one to succeed
or `None` if all fail.
Expand All @@ -65,7 +65,7 @@ def detect_credential(audience: str) -> Optional[str]:
detect_gitlab,
)

detectors: List[Callable[..., Optional[str]]] = [
detectors: list[Callable[..., str | None]] = [
detect_github,
detect_gcp,
detect_buildkite,
Expand Down
19 changes: 9 additions & 10 deletions id/_internal/oidc/ambient.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
Ambient OIDC credential detection.
"""

from __future__ import annotations

import json
import logging
import os
import re
import shutil
import subprocess # nosec B404
from typing import Optional

import requests
from pydantic import BaseModel, StrictStr
Expand Down Expand Up @@ -55,7 +56,7 @@ class _GitHubTokenPayload(BaseModel):
value: StrictStr


def detect_github(audience: str) -> Optional[str]:
def detect_github(audience: str) -> str | None:
"""
Detect and return a GitHub Actions ambient OIDC credential.
Expand Down Expand Up @@ -113,7 +114,7 @@ def detect_github(audience: str) -> Optional[str]:
return payload.value


def detect_gcp(audience: str) -> Optional[str]:
def detect_gcp(audience: str) -> str | None:
"""
Detect an return a Google Cloud Platform ambient OIDC credential.
Expand Down Expand Up @@ -214,7 +215,7 @@ def detect_gcp(audience: str) -> Optional[str]:
return resp.text


def detect_buildkite(audience: str) -> Optional[str]:
def detect_buildkite(audience: str) -> str | None:
"""
Detect and return a Buildkite ambient OIDC credential.
Expand Down Expand Up @@ -253,8 +254,7 @@ def detect_buildkite(audience: str) -> Optional[str]:
# we can do about this.
process = subprocess.run( # nosec B603, B607
["buildkite-agent", "oidc", "request-token", "--audience", audience],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
capture_output=True,
text=True,
)

Expand All @@ -266,7 +266,7 @@ def detect_buildkite(audience: str) -> Optional[str]:
return process.stdout.strip()


def detect_gitlab(audience: str) -> Optional[str]:
def detect_gitlab(audience: str) -> str | None:
"""
Detect and return a GitLab CI/CD ambient OIDC credential.
Expand Down Expand Up @@ -301,7 +301,7 @@ def detect_gitlab(audience: str) -> Optional[str]:
return token


def detect_circleci(audience: str) -> Optional[str]:
def detect_circleci(audience: str) -> str | None:
"""
Detect and return a CircleCI ambient OIDC credential.
Expand All @@ -324,8 +324,7 @@ def detect_circleci(audience: str) -> Optional[str]:
payload = json.dumps({"aud": audience})
process = subprocess.run( # nosec B603, B607
["circleci", "run", "oidc", "get", "--claims", payload],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
capture_output=True,
text=True,
)

Expand Down
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,4 @@ exclude_dirs = ["./test"]

[tool.ruff]
line-length = 100
# TODO: Enable "UP" here once Pydantic allows us to:
# See: https://github.com/pydantic/pydantic/issues/4146
select = ["I", "E", "F", "W"]
select = ["I", "E", "F", "W", "UP"]
12 changes: 4 additions & 8 deletions test/unit/internal/oidc/test_ambient.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,7 @@ def test_buildkite_agent_error(monkeypatch):
assert subprocess.run.calls == [
pretend.call(
["buildkite-agent", "oidc", "request-token", "--audience", "some-audience"],
stdout=None,
stderr=None,
capture_output=True,
text=True,
)
]
Expand All @@ -600,8 +599,7 @@ def test_buildkite(monkeypatch):
assert subprocess.run.calls == [
pretend.call(
["buildkite-agent", "oidc", "request-token", "--audience", "some-audience"],
stdout=None,
stderr=None,
capture_output=True,
text=True,
)
]
Expand Down Expand Up @@ -724,8 +722,7 @@ def test_circleci_circlecli_error(monkeypatch):
assert subprocess.run.calls == [
pretend.call(
["circleci", "run", "oidc", "get", "--claims", payload],
stdout=None,
stderr=None,
capture_output=True,
text=True,
)
]
Expand All @@ -752,8 +749,7 @@ def test_circleci(monkeypatch):
assert subprocess.run.calls == [
pretend.call(
["circleci", "run", "oidc", "get", "--claims", payload],
stdout=None,
stderr=None,
capture_output=True,
text=True,
)
]

0 comments on commit fedbdb4

Please sign in to comment.