Skip to content

Commit 739e439

Browse files
committed
fix: delete storage config fields (#416)
Fixes deleting storage configuration fields by setting them to `null`.
1 parent 798871f commit 739e439

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

.devcontainer/devcontainer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"ghcr.io/mpriscella/features/kind:1": {},
1515
"ghcr.io/devcontainers-contrib/features/gh-release:1": {
1616
"repo": "authzed/zed",
17-
"binaryNames": "zed"
17+
"binaryNames": "zed",
18+
"version": "v0.21.1"
1819
},
1920
"ghcr.io/devcontainers-contrib/features/spicedb:1": {},
2021
"ghcr.io/devcontainers/features/kubectl-helm-minikube:1": {

components/renku_data_services/data_connectors/core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ def validate_storage_patch(
8080
if patch.configuration is not None:
8181
# we need to apply the patch to the existing storage to properly validate it
8282
patch.configuration = {**storage.configuration, **patch.configuration}
83-
for k, v in patch.configuration.items():
83+
dict_items = list(patch.configuration.items())
84+
for k, v in dict_items:
8485
if v is None:
8586
# delete fields that were unset
8687
del patch.configuration[k]

test/bases/renku_data_services/data_api/test_data_connectors.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,42 @@ async def test_patch_data_connector(sanic_client: SanicASGITestClient, create_da
248248
assert set(data_connector.get("keywords")) == {"keyword 1", "keyword 2"}
249249

250250

251+
@pytest.mark.asyncio
252+
async def test_patch_data_connector_can_unset_storage_field(
253+
sanic_client: SanicASGITestClient, create_data_connector, user_headers
254+
) -> None:
255+
initial_storage = {
256+
"configuration": {
257+
"provider": "AWS",
258+
"type": "s3",
259+
"region": "us-east-1",
260+
"access_key_id": "ACCESS KEY",
261+
"secret_access_key": "SECRET",
262+
},
263+
"source_path": "my-bucket",
264+
"target_path": "my_data",
265+
}
266+
data_connector = await create_data_connector("My data connector", storage=initial_storage)
267+
268+
headers = merge_headers(user_headers, {"If-Match": data_connector["etag"]})
269+
data_connector_id = data_connector["id"]
270+
patch = {"storage": {"configuration": {"region": None, "access_key_id": None, "secret_access_key": None}}}
271+
_, response = await sanic_client.patch(
272+
f"/api/data/data_connectors/{data_connector_id}", headers=headers, json=patch
273+
)
274+
275+
assert response.status_code == 200, response.text
276+
assert response.json is not None
277+
new_configuration = response.json["storage"]["configuration"]
278+
assert new_configuration is not None
279+
assert new_configuration["provider"] == "AWS"
280+
assert new_configuration["type"] == "s3"
281+
assert "region" not in new_configuration
282+
assert "access_key_id" not in new_configuration
283+
assert "secret_access_key" not in new_configuration
284+
assert len(response.json["storage"]["sensitive_fields"]) == 0
285+
286+
251287
@pytest.mark.asyncio
252288
async def test_delete_data_connector(sanic_client: SanicASGITestClient, create_data_connector, user_headers) -> None:
253289
await create_data_connector("Data connector 1")

0 commit comments

Comments
 (0)