From 82459983aeb4c1aa3c7f77087cfb2ac39ba716d9 Mon Sep 17 00:00:00 2001
From: kmochocki <kmochocki@syncad.com>
Date: Wed, 12 Feb 2025 09:22:28 +0000
Subject: [PATCH] Remove validate for wallet name and depend only on beekeeper
 error

---
 .../beekeepy/_interface/asynchronous/session.py    |  6 ++----
 .../beekeepy/_interface/synchronous/session.py     |  6 ++----
 beekeepy/beekeepy/_interface/validators.py         |  7 -------
 beekeepy/beekeepy/exceptions/__init__.py           |  2 --
 beekeepy/beekeepy/exceptions/common.py             | 14 --------------
 5 files changed, 4 insertions(+), 31 deletions(-)

diff --git a/beekeepy/beekeepy/_interface/asynchronous/session.py b/beekeepy/beekeepy/_interface/asynchronous/session.py
index dc6569f1..78378e91 100644
--- a/beekeepy/beekeepy/_interface/asynchronous/session.py
+++ b/beekeepy/beekeepy/_interface/asynchronous/session.py
@@ -10,7 +10,7 @@ from beekeepy._interface.asynchronous.wallet import (
     Wallet,
 )
 from beekeepy._interface.state_invalidator import StateInvalidator
-from beekeepy._interface.validators import validate_digest, validate_public_keys, validate_timeout, validate_wallet_name
+from beekeepy._interface.validators import validate_digest, validate_public_keys, validate_timeout
 from beekeepy.exceptions import (
     InvalidatedStateByClosingSessionError,
     InvalidWalletError,
@@ -56,7 +56,6 @@ class Session(SessionInterface, StateInvalidator):
     async def create_wallet(  # type: ignore[override]
         self, *, name: str, password: str | None = None
     ) -> UnlockedWalletInterface | tuple[UnlockedWalletInterface, Password]:
-        validate_wallet_name(wallet_name=name)
         with WalletWithSuchNameAlreadyExistsError(wallet_name=name), InvalidWalletError(wallet_name=name):
             create_result = await self.__beekeeper.api.create(
                 wallet_name=name, password=password, token=await self.token
@@ -65,8 +64,7 @@ class Session(SessionInterface, StateInvalidator):
         return wallet if password is not None else (wallet, create_result.password)
 
     async def open_wallet(self, *, name: str) -> WalletInterface:
-        validate_wallet_name(wallet_name=name)
-        with NoWalletWithSuchNameError(name):
+        with NoWalletWithSuchNameError(name), InvalidWalletError(wallet_name=name):
             await self.__beekeeper.api.open(wallet_name=name, token=await self.token)
         return await self.__construct_wallet(name=name)
 
diff --git a/beekeepy/beekeepy/_interface/synchronous/session.py b/beekeepy/beekeepy/_interface/synchronous/session.py
index 821cd29d..836ba77b 100644
--- a/beekeepy/beekeepy/_interface/synchronous/session.py
+++ b/beekeepy/beekeepy/_interface/synchronous/session.py
@@ -9,7 +9,7 @@ from beekeepy._interface.synchronous.wallet import (
     UnlockedWallet,
     Wallet,
 )
-from beekeepy._interface.validators import validate_digest, validate_public_keys, validate_timeout, validate_wallet_name
+from beekeepy._interface.validators import validate_digest, validate_public_keys, validate_timeout
 from beekeepy.exceptions import (
     InvalidatedStateByClosingSessionError,
     InvalidWalletError,
@@ -55,15 +55,13 @@ class Session(SessionInterface, StateInvalidator):
     def create_wallet(  # type: ignore[override]
         self, *, name: str, password: str | None = None
     ) -> UnlockedWalletInterface | tuple[UnlockedWalletInterface, Password]:
-        validate_wallet_name(wallet_name=name)
         with WalletWithSuchNameAlreadyExistsError(wallet_name=name), InvalidWalletError(wallet_name=name):
             create_result = self.__beekeeper.api.create(wallet_name=name, password=password, token=self.token)
         wallet = self.__construct_unlocked_wallet(name)
         return wallet if password is not None else (wallet, create_result.password)
 
     def open_wallet(self, *, name: str) -> WalletInterface:
-        validate_wallet_name(wallet_name=name)
-        with NoWalletWithSuchNameError(name):
+        with NoWalletWithSuchNameError(name), InvalidWalletError(wallet_name=name):
             self.__beekeeper.api.open(wallet_name=name, token=self.token)
         return self.__construct_wallet(name=name)
 
diff --git a/beekeepy/beekeepy/_interface/validators.py b/beekeepy/beekeepy/_interface/validators.py
index 574754ba..8b3d2c25 100644
--- a/beekeepy/beekeepy/_interface/validators.py
+++ b/beekeepy/beekeepy/_interface/validators.py
@@ -9,7 +9,6 @@ from beekeepy.exceptions import (
     InvalidSchemaHexError,
     InvalidSchemaPrivateKeyError,
     InvalidSchemaPublicKeyError,
-    InvalidWalletNameError,
     NotPositiveTimeError,
     SchemaDetectableError,
     TimeTooBigError,
@@ -25,7 +24,6 @@ __all__ = [
     "validate_private_keys",
     "validate_public_keys",
     "validate_timeout",
-    "validate_wallet_name",
     "validate_digest",
 ]
 
@@ -62,8 +60,3 @@ def validate_timeout(time: int) -> None:
 
     if time >= TimeTooBigError.MAX_VALUE:
         raise TimeTooBigError(time=time)
-
-
-def validate_wallet_name(wallet_name: str) -> None:
-    if wallet_name_regex.match(wallet_name) is None:
-        raise InvalidWalletNameError(wallet_name=wallet_name)
diff --git a/beekeepy/beekeepy/exceptions/__init__.py b/beekeepy/beekeepy/exceptions/__init__.py
index b5b16b05..960a88b1 100644
--- a/beekeepy/beekeepy/exceptions/__init__.py
+++ b/beekeepy/beekeepy/exceptions/__init__.py
@@ -16,7 +16,6 @@ from beekeepy.exceptions.common import (
     DetachRemoteBeekeeperError,
     InvalidatedStateByClosingBeekeeperError,
     InvalidatedStateByClosingSessionError,
-    InvalidWalletNameError,
     NotPositiveTimeError,
     TimeoutReachWhileCloseError,
     TimeTooBigError,
@@ -59,7 +58,6 @@ __all__ = [
     "InvalidSchemaPrivateKeyError",
     "InvalidSchemaPublicKeyError",
     "InvalidWalletError",
-    "InvalidWalletNameError",
     "MissingSTMPrefixError",
     "NotExistingKeyError",
     "NotPositiveTimeError",
diff --git a/beekeepy/beekeepy/exceptions/common.py b/beekeepy/beekeepy/exceptions/common.py
index 2f46270f..76d77141 100644
--- a/beekeepy/beekeepy/exceptions/common.py
+++ b/beekeepy/beekeepy/exceptions/common.py
@@ -66,20 +66,6 @@ class TimeTooBigError(BeekeepyError):
         super().__init__(f"Given time value is too big: `{time}` >= {TimeTooBigError.MAX_VALUE}.")
 
 
-class InvalidWalletNameError(BeekeepyError):
-    """Raises when specified wallet name was not matching alphanumeric and extra characters conditions."""
-
-    def __init__(self, wallet_name: str) -> None:
-        """Constructor.
-
-        Args:
-            wallet_name (str): invalid wallet name
-        """
-        super().__init__(
-            f"Given wallet name is invalid: `{wallet_name}`. Can be only alphanumeric or contain `._-@` characters."
-        )
-
-
 class DetachRemoteBeekeeperError(BeekeeperHandleError):
     """Raises when user tries to detach beekeeper that is remote."""
 
-- 
GitLab