-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ralf Grubenmann
committed
Sep 27, 2023
1 parent
19142c6
commit 63ed138
Showing
47 changed files
with
1,551 additions
and
783 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ | |
renku storage | ||
************* | ||
|
||
.. automodule:: renku.ui.cli.storage | ||
.. automodule:: renku.ui.cli.lfs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Copyright Swiss Data Science Center (SDSC). A partnership between | ||
# École Polytechnique Fédérale de Lausanne (EPFL) and | ||
# Eidgenössische Technische Hochschule Zürich (ETHZ). | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Command builder for gitlab api.""" | ||
|
||
|
||
from renku.command.command_builder.command import Command, check_finalized | ||
from renku.core.interface.git_api_provider import IGitAPIProvider | ||
from renku.domain_model.project_context import project_context | ||
from renku.infrastructure.gitlab_api_provider import GitlabAPIProvider | ||
|
||
|
||
class GitlabApiCommand(Command): | ||
"""Builder to get a gitlab api client.""" | ||
|
||
PRE_ORDER = 4 | ||
|
||
def __init__(self, builder: Command) -> None: | ||
self._builder = builder | ||
|
||
def _injection_pre_hook(self, builder: Command, context: dict, *args, **kwargs) -> None: | ||
"""Create a gitlab api provider.""" | ||
|
||
if not project_context.has_context(): | ||
raise ValueError("Gitlab API builder needs a ProjectContext to be set.") | ||
|
||
def _get_provider(): | ||
from renku.core.login import read_renku_token | ||
|
||
token = read_renku_token(None, True) | ||
if not token: | ||
return None | ||
return GitlabAPIProvider(token=token) | ||
|
||
context["constructor_bindings"][IGitAPIProvider] = _get_provider | ||
|
||
@check_finalized | ||
def build(self) -> Command: | ||
"""Build the command.""" | ||
self._builder.add_injection_pre_hook(self.PRE_ORDER, self._injection_pre_hook) | ||
|
||
return self._builder.build() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Copyright Swiss Data Science Center (SDSC). A partnership between | ||
# École Polytechnique Fédérale de Lausanne (EPFL) and | ||
# Eidgenössische Technische Hochschule Zürich (ETHZ). | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Command builder for storage api.""" | ||
|
||
|
||
from renku.command.command_builder.command import Command, check_finalized | ||
from renku.core.interface.storage_service_gateway import IStorageService | ||
from renku.domain_model.project_context import project_context | ||
from renku.infrastructure.storage.storage_service import StorageService | ||
|
||
|
||
class StorageApiCommand(Command): | ||
"""Builder to get a storage api client.""" | ||
|
||
PRE_ORDER = 4 | ||
|
||
def __init__(self, builder: Command) -> None: | ||
self._builder = builder | ||
|
||
def _injection_pre_hook(self, builder: Command, context: dict, *args, **kwargs) -> None: | ||
"""Create a storage api provider.""" | ||
|
||
if not project_context.has_context(): | ||
raise ValueError("storage api builder needs a ProjectContext to be set.") | ||
|
||
context["constructor_bindings"][IStorageService] = lambda: StorageService() | ||
|
||
@check_finalized | ||
def build(self) -> Command: | ||
"""Build the command.""" | ||
self._builder.add_injection_pre_hook(self.PRE_ORDER, self._injection_pre_hook) | ||
|
||
return self._builder.build() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Copyright Swiss Data Science Center (SDSC). A partnership between | ||
# École Polytechnique Fédérale de Lausanne (EPFL) and | ||
# Eidgenössische Technische Hochschule Zürich (ETHZ). | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Serializers for storage.""" | ||
|
||
import json | ||
from typing import List, Optional | ||
|
||
from renku.command.format.tabulate import tabulate | ||
from renku.domain_model.cloud_storage import CloudStorage | ||
|
||
|
||
def tabular(cloud_storages: List[CloudStorage], *, columns: Optional[str] = None): | ||
"""Format cloud_storages with a tabular output.""" | ||
if not columns: | ||
columns = "id,start_time,status,provider,url" | ||
|
||
if any(s.ssh_enabled for s in cloud_storages): | ||
columns += ",ssh" | ||
|
||
return tabulate(collection=cloud_storages, columns=columns, columns_mapping=cloud_storage_COLUMNS) | ||
|
||
|
||
def log(cloud_storages: List[CloudStorage], *, columns: Optional[str] = None): | ||
"""Format cloud_storages in a log like output.""" | ||
from renku.ui.cli.utils.terminal import style_header, style_key | ||
|
||
output = [] | ||
|
||
for cloud_storage in cloud_storages: | ||
output.append(style_header(f"CloudStorage {cloud_storage.name}")) | ||
output.append(style_key("Id: ") + cloud_storage.storage_id) | ||
output.append(style_key("Source Path: ") + cloud_storage.source_path) | ||
output.append(style_key("Target path: ") + cloud_storage.target_path) | ||
output.append(style_key("Private: ") + "Yes" if cloud_storage.private else "No") | ||
output.append(style_key("Configuration: \n") + json.dumps(cloud_storage.configuration, indent=4)) | ||
output.append("") | ||
return "\n".join(output) | ||
|
||
|
||
CLOUD_STORAGE_FORMATS = {"tabular": tabular, "log": log} | ||
"""Valid formatting options.""" | ||
|
||
CLOUD_STORAGE_COLUMNS = { | ||
"id": ("id", "id"), | ||
"status": ("status", "status"), | ||
"url": ("url", "url"), | ||
"ssh": ("ssh_enabled", "SSH enabled"), | ||
"start_time": ("start_time", "start_time"), | ||
"commit": ("commit", "commit"), | ||
"branch": ("branch", "branch"), | ||
"provider": ("provider", "provider"), | ||
} |
Oops, something went wrong.