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

GCS authentication and object updated timestamp parsing fix for Python 3.8-3.10 #195

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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: 4 additions & 2 deletions rohmu/object_storage/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ def get_credentials(
credential_file: Optional[TextIO] = None, credentials: Optional[dict[str, Any]] = None
) -> GoogleCredentials:
if credential_file:
return GoogleCredentials.from_stream(credential_file)
return GoogleCredentials.from_stream(credential_file).create_scoped(
["https://www.googleapis.com/auth/cloud-platform"]
)

if credentials and credentials["type"] == "service_account":
return ServiceAccountCredentials_from_dict(
Expand Down Expand Up @@ -442,7 +444,7 @@ def initial_op(domain: Any) -> HttpRequest:
if (size := item.get("size")) is not None:
value["size"] = int(size)
if (updated := item.get("updated")) is not None:
value["last_modified"] = datetime.datetime.fromisoformat(updated)
value["last_modified"] = datetime.datetime.strptime(updated, "%Y-%m-%dT%H:%M:%S.%f%z")
if (md5 := item.get("md5Hash")) is not None:
value["md5"] = base64_to_hex(md5)
yield IterKeyItem(type=KEY_TYPE_OBJECT, value=value)
Expand Down
2 changes: 1 addition & 1 deletion test/object_storage/test_google.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def test_object_listed_when_missing_md5hash_size_and_updated() -> None:
sample_item,
{"size": 100, **sample_item},
{"md5Hash": base64.encodebytes(b"Missing md5Hash!"), **sample_item},
{"updated": "2023-11-20T16:18:00+00:00", **sample_item},
{"updated": "2023-11-20T16:18:00.000Z", **sample_item},
]
}

Expand Down
Loading