Skip to content

Commit e3f04ea

Browse files
committed
Island: Add OTP type
Issue #3078
1 parent d20adbd commit e3f04ea

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

monkey/monkey_island/cc/services/authentication_service/flask_resources/agent_otp_login.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from monkey_island.cc.flask_utils import AbstractResource, responses
77

88
from ..authentication_facade import AuthenticationFacade
9+
from ..types import OTP
910
from .utils import add_refresh_token_to_response
1011

1112

@@ -47,5 +48,5 @@ def post(self):
4748

4849
return responses.make_response_to_invalid_request()
4950

50-
def _validate_otp(self, otp: str):
51+
def _validate_otp(self, otp: OTP):
5152
return len(otp) > 0

monkey/monkey_island/cc/services/authentication_service/i_otp_repository.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
from abc import ABC, abstractmethod
22

3+
from .types import OTP
4+
35

46
class IOTPRepository(ABC):
57
"""A repository used to store and retrieve `OTP`s"""
68

79
@abstractmethod
8-
def insert_otp(self, otp: str, expiration: float):
10+
def insert_otp(self, otp: OTP, expiration: float):
911
"""
1012
Insert an OTP into the repository
1113
@@ -15,7 +17,7 @@ def insert_otp(self, otp: str, expiration: float):
1517
"""
1618

1719
@abstractmethod
18-
def get_expiration(self, otp: str) -> float:
20+
def get_expiration(self, otp: OTP) -> float:
1921
"""
2022
Get the expiration time of a given OTP
2123

monkey/monkey_island/cc/services/authentication_service/mongo_otp_repository.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from monkey_island.cc.server_utils.encryption import ILockableEncryptor
1111

1212
from .i_otp_repository import IOTPRepository
13+
from .types import OTP
1314

1415

1516
class MongoOTPRepository(IOTPRepository):
@@ -22,14 +23,14 @@ def __init__(
2223
self._otp_collection = mongo_client.monkey_island.otp
2324
self._otp_collection.create_index("otp", unique=True)
2425

25-
def insert_otp(self, otp: str, expiration: float):
26+
def insert_otp(self, otp: OTP, expiration: float):
2627
try:
2728
encrypted_otp = self._encryptor.encrypt(otp.encode())
2829
self._otp_collection.insert_one({"otp": encrypted_otp, "expiration_time": expiration})
2930
except Exception as err:
3031
raise StorageError(f"Error updating otp: {err}")
3132

32-
def get_expiration(self, otp: str) -> float:
33+
def get_expiration(self, otp: OTP) -> float:
3334
try:
3435
encrypted_otp = self._encryptor.encrypt(otp.encode())
3536
otp_dict = self._otp_collection.find_one(
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
from typing import TypeAlias
22

33
Token: TypeAlias = str
4+
OTP: TypeAlias = str

0 commit comments

Comments
 (0)