Skip to content

Commit

Permalink
wip: onedrive
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Jun 13, 2024
1 parent fe21eca commit 29a3fa2
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 4 deletions.
4 changes: 2 additions & 2 deletions client/src/api/schema/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5188,7 +5188,7 @@ export interface components {
* Type
* @enum {string}
*/
type: "ftp" | "posix" | "s3fs" | "azure" | "dropbox" | "googledrive";
type: "ftp" | "posix" | "s3fs" | "azure" | "dropbox" | "googledrive" | "onedrive";
/** Variables */
variables?:
| (
Expand Down Expand Up @@ -12790,7 +12790,7 @@ export interface components {
* Type
* @enum {string}
*/
type: "ftp" | "posix" | "s3fs" | "azure" | "dropbox" | "googledrive";
type: "ftp" | "posix" | "s3fs" | "azure" | "dropbox" | "googledrive" | "onedrive";
/** Uri Root */
uri_root: string;
/** Uuid */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface Props {
uuid?: string;
}
const OAUTH2_TYPES = ["dropbox", "googledrive"];
const OAUTH2_TYPES = ["dropbox", "googledrive", "onedrive"];
const fileSourceTemplatesStore = useFileSourceTemplatesStore();
fileSourceTemplatesStore.fetchTemplates();
Expand Down
27 changes: 27 additions & 0 deletions lib/galaxy/files/sources/onedrive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
try:
from fs.onedrivefs import OneDriveFS
from google.oauth2.credentials import Credentials
except ImportError:
OneDriveFS = None

from typing import Optional

from . import FilesSourceOptions
from ._pyfilesystem2 import PyFilesystem2FilesSource


class OneDriveFilesSource(PyFilesystem2FilesSource):
plugin_type = "onedrive"
required_module = OneDriveFS
required_package = "fs.onedrivefs"

def _open_fs(self, user_context=None, opts: Optional[FilesSourceOptions] = None):
props = self._serialization_props(user_context)
access_token = props.pop("oauth2_access_token")
if access_token:
props["token"] = access_token
handle = OneDriveFS(**props)
return handle


__all__ = ("OneDriveFilesSource",)
15 changes: 15 additions & 0 deletions lib/galaxy/files/templates/examples/production_onedrive.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
- id: onedrive
name: Microsoft OneDrive
description: This file source type allows importing and exporting to your Microsoft OneDrive "personal cloud storage" account.
configuration:
type: onedrive
oauth2_client_id: "{{ environment.oauth2_client_id }}"
oauth2_client_secret: "{{ environment.oauth2_client_secret }}"
writable: true
environment:
oauth2_client_id:
type: variable
variable: GALAXY_ONEDRIVE_APP_CLIENT_ID
oauth2_client_secret:
type: variable
variable: GALAXY_ONEDRIVE_APP_CLIENT_SECRET
26 changes: 25 additions & 1 deletion lib/galaxy/files/templates/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
UserDetailsDict,
)

FileSourceTemplateType = Literal["ftp", "posix", "s3fs", "azure", "dropbox", "googledrive"]
FileSourceTemplateType = Literal["ftp", "posix", "s3fs", "azure", "dropbox", "googledrive", "onedrive"]


class PosixFileSourceTemplateConfiguration(StrictModel):
Expand Down Expand Up @@ -94,6 +94,21 @@ class GoogleDriveFileSourceConfiguration(OAuth2FileSourceConfiguration, StrictMo
oauth2_access_token: str


class OneDriveFileSourceTemplateConfiguration(OAuth2TemplateConfiguration, StrictModel):
type: Literal["onedrive"]
writable: Union[bool, TemplateExpansion] = False
oauth2_client_id: Union[str, TemplateExpansion]
oauth2_client_secret: Union[str, TemplateExpansion]
template_start: Optional[str] = None
template_end: Optional[str] = None


class OneDriveFileSourceConfiguration(OAuth2FileSourceConfiguration, StrictModel):
type: Literal["onedrive"]
writable: bool = False
oauth2_access_token: str


class S3FSFileSourceTemplateConfiguration(StrictModel):
type: Literal["s3fs"]
endpoint_url: Optional[Union[str, TemplateExpansion]] = None
Expand Down Expand Up @@ -163,6 +178,7 @@ class AzureFileSourceConfiguration(StrictModel):
AzureFileSourceTemplateConfiguration,
DropboxFileSourceTemplateConfiguration,
GoogleDriveFileSourceTemplateConfiguration,
OneDriveFileSourceTemplateConfiguration,
]
FileSourceConfiguration = Union[
PosixFileSourceConfiguration,
Expand All @@ -171,6 +187,7 @@ class AzureFileSourceConfiguration(StrictModel):
AzureFileSourceConfiguration,
DropboxFileSourceConfiguration,
GoogleDriveFileSourceConfiguration,
OneDriveFileSourceConfiguration,
]


Expand Down Expand Up @@ -235,6 +252,7 @@ def template_to_configuration(
"azure": AzureFileSourceConfiguration,
"dropbox": DropboxFileSourceConfiguration,
"googledrive": GoogleDriveFileSourceConfiguration,
"onedrive": OneDriveFileSourceConfiguration,
}


Expand All @@ -250,6 +268,12 @@ def template_to_configuration(
token_url="https://oauth2.googleapis.com/token",
scope=["https://www.googleapis.com/auth/drive.file"],
),
"onedrive": OAuth2Configuration(
authorize_url="https://login.live.com/oauth20_authorize.srf",
authorize_params={},
token_url="https://login.live.com/oauth20_token.srf",
scope=["onedrive.readwrite offline_access"],
)
}


Expand Down

0 comments on commit 29a3fa2

Please sign in to comment.