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
40 changes: 19 additions & 21 deletions archivist/access_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@

"""

from __future__ import annotations

from copy import deepcopy
from logging import getLogger
from typing import TYPE_CHECKING, Any, Generator, Optional
from typing import TYPE_CHECKING, Any, Generator

# pylint:disable=cyclic-import # but pylint doesn't understand this feature

Expand All @@ -47,7 +45,7 @@ class AccessPolicy(dict):
"""AccessPolicy object"""

@property
def name(self) -> str | None:
def name(self) -> "str | None":
"""str: name of the access policy"""
return self.get("display_name")

Expand All @@ -63,7 +61,7 @@ class _AccessPoliciesClient:

"""

def __init__(self, archivist_instance: Archivist):
def __init__(self, archivist_instance: "Archivist"):
self._archivist = archivist_instance
self._subpath = f"{archivist_instance.root}/{ACCESS_POLICIES_SUBPATH}"
self._label = f"{self._subpath}/{ACCESS_POLICIES_LABEL}"
Expand All @@ -73,9 +71,9 @@ def __str__(self) -> str:

def create(
self,
props: dict[str, Any],
filters: list[dict[str, Any]],
access_permissions: list[dict[str, Any]],
props: "dict[str, Any]",
filters: "list[dict[str, Any]]",
access_permissions: "list[dict[str, Any]]",
) -> AccessPolicy:
"""Create access policy

Expand All @@ -97,7 +95,7 @@ def create(
),
)

def create_from_data(self, data: dict[str, Any]) -> AccessPolicy:
def create_from_data(self, data: "dict[str, Any]") -> AccessPolicy:
"""Create access policy

Creates access policy with request body from data stream.
Expand Down Expand Up @@ -135,9 +133,9 @@ def update(
self,
identity,
*,
props: Optional[dict[str, Any]] = None,
filters: Optional[list[dict]] = None,
access_permissions: Optional[list[dict]] = None,
props: "dict[str, Any] | None " = None,
filters: "list[dict] | None " = None,
access_permissions: "list[dict] | None " = None,
) -> AccessPolicy:
"""Update Access Policy

Expand All @@ -162,7 +160,7 @@ def update(
)
)

def delete(self, identity: str) -> dict[str, Any]:
def delete(self, identity: str) -> "dict[str, Any]":
"""Delete Access Policy

Deletes access policy.
Expand All @@ -178,11 +176,11 @@ def delete(self, identity: str) -> dict[str, Any]:

def __params(
self,
props: Optional[dict[str, Any]],
props: "dict[str, Any] | None",
*,
filters: list[dict] | None = None,
access_permissions: list[dict] | None = None,
) -> dict[str, Any]:
filters: "list[dict] | None" = None,
access_permissions: "list[dict] | None" = None,
) -> "dict[str, Any]":
params = deepcopy(props) if props else {}
if filters is not None:
params["filters"] = filters
Expand All @@ -192,7 +190,7 @@ def __params(

return _deepmerge(self._archivist.fixtures.get(ACCESS_POLICIES_LABEL), params)

def count(self, *, display_name: Optional[str] = None) -> int:
def count(self, *, display_name: "str | None" = None) -> int:
"""Count access policies.

Counts number of access policies that match criteria.
Expand All @@ -208,7 +206,7 @@ def count(self, *, display_name: Optional[str] = None) -> int:
return self._archivist.count(self._label, params=params)

def list(
self, *, page_size: Optional[int] = None, display_name: Optional[str] = None
self, *, page_size: "int|None" = None, display_name: "str|None" = None
) -> Generator[AccessPolicy, None, None]:
"""List access policies.

Expand All @@ -235,7 +233,7 @@ def list(

# additional queries on different endpoints
def list_matching_assets(
self, access_policy_id: str, *, page_size: Optional[int] = None
self, access_policy_id: str, *, page_size: "int|None" = None
) -> Generator[Asset, None, None]:
"""List matching assets.

Expand All @@ -259,7 +257,7 @@ def list_matching_assets(
)

def list_matching_access_policies(
self, asset_id: str, *, page_size: Optional[int] = None
self, asset_id: str, *, page_size: "int|None" = None
) -> Generator[AccessPolicy, None, None]:
"""List matching access policies.

Expand Down
4 changes: 1 addition & 3 deletions archivist/appidp.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

"""

from __future__ import annotations

from logging import getLogger
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -57,7 +55,7 @@ class _AppIDPClient:

"""

def __init__(self, archivist_instance: Archivist):
def __init__(self, archivist_instance: "Archivist"):
self._archivist = archivist_instance
self._subpath = f"{archivist_instance.root}/{APPIDP_SUBPATH}"
self._label = f"{self._subpath}/{APPIDP_LABEL}"
Expand Down
26 changes: 12 additions & 14 deletions archivist/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@

"""

from __future__ import annotations

from logging import getLogger
from typing import TYPE_CHECKING, Any, Optional
from typing import TYPE_CHECKING, Any

# pylint:disable=cyclic-import # but pylint doesn't understand this feature
if TYPE_CHECKING:
Expand Down Expand Up @@ -55,15 +53,15 @@ class _ApplicationsClient:

"""

def __init__(self, archivist_instance: Archivist):
def __init__(self, archivist_instance: "Archivist"):
self._archivist = archivist_instance
self._subpath = f"{archivist_instance.root}/{APPLICATIONS_SUBPATH}"
self._label = f"{self._subpath}/{APPLICATIONS_LABEL}"

def __str__(self) -> str:
return f"ApplicationsClient({self._archivist.url})"

def create(self, display_name: str, custom_claims: dict[str, str]) -> Application:
def create(self, display_name: str, custom_claims: "dict[str, str]") -> Application:
"""Create application

Creates application with defined attributes.
Expand All @@ -84,7 +82,7 @@ def create(self, display_name: str, custom_claims: dict[str, str]) -> Applicatio
),
)

def create_from_data(self, data: dict[str, Any]) -> Application:
def create_from_data(self, data: "dict[str, Any]") -> Application:
"""Create application

Creates application with request body from data stream.
Expand Down Expand Up @@ -117,8 +115,8 @@ def update(
self,
identity: str,
*,
display_name: Optional[str] = None,
custom_claims: Optional[dict[str, str]] = None,
display_name: "str|None" = None,
custom_claims: "dict[str,str]|None" = None,
) -> Application:
"""Update Application

Expand All @@ -143,7 +141,7 @@ def update(
)
)

def delete(self, identity: str) -> dict[str, Any]:
def delete(self, identity: str) -> "dict[str, Any]":
"""Delete Application

Deletes application.
Expand All @@ -160,9 +158,9 @@ def delete(self, identity: str) -> dict[str, Any]:
def __params(
self,
*,
display_name: Optional[str] = None,
custom_claims: Optional[dict[str, str]] = None,
) -> dict[str, Any]:
display_name: "str|None" = None,
custom_claims: "dict[str,str] | None" = None,
) -> "dict[str, Any]":
params = {}

if display_name is not None:
Expand All @@ -176,8 +174,8 @@ def __params(
def list(
self,
*,
page_size: Optional[int] = None,
display_name: Optional[str] = None,
page_size: "int|None" = None,
display_name: "str|None" = None,
):
"""List applications.

Expand Down
38 changes: 18 additions & 20 deletions archivist/archivist.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@
attachments, IAM subjects and IAM access policies documented elsewhere.

"""
from __future__ import annotations

from copy import deepcopy
from logging import getLogger
from time import time
from typing import Any, BinaryIO, Optional, Tuple
from typing import Any, BinaryIO

from requests_toolbelt.multipart.encoder import MultipartEncoder

Expand Down Expand Up @@ -104,9 +102,9 @@ class Archivist(ArchivistPublic): # pylint: disable=too-many-instance-attribute
def __init__(
self,
url: str,
auth: str | Tuple[str, str] | None,
auth: "str|tuple[str,str]|None",
*,
fixtures: Optional[dict[str, dict[Any, Any]]] = None,
fixtures: "dict[str,dict[Any,Any]]|None" = None,
verify: bool = True,
max_time: float = MAX_TIME,
):
Expand Down Expand Up @@ -183,7 +181,7 @@ def root(self) -> str:
return self._root

@property
def auth(self) -> str | None:
def auth(self) -> "str | None":
"""str: authorization token"""

if self._auth is None and self._machine_auth is None:
Expand All @@ -208,7 +206,7 @@ def Public(self) -> ArchivistPublic: # pylint: disable=invalid-name
max_time=self._max_time,
)

def __copy__(self) -> Archivist:
def __copy__(self) -> "Archivist":
return Archivist(
self._url,
self.auth,
Expand All @@ -217,7 +215,7 @@ def __copy__(self) -> Archivist:
max_time=self._max_time,
)

def _add_headers(self, headers: dict[str, str] | None) -> dict[str, Any]:
def _add_headers(self, headers: "dict[str,str]|None") -> "dict[str,Any]":
newheaders = {**headers} if isinstance(headers, dict) else {}

auth = self.auth # this may trigger a refetch so only do it once here
Expand All @@ -233,11 +231,11 @@ def _add_headers(self, headers: dict[str, str] | None) -> dict[str, Any]:
def post(
self,
url: str,
request: dict[str, Any] | None,
request: "dict[str,Any]|None",
*,
headers: Optional[dict[str, Any]] = None,
data: dict[str, Any] | bool = False,
) -> dict[str, Any]:
headers: "dict[str,Any]|None" = None,
data: "dict[str, Any] | bool" = False,
) -> "dict[str, Any]":
"""POST method (REST)

Creates an entity
Expand Down Expand Up @@ -276,11 +274,11 @@ def post_file(
self,
url: str,
fd: BinaryIO,
mtype: str | None,
mtype: "str|None",
*,
form: str = "file",
params: Optional[dict] = None,
) -> dict[str, Any]:
params: "dict[str, Any]|None" = None,
) -> "dict[str, Any]":
"""POST method (REST) - upload binary

Uploads a file to an endpoint
Expand Down Expand Up @@ -321,8 +319,8 @@ def post_file(

@retry_429
def delete(
self, url: str, *, headers: Optional[dict[str, Any]] = None
) -> dict[str, Any]:
self, url: str, *, headers: "dict[str, Any]|None" = None
) -> "dict[str, Any]":
"""DELETE method (REST)

Deletes an entity
Expand Down Expand Up @@ -352,10 +350,10 @@ def delete(
def patch(
self,
url: str,
request: dict[str, Any],
request: "dict[str, Any]",
*,
headers: Optional[dict[str, Any]] = None,
) -> dict[str, Any]:
headers: "dict[str, Any]| None" = None,
) -> "dict[str, Any]":
"""PATCH method (REST)

Updates the specified entity.
Expand Down
Loading