Skip to content
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
23 changes: 9 additions & 14 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ orbs:
poetry: talkiq/poetry@4.2.0

executors:
python39:
docker:
- image: python:3.9.19
resource_class: small

python310:
docker:
- image: python:3.10.14
Expand Down Expand Up @@ -63,7 +58,7 @@ jobs:
steps:
- poetry/install:
# renovate: datasource=pypi depName=poetry
version: 2.2.1
version: 2.3.1
- checkout
- run: ./bin/build-rest
- store-rest
Expand All @@ -82,7 +77,7 @@ jobs:
steps:
- poetry/install:
# renovate: datasource=pypi depName=poetry
version: 2.2.1
version: 2.3.1
- checkout
- attach_workspace:
at: /rest
Expand Down Expand Up @@ -170,7 +165,7 @@ workflows:
- linter/pre-commit:
# N.B. keep this pinned to the oldest 3.x to make sure we maintain
# support.
executor: python39
executor: python310
filters:
tags:
only: /.*/
Expand All @@ -184,12 +179,12 @@ workflows:
working_directory: <<matrix.cwd>>
install_flags: --no-ansi
# renovate: datasource=pypi depName=poetry
version: 2.2.1
version: 2.3.1
matrix:
alias: test-unit-aio
parameters:
cwd: [auth, bigquery, datastore, kms, pubsub, storage, taskqueue]
executor: [python39, python310, python311, python312]
executor: [python310, python311, python312]
filters:
tags:
only: /.*/
Expand All @@ -202,7 +197,7 @@ workflows:
executor: python-integration
install_flags: --no-ansi
# renovate: datasource=pypi depName=poetry
version: 2.2.1
version: 2.3.1
pre-steps:
- run: echo "${GOOGLE_SERVICE_PUBLIC}" | base64 -d > "${GOOGLE_APPLICATION_CREDENTIALS}"
matrix:
Expand All @@ -220,15 +215,15 @@ workflows:
working_directory: <<matrix.cwd>>
install_flags: --no-ansi
# renovate: datasource=pypi depName=poetry
version: 2.2.1
version: 2.3.1
pre-steps:
- attach_workspace:
at: /rest
matrix:
alias: test-unit-rest
parameters:
cwd: [/rest/auth, /rest/bigquery, /rest/datastore, /rest/kms, /rest/pubsub, /rest/storage, /rest/taskqueue]
executor: [python39, python310, python311, python312]
executor: [python310, python311, python312]
filters:
tags:
only: /.*/
Expand All @@ -243,7 +238,7 @@ workflows:
executor: python-integration
install_flags: --no-ansi
# renovate: datasource=pypi depName=poetry
version: 2.2.1
version: 2.3.1
pre-steps:
- run: echo ${GOOGLE_SERVICE_PUBLIC} | base64 -d > "${GOOGLE_APPLICATION_CREDENTIALS}"
- attach_workspace:
Expand Down
15 changes: 8 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ci:
autoupdate_commit_msg: 'chore(deps): bump pre-commit linter versions'

default_language_version:
python: python3.9
python: python3.10

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down Expand Up @@ -68,12 +68,12 @@ repos:
rev: v3.16.0
hooks:
- id: reorder-python-imports
args: [--py38-plus]
args: [--py310-plus]
- repo: https://github.com/asottile/pyupgrade
rev: v3.21.0
rev: v3.21.2
hooks:
- id: pyupgrade
args: [--py38-plus]
args: [--py310-plus]
# TODO: enable me
# - repo: https://github.com/asottile/add-trailing-comma
# rev: v3.1.0
Expand Down Expand Up @@ -173,7 +173,8 @@ repos:
- id: flake8
additional_dependencies: *flake8deps
args:
- --ignore=E501,W503,F401,F811
# TODO: fix A005
- --ignore=A005,E501,W503,F401,F811
- repo: local
hooks:
- id: poetry-check
Expand All @@ -182,7 +183,7 @@ repos:
entry: bash -c 'set -e; for toml in "$@"; do pushd ./${toml%pyproject.toml}; poetry check; popd; done' --
language: python
additional_dependencies:
- poetry==2.2.1
- poetry==2.3.1
pass_filenames: true
files: 'pyproject\.toml$'
- id: poetry-use-version-ranges
Expand Down Expand Up @@ -219,4 +220,4 @@ repos:
- id: check-renovate
language: python
additional_dependencies:
- pyjson5==1.6.9
- pyjson5==2.0.0
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 TalkIQ

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
50 changes: 23 additions & 27 deletions auth/gcloud/aio/auth/iam.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import json
from typing import Any
from typing import AnyStr
from typing import Dict
from typing import IO
from typing import List
from typing import Optional
from typing import Union

from .build_constants import BUILD_GCLOUD_REST
from .session import AioSession
Expand All @@ -26,9 +22,9 @@

class IamClient:
def __init__(
self, service_file: Optional[Union[str, IO[AnyStr]]] = None,
session: Optional[Session] = None,
token: Optional[Token] = None,
self, service_file: str | IO[AnyStr] | None = None,
session: Session | None = None,
token: Token | None = None,
) -> None:
self.session = AioSession(session)
self.token = token or Token(
Expand All @@ -45,25 +41,25 @@ def __init__(
'with Service Accounts or GCE Metadata',
)

async def headers(self) -> Dict[str, str]:
async def headers(self) -> dict[str, str]:
token = await self.token.get()
return {
'Authorization': f'Bearer {token}',
}

@property
def service_account_email(self) -> Optional[str]:
def service_account_email(self) -> str | None:
return self.token.service_data.get('client_email')

# https://cloud.google.com/iam/reference/rest/v1/projects.serviceAccounts.keys/get
async def get_public_key(
self, key_id: Optional[str] = None,
key: Optional[str] = None,
service_account_email: Optional[str] = None,
project: Optional[str] = None,
session: Optional[Session] = None,
self, key_id: str | None = None,
key: str | None = None,
service_account_email: str | None = None,
project: str | None = None,
session: Session | None = None,
timeout: int = 10,
) -> Dict[str, str]:
) -> dict[str, str]:
service_account_email = (
service_account_email
or self.service_account_email
Expand All @@ -86,16 +82,16 @@ async def get_public_key(

resp = await s.get(url=url, headers=headers, timeout=timeout)

data: Dict[str, str] = await resp.json()
data: dict[str, str] = await resp.json()
return data

# https://cloud.google.com/iam/reference/rest/v1/projects.serviceAccounts.keys/list
async def list_public_keys(
self, service_account_email: Optional[str] = None,
project: Optional[str] = None,
session: Optional[Session] = None,
self, service_account_email: str | None = None,
project: str | None = None,
session: Session | None = None,
timeout: int = 10,
) -> List[Dict[str, str]]:
) -> list[dict[str, str]]:
service_account_email = (
service_account_email
or self.service_account_email
Expand All @@ -113,17 +109,17 @@ async def list_public_keys(

resp = await s.get(url=url, headers=headers, timeout=timeout)

data: List[Dict[str, Any]] = (await resp.json()).get('keys', [])
data: list[dict[str, Any]] = (await resp.json()).get('keys', [])
return data

# https://cloud.google.com/iam/credentials/reference/rest/v1/projects.serviceAccounts/signBlob
async def sign_blob(
self, payload: Optional[Union[str, bytes]],
service_account_email: Optional[str] = None,
delegates: Optional[List[str]] = None,
session: Optional[Session] = None,
self, payload: str | bytes | None,
service_account_email: str | None = None,
delegates: list[str] | None = None,
session: Session | None = None,
timeout: int = 10,
) -> Dict[str, str]:
) -> dict[str, str]:
service_account_email = (
service_account_email
or self.service_account_email
Expand Down Expand Up @@ -154,7 +150,7 @@ async def sign_blob(
url=url, data=json_str, headers=headers,
timeout=timeout,
)
data: Dict[str, Any] = await resp.json()
data: dict[str, Any] = await resp.json()
return data

async def close(self) -> None:
Expand Down
Loading