Skip to content
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

add type hint for minio/credentials/credentials.py #1298

Merged
merged 5 commits into from
Sep 24, 2023
Merged
Changes from 4 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: 17 additions & 6 deletions minio/credentials/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# limitations under the License.

"""Credential definitions to access S3 service."""
from __future__ import annotations

from datetime import datetime, timedelta, timezone

Expand All @@ -24,8 +25,17 @@ class Credentials:
Represents credentials access key, secret key and session token.
"""

_access_key: str
_secret_key: str
_session_token: str | None
_expiration: datetime | None

def __init__(
self, access_key, secret_key, session_token=None, expiration=None,
self,
access_key: str,
secret_key: str,
session_token: str | None = None,
expiration: datetime | None = None,
):
if not access_key:
raise ValueError("Access key must not be empty")
Expand All @@ -43,23 +53,24 @@ def __init__(
self._expiration = expiration

@property
def access_key(self):
def access_key(self) -> str:
"""Get access key."""
return self._access_key

@property
def secret_key(self):
def secret_key(self) -> str:
"""Get secret key."""
return self._secret_key

@property
def session_token(self):
def session_token(self) -> str | None:
"""Get session token."""
return self._session_token

def is_expired(self):
def is_expired(self) -> bool:
"""Check whether this credentials expired or not."""
return (
self._expiration < (datetime.utcnow() + timedelta(seconds=10))
if self._expiration else False
if self._expiration
trim21 marked this conversation as resolved.
Show resolved Hide resolved
else False
)