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

Driver google drive #35

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open

Driver google drive #35

wants to merge 20 commits into from

Conversation

JanCaha
Copy link
Collaborator

@JanCaha JanCaha commented Jan 16, 2025

  • implements Google Drive driver - add tests for it
  • bump media-sync version to 0.5.0
  • bump version of python in docker to 3.11
  • bump mergin-client to latest version

Fixes #13

@JanCaha JanCaha marked this pull request as ready for review January 17, 2025 08:49
@JanCaha JanCaha requested a review from wonder-sk January 17, 2025 08:59
Copy link
Contributor

@varmar05 varmar05 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. I left some suggestions for small refactoring.

@@ -28,7 +29,7 @@ def validate_config(config):
):
raise ConfigError("Config error: Incorrect mergin settings")

if config.driver not in ["local", "minio"]:
if config.driver not in ["local", "minio", "google_drive"]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest moving to enum (of supported drivers) rather than expanding list with strings, all comparisons in code would be less error prone.

@@ -66,6 +67,13 @@ def validate_config(config):
):
raise ConfigError("Config error: Incorrect media reference settings")

if config.driver == "google_drive" and not (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should not move these kinds of validations to driver class (e.g. validate() or even to init)

@@ -81,3 +89,14 @@ def update_config_path(
config.update(user_file_config)
else:
raise IOError(f"Config file {config_file_path} does not exist.")


def get_share_with(google_driver_settings) -> typing.List[str]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is not this more like config validation to be used in check above? Or maybe split between check and getter in driver?

self._folder_id = self._create_folder(self._folder)

for email in get_share_with(config.google_drive):
if email:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be better if get_share_with returned only list of valid emails or empty list


file_id = file.get("id")

except Exception as e:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for such broad exception? I can see in many places call of some .execute() method which might have a well defined exception?

)

# Check if email exists in permissions
for permission in permissions.get("permissions", []):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use next(condition, False) ?

"DRIVER": "google_drive",
"GOOGLE_DRIVE__SERVICE_ACCOUNT_FILE": GOOGLE_DRIVE_SERVICE_ACCOUNT_FILE,
"GOOGLE_DRIVE__FOLDER": GOOGLE_DRIVE_FOLDER,
"GOOGLE_DRIVE__SHARE_WITH": "jan.caha@lutraconsulting.co.uk",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure it is good to have your email here for automated tests

prepare_mergin_project(mc, full_project_name)

# patch config to fit testing purposes
config.update(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add some tests for invalid config?


google_drive_delete_folder(GoogleDriveDriver(config), GOOGLE_DRIVE_FOLDER)

main()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is quite a few extra methods in driver, I wonder if we should not test also some basic failures, even with mocked api or something.

# patch config to fit testing purposes
config.update(
{
"OPERATION_MODE": "move",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to test both, move and copy modes, is not is driver agnostic?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for google drive
2 participants