Skip to content

Commit

Permalink
feat: convert openBIS cloud storage configurations into valid rclone …
Browse files Browse the repository at this point in the history
…configurations before starting a session (next try)
  • Loading branch information
olloz26 committed Jan 9, 2025
1 parent 8f034a2 commit 5516d0e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
30 changes: 27 additions & 3 deletions components/renku_data_services/data_connectors/blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,15 @@ async def _get_secrets(
secrets = await self.data_connector_secret_repo.get_data_connector_secrets(
user=user, data_connector_id=data_connector_id
)
data_connector = await self.data_connector_repo.get_data_connector(
user=user, data_connector_id=data_connector_id
)
return validated_json(
apispec.DataConnectorSecretsList, [self._dump_data_connector_secret(secret) for secret in secrets]
apispec.DataConnectorSecretsList,
[
self._dump_data_connector_secret(secret)
for secret in self._adjust_secrets(secrets, data_connector.storage)
],
)

return "/data_connectors/<data_connector_id:ulid>/secrets", ["GET"], _get_secrets
Expand Down Expand Up @@ -342,7 +349,7 @@ async def openbis_transform_session_token_to_pat() -> (
storage.configuration["host"], unsaved_secrets[0].value
)
return (
[models.DataConnectorSecretUpdate(name="session_token", value=openbis_pat[0])],
[models.DataConnectorSecretUpdate(name="pass", value=openbis_pat[0])],
openbis_pat[1],
)
except Exception as e:
Expand All @@ -363,7 +370,8 @@ async def openbis_transform_session_token_to_pat() -> (
expiration_timestamp=expiration_timestamp,
)
return validated_json(
apispec.DataConnectorSecretsList, [self._dump_data_connector_secret(secret) for secret in secrets]
apispec.DataConnectorSecretsList,
[self._dump_data_connector_secret(secret) for secret in self._adjust_secrets(secrets, storage)],
)

return "/data_connectors/<data_connector_id:ulid>/secrets", ["PATCH"], _patch_secrets
Expand Down Expand Up @@ -415,6 +423,22 @@ def _dump_data_connector_to_project_link(link: models.DataConnectorToProjectLink
created_by=link.created_by,
)

@staticmethod
def _adjust_secrets(
secrets: list[models.DataConnectorSecret], storage: models.CloudStorageCore
) -> list[models.DataConnectorSecret]:
if storage.storage_type == "openbis":
for i, secret in enumerate(secrets):
if secret.name == "pass":
secrets[i] = models.DataConnectorSecret(
name="session_token",
user_id=secret.user_id,
data_connector_id=secret.data_connector_id,
secret_id=secret.secret_id,
)
break
return secrets

@staticmethod
def _dump_data_connector_secret(secret: models.DataConnectorSecret) -> dict[str, Any]:
"""Dumps a data connector secret for API responses."""
Expand Down
17 changes: 12 additions & 5 deletions test/bases/renku_data_services/data_api/test_data_connectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1298,14 +1298,21 @@ async def test_create_openbis_data_connector(sanic_client, create_openbis_data_c
payload = [
{"name": "session_token", "value": openbis_session_token},
]

def check_response(r):
assert r.status_code == 200, r.json
assert {s["name"] for s in r.json} == {"session_token"}
created_secret_ids = {s["secret_id"] for s in r.json}
assert len(created_secret_ids) == 1
assert r.json[0].keys() == {"secret_id", "name"}

_, response = await sanic_client.patch(
f"/api/data/data_connectors/{data_connector_id}/secrets", headers=user_headers, json=payload
)
assert response.status_code == 200, response.json
assert {s["name"] for s in response.json} == {"session_token"}
created_secret_ids = {s["secret_id"] for s in response.json}
assert len(created_secret_ids) == 1
assert response.json[0].keys() == {"secret_id", "name"}
check_response(response)

_, response = await sanic_client.get(f"/api/data/data_connectors/{data_connector_id}/secrets", headers=user_headers)
check_response(response)


@pytest.mark.myskip(1 == 1, reason="Depends on a remote openBIS host which may not always be available.")
Expand Down

0 comments on commit 5516d0e

Please sign in to comment.