Skip to content

Commit 86e03fb

Browse files
authored
fix: allow unsetting storage secrets (#415)
1 parent a449135 commit 86e03fb

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

components/renku_data_services/storage/api.spec.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ components:
515515
minLength: 1
516516
maxLength: 99
517517
value:
518-
$ref: "#/components/schemas/SecretValue"
518+
$ref: "#/components/schemas/SecretValueNullable"
519519
required:
520520
- name
521521
- value
@@ -543,11 +543,12 @@ components:
543543
required:
544544
- name
545545
- secret_id
546-
SecretValue:
547-
description: Secret value that can be any text
548-
type: string
549-
minLength: 1
550-
maxLength: 5000
546+
SecretValueNullable:
547+
description: Secret value that can be any text
548+
type: string
549+
minLength: 1
550+
maxLength: 5000
551+
nullable: true
551552
RCloneSchema:
552553
description: List of RClone schemas for different storage types
553554
type: array

components/renku_data_services/storage/apispec.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# generated by datamodel-codegen:
22
# filename: api.spec.yaml
3-
# timestamp: 2024-08-13T13:29:46+00:00
3+
# timestamp: 2024-10-07T08:21:24+00:00
44

55
from __future__ import annotations
66

@@ -242,7 +242,7 @@ class CloudStorageSecretPost(BaseAPISpec):
242242
max_length=99,
243243
min_length=1,
244244
)
245-
value: str = Field(
245+
value: Optional[str] = Field(
246246
...,
247247
description="Secret value that can be any text",
248248
max_length=5000,

components/renku_data_services/storage/db.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,16 @@ async def upsert_storage_secrets(
188188
stored_secrets = []
189189

190190
for name, value in secret_names_values.items():
191+
if value is None:
192+
# delete the secret
193+
storage_secret_orm = existing_secrets.get(name)
194+
if storage_secret_orm is None:
195+
continue
196+
await session.delete(storage_secret_orm)
197+
await session.delete(storage_secret_orm.secret)
198+
del existing_secrets[name]
199+
continue
200+
191201
encrypted_value, encrypted_key = await encrypt_user_secret(
192202
user_repo=self.user_repo,
193203
requested_by=user,

components/renku_data_services/storage/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,4 +252,4 @@ class CloudStorageSecretUpsert(BaseModel):
252252
"""Insert/update storage secret data."""
253253

254254
name: str = Field()
255-
value: str = Field()
255+
value: str | None = Field()

0 commit comments

Comments
 (0)