From f10852bc2505062893b31bafcbabd16c844e6cb4 Mon Sep 17 00:00:00 2001 From: Jye Cusch Date: Wed, 4 Dec 2024 15:57:49 +1100 Subject: [PATCH] fix: rename id to version for secretvalue parent references (#151) --- nitric/resources/secrets.py | 22 +++++++++++++++++----- tests/resources/test_secrets.py | 6 +++--- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/nitric/resources/secrets.py b/nitric/resources/secrets.py index 8d3c0eb..426510a 100644 --- a/nitric/resources/secrets.py +++ b/nitric/resources/secrets.py @@ -20,6 +20,7 @@ from dataclasses import dataclass from typing import List, Literal, Union +import warnings from grpclib import GRPCError from grpclib.client import Channel @@ -77,7 +78,7 @@ def version(self, version: str) -> SecretVersionRef: Can be used to retrieve the secret value associated with the version. """ - return SecretVersionRef(secret=self, id=version) + return SecretVersionRef(secret=self, version=version) def latest(self) -> SecretVersionRef: """ @@ -90,7 +91,7 @@ def latest(self) -> SecretVersionRef: def _secret_version_to_wire(version: SecretVersionRef) -> VersionMessage: - return VersionMessage(SecretMessage(name=version.secret.name), version=version.id) + return VersionMessage(SecretMessage(name=version.secret.name), version=version.version) @dataclass(frozen=True) @@ -98,7 +99,18 @@ class SecretVersionRef: """A reference to a version of a secret, used to access the value of the version.""" secret: SecretRef - id: str + version: str + + @property + def id(self) -> SecretVersionRef: + """Get the version of this secret value.""" + warnings.warn( + "id is deprecated and will be removed in a future version. " + "Use version instead.", + DeprecationWarning, + stacklevel=2 + ) + return self.version async def access(self) -> SecretValue: """Return the value stored in this version of the secret.""" @@ -115,8 +127,8 @@ async def access(self) -> SecretValue: # with a fixed version id. static_version = ( self - if response.secret_version.version == self.id - else SecretVersionRef(secret=self.secret, id=response.secret_version.version) + if response.secret_version.version == self.version + else SecretVersionRef(secret=self.secret, version=response.secret_version.version) ) return SecretValue(version=static_version, value=response.value) diff --git a/tests/resources/test_secrets.py b/tests/resources/test_secrets.py index d204566..6fb901d 100644 --- a/tests/resources/test_secrets.py +++ b/tests/resources/test_secrets.py @@ -55,7 +55,7 @@ async def test_put(self): ) # Check the returned value - assert result.id == "test-version" + assert result.version == "test-version" assert result.secret.name == "test-secret" async def test_put_string(self): @@ -78,7 +78,7 @@ async def test_latest(self): version = SecretRef("test-secret").latest() assert version.secret.name == "test-secret" - assert version.id == "latest" + assert version.version == "latest" async def test_access(self): mock_access = AsyncMock() @@ -100,7 +100,7 @@ async def test_access(self): ) # Check the returned value - assert result.version.id == "response-version" + assert result.version.version == "response-version" assert result.value == b"super secret value" async def test_value_to_string(self):