passphera-core 0.9.0__py3-none-any.whl → 0.9.1__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- passphera_core/application/__init__.py +0 -0
- passphera_core/application/generator.py +78 -0
- passphera_core/application/password.py +118 -0
- passphera_core/application/user.py +56 -0
- {passphera_core-0.9.0.dist-info → passphera_core-0.9.1.dist-info}/METADATA +1 -1
- passphera_core-0.9.1.dist-info/RECORD +12 -0
- passphera_core-0.9.0.dist-info/RECORD +0 -8
- {passphera_core-0.9.0.dist-info → passphera_core-0.9.1.dist-info}/WHEEL +0 -0
- {passphera_core-0.9.0.dist-info → passphera_core-0.9.1.dist-info}/top_level.txt +0 -0
File without changes
|
@@ -0,0 +1,78 @@
|
|
1
|
+
from datetime import datetime, timezone
|
2
|
+
from uuid import UUID
|
3
|
+
|
4
|
+
from passphera_core.entities import Generator, GeneratorConfig
|
5
|
+
from passphera_core.interfaces import GeneratorRepository, GeneratorConfigRepository
|
6
|
+
|
7
|
+
|
8
|
+
class GetGeneratorUseCase:
|
9
|
+
def __init__(self, generator_repository: GeneratorRepository):
|
10
|
+
self.generator_repository: GeneratorRepository = generator_repository
|
11
|
+
|
12
|
+
def execute(self, user_id: UUID) -> Generator:
|
13
|
+
return self.generator_repository.find_by_user_id(user_id)
|
14
|
+
|
15
|
+
|
16
|
+
class GetGeneratorConfigPropertyUseCase:
|
17
|
+
def __init__(self, generator_repository: GeneratorRepository, generator_config_repository: GeneratorConfigRepository):
|
18
|
+
self.generator_repository: GeneratorRepository = generator_repository
|
19
|
+
self.generator_config_repository: GeneratorConfigRepository = generator_config_repository
|
20
|
+
|
21
|
+
def execute(self, user_id: UUID, field: str) -> str:
|
22
|
+
generator_entity: Generator = self.generator_repository.find_by_user_id(user_id)
|
23
|
+
generator_config_entity: GeneratorConfig = self.generator_config_repository.find_by_generator_id(generator_entity.id)
|
24
|
+
return getattr(generator_config_entity, field)
|
25
|
+
|
26
|
+
|
27
|
+
class UpdateGeneratorConfigUseCase:
|
28
|
+
def __init__(
|
29
|
+
self,
|
30
|
+
generator_repository: GeneratorRepository,
|
31
|
+
generator_config_repository: GeneratorConfigRepository,
|
32
|
+
):
|
33
|
+
self.generator_repository: GeneratorRepository = generator_repository
|
34
|
+
self.generator_config_repository: GeneratorConfigRepository = generator_config_repository
|
35
|
+
|
36
|
+
def execute(self, user_id: UUID, field: str, value: str) -> None:
|
37
|
+
generator_entity: Generator = self.generator_repository.find_by_user_id(user_id)
|
38
|
+
generator_config_entity: GeneratorConfig = self.generator_config_repository.find_by_generator_id(generator_entity.id)
|
39
|
+
setattr(generator_config_entity, field, value)
|
40
|
+
if field == 'algorithm':
|
41
|
+
generator_config_entity.get_algorithm()
|
42
|
+
generator_config_entity.updated_at = datetime.now(timezone.utc)
|
43
|
+
self.generator_config_repository.update(generator_config_entity)
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
class AddCharacterReplacementUseCase:
|
48
|
+
def __init__(
|
49
|
+
self,
|
50
|
+
generator_repository: GeneratorRepository,
|
51
|
+
generator_config_repository: GeneratorConfigRepository,
|
52
|
+
):
|
53
|
+
self.generator_repository: GeneratorRepository = generator_repository
|
54
|
+
self.generator_config_repository: GeneratorConfigRepository = generator_config_repository
|
55
|
+
|
56
|
+
def execute(self, user_id: UUID, character: str, replacement: str) -> None:
|
57
|
+
generator_entity: Generator = self.generator_repository.find_by_user_id(user_id)
|
58
|
+
generator_config_entity: GeneratorConfig = self.generator_config_repository.find_by_generator_id(generator_entity.id)
|
59
|
+
generator_config_entity.replace_character(character, replacement)
|
60
|
+
generator_config_entity.updated_at = datetime.now(timezone.utc)
|
61
|
+
self.generator_config_repository.update(generator_config_entity)
|
62
|
+
|
63
|
+
|
64
|
+
class ResetCharacterReplacementUseCase:
|
65
|
+
def __init__(
|
66
|
+
self,
|
67
|
+
generator_repository: GeneratorRepository,
|
68
|
+
generator_config_repository: GeneratorConfigRepository,
|
69
|
+
):
|
70
|
+
self.generator_repository: GeneratorRepository = generator_repository
|
71
|
+
self.generator_config_repository: GeneratorConfigRepository = generator_config_repository
|
72
|
+
|
73
|
+
def execute(self, user_id: UUID, character: str) -> None:
|
74
|
+
generator_entity: Generator = self.generator_repository.find_by_user_id(user_id)
|
75
|
+
generator_config_entity: GeneratorConfig = self.generator_config_repository.find_by_generator_id(generator_entity.id)
|
76
|
+
generator_config_entity.reset_character(character)
|
77
|
+
generator_config_entity.updated_at = datetime.now(timezone.utc)
|
78
|
+
self.generator_config_repository.update(generator_config_entity)
|
@@ -0,0 +1,118 @@
|
|
1
|
+
from datetime import datetime, timezone
|
2
|
+
from uuid import UUID
|
3
|
+
|
4
|
+
from passphera_core.entities import Password, Generator, User
|
5
|
+
from passphera_core.exceptions import EntityNotFoundException
|
6
|
+
from passphera_core.interfaces import PasswordRepository, GeneratorRepository, UserRepository
|
7
|
+
|
8
|
+
|
9
|
+
class GeneratePasswordUseCase:
|
10
|
+
def __init__(
|
11
|
+
self,
|
12
|
+
password_repository: PasswordRepository,
|
13
|
+
generator_repository: GeneratorRepository,
|
14
|
+
user_repository: UserRepository
|
15
|
+
):
|
16
|
+
self.password_repository: PasswordRepository = password_repository
|
17
|
+
self.generator_repository: GeneratorRepository = generator_repository
|
18
|
+
self.user_repository: UserRepository = user_repository
|
19
|
+
|
20
|
+
def execute(self, user_id: UUID, context: str, text: str) -> Password:
|
21
|
+
user_entity: User = self.user_repository.find_by_id(user_id)
|
22
|
+
generator_entity: Generator = self.generator_repository.find_by_id(user_entity.generator)
|
23
|
+
password: str = generator_entity.generate_password(text)
|
24
|
+
password_entity: Password = Password(user_id=user_id, context=context, text=text, password=password)
|
25
|
+
password_entity.encrypt()
|
26
|
+
self.password_repository.save(password_entity)
|
27
|
+
user_entity.add_password(password_entity.id)
|
28
|
+
self.user_repository.update(user_entity)
|
29
|
+
return password_entity
|
30
|
+
|
31
|
+
|
32
|
+
class GetPasswordByIdUseCase:
|
33
|
+
def __init__(self, password_repository: PasswordRepository):
|
34
|
+
self.password_repository: PasswordRepository = password_repository
|
35
|
+
|
36
|
+
def execute(self, password_id: UUID) -> Password:
|
37
|
+
password_entity: Password = self.password_repository.find_by_id(password_id)
|
38
|
+
if not password_entity:
|
39
|
+
raise EntityNotFoundException(password_entity)
|
40
|
+
return password_entity
|
41
|
+
|
42
|
+
|
43
|
+
class GetPasswordByContextUseCase:
|
44
|
+
def __init__(self, password_repository: PasswordRepository, user_repository: UserRepository):
|
45
|
+
self.password_repository: PasswordRepository = password_repository
|
46
|
+
self.user_repository: UserRepository = user_repository
|
47
|
+
|
48
|
+
def execute(self, user_id: UUID, context: str) -> Password:
|
49
|
+
user_entity: User = self.user_repository.find_by_id(user_id)
|
50
|
+
for password_id in user_entity.passwords:
|
51
|
+
password_entity: Password = self.password_repository.find_by_id(password_id)
|
52
|
+
if password_entity.context == context:
|
53
|
+
return password_entity
|
54
|
+
raise EntityNotFoundException(Password())
|
55
|
+
|
56
|
+
|
57
|
+
class UpdatePasswordUseCase:
|
58
|
+
def __init__(
|
59
|
+
self,
|
60
|
+
password_repository: PasswordRepository,
|
61
|
+
generator_repository: GeneratorRepository,
|
62
|
+
user_repository: UserRepository
|
63
|
+
):
|
64
|
+
self.password_repository: PasswordRepository = password_repository
|
65
|
+
self.generator_repository: GeneratorRepository = generator_repository
|
66
|
+
self.user_repository: UserRepository = user_repository
|
67
|
+
|
68
|
+
def execute(self, user_id: UUID, context: str, text: str) -> Password:
|
69
|
+
user_entity: User = self.user_repository.find_by_id(user_id)
|
70
|
+
generator_entity: Generator = self.generator_repository.find_by_id(user_entity.generator)
|
71
|
+
for password_id in user_entity.passwords:
|
72
|
+
password_entity: Password = self.password_repository.find_by_id(password_id)
|
73
|
+
if password_entity.context == context:
|
74
|
+
password_entity.password = generator_entity.generate_password(text)
|
75
|
+
password_entity.encrypt()
|
76
|
+
password_entity.updated_at = datetime.now(timezone.utc)
|
77
|
+
self.password_repository.update(password_entity)
|
78
|
+
return password_entity
|
79
|
+
raise EntityNotFoundException(Password())
|
80
|
+
|
81
|
+
|
82
|
+
class DeletePasswordUseCase:
|
83
|
+
def __init__(self, password_repository: PasswordRepository, user_repository: UserRepository):
|
84
|
+
self.password_repository: PasswordRepository = password_repository
|
85
|
+
self.user_repository: UserRepository = user_repository
|
86
|
+
|
87
|
+
def execute(self, user_id: UUID, password_id: UUID) -> None:
|
88
|
+
self.password_repository.delete(password_id)
|
89
|
+
user_entity: User = self.user_repository.find_by_id(user_id)
|
90
|
+
user_entity.delete_password(password_id)
|
91
|
+
self.user_repository.update(user_entity)
|
92
|
+
|
93
|
+
|
94
|
+
class GetAllUserPasswordsUseCase:
|
95
|
+
def __init__(self, password_repository: PasswordRepository, user_repository: UserRepository):
|
96
|
+
self.password_repository: PasswordRepository = password_repository
|
97
|
+
self.user_repository: UserRepository = user_repository
|
98
|
+
|
99
|
+
def execute(self, user_id: UUID) -> list[Password]:
|
100
|
+
user_entity: User = self.user_repository.find_by_id(user_id)
|
101
|
+
passwords: list[Password] = []
|
102
|
+
for password_id in user_entity.passwords:
|
103
|
+
password_entity: Password = self.password_repository.find_by_id(password_id)
|
104
|
+
passwords.append(password_entity)
|
105
|
+
return passwords
|
106
|
+
|
107
|
+
|
108
|
+
class DeleteAllUserPasswordsUseCase:
|
109
|
+
def __init__(self, password_repository: PasswordRepository, user_repository: UserRepository):
|
110
|
+
self.password_repository: PasswordRepository = password_repository
|
111
|
+
self.user_repository: UserRepository = user_repository
|
112
|
+
|
113
|
+
def execute(self, user_id: UUID) -> None:
|
114
|
+
user_entity: User = self.user_repository.find_by_id(user_id)
|
115
|
+
for password_id in user_entity.passwords:
|
116
|
+
self.password_repository.delete(password_id)
|
117
|
+
user_entity.delete_password(password_id)
|
118
|
+
self.user_repository.update(user_entity)
|
@@ -0,0 +1,56 @@
|
|
1
|
+
from uuid import UUID
|
2
|
+
|
3
|
+
from passphera_core.entities import User, Generator
|
4
|
+
from passphera_core.exceptions import DuplicateEntityException
|
5
|
+
from passphera_core.interfaces import UserRepository, GeneratorRepository
|
6
|
+
|
7
|
+
|
8
|
+
class RegisterUserUseCase:
|
9
|
+
def __init__(self, user_repository: UserRepository, generator_repository: GeneratorRepository):
|
10
|
+
self.user_repository: UserRepository = user_repository
|
11
|
+
self.generator_repository: GeneratorRepository = generator_repository
|
12
|
+
|
13
|
+
def execute(self, user: User) -> User:
|
14
|
+
if self.user_repository.find_by_email(user.email):
|
15
|
+
raise DuplicateEntityException(user, 'email')
|
16
|
+
if self.user_repository.find_by_username(user.username):
|
17
|
+
raise DuplicateEntityException(user, 'username')
|
18
|
+
user_entity: User = User(**user.__dict__)
|
19
|
+
generator_entity: Generator = Generator(user_id=user_entity.id)
|
20
|
+
self.generator_repository.save(generator_entity)
|
21
|
+
user_entity.generator = generator_entity.id
|
22
|
+
self.user_repository.save(user_entity)
|
23
|
+
return user_entity
|
24
|
+
|
25
|
+
|
26
|
+
class GetUserByIdUseCase:
|
27
|
+
def __init__(self, user_repository: UserRepository):
|
28
|
+
self.user_repository: UserRepository = user_repository
|
29
|
+
|
30
|
+
def execute(self, id: UUID) -> User:
|
31
|
+
user = self.user_repository.find_by_id(id)
|
32
|
+
if not user:
|
33
|
+
raise ValueError(f'User not found')
|
34
|
+
return user
|
35
|
+
|
36
|
+
|
37
|
+
class GetUserByUsernameUseCase:
|
38
|
+
def __init__(self, user_repository: UserRepository):
|
39
|
+
self.user_repository = user_repository
|
40
|
+
|
41
|
+
def execute(self, username: str) -> User:
|
42
|
+
user = self.user_repository.find_by_username(username)
|
43
|
+
if not user:
|
44
|
+
raise ValueError(f'User not found')
|
45
|
+
return user
|
46
|
+
|
47
|
+
|
48
|
+
class GetUserByEmailUseCase:
|
49
|
+
def __init__(self, user_repository: UserRepository):
|
50
|
+
self.user_repository = user_repository
|
51
|
+
|
52
|
+
def execute(self, email: str) -> User:
|
53
|
+
user = self.user_repository.find_by_email(email)
|
54
|
+
if not user:
|
55
|
+
raise ValueError(f'User not found')
|
56
|
+
return user
|
@@ -0,0 +1,12 @@
|
|
1
|
+
passphera_core/__init__.py,sha256=0kEfHV5WvMWDoFn1qCeuD52WsgaX4sQ4V9P48cnFKb8,120
|
2
|
+
passphera_core/entities.py,sha256=SvzBKDx9NkaVunXBGT-PgEWbXNXivb8pGw9Q_KFtAgI,5021
|
3
|
+
passphera_core/exceptions.py,sha256=5NvV6LW4Pdok6gRxvM0cN3q6JEKgaCYAX8qGr2eqX2w,1890
|
4
|
+
passphera_core/interfaces.py,sha256=uwHjPd1uhnA02X9h39IrHuNS-_M8j_RyKMVdxi3DUak,2036
|
5
|
+
passphera_core/application/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
|
+
passphera_core/application/generator.py,sha256=ABUigLMtP52CHpTKIZmwNb0pgGeL4s_WgrpxLr1M9zw,3896
|
7
|
+
passphera_core/application/password.py,sha256=72PXsHsSYvBDLdzwtC8icwf8KZPScWBKb9jKIQRAkEg,5511
|
8
|
+
passphera_core/application/user.py,sha256=WTDjccHjxoqsfC2j0c9MfwREmiST9XxYOHoaDWYGTcg,2066
|
9
|
+
passphera_core-0.9.1.dist-info/METADATA,sha256=jwBmrk5oor-rOcC6PSjASjC00mpNFHc3PifeR3uKZ44,671
|
10
|
+
passphera_core-0.9.1.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
11
|
+
passphera_core-0.9.1.dist-info/top_level.txt,sha256=aDUX2iWGOyfzyf6XakLWTbgeWqNrypMHO074Qratyds,15
|
12
|
+
passphera_core-0.9.1.dist-info/RECORD,,
|
@@ -1,8 +0,0 @@
|
|
1
|
-
passphera_core/__init__.py,sha256=0kEfHV5WvMWDoFn1qCeuD52WsgaX4sQ4V9P48cnFKb8,120
|
2
|
-
passphera_core/entities.py,sha256=SvzBKDx9NkaVunXBGT-PgEWbXNXivb8pGw9Q_KFtAgI,5021
|
3
|
-
passphera_core/exceptions.py,sha256=5NvV6LW4Pdok6gRxvM0cN3q6JEKgaCYAX8qGr2eqX2w,1890
|
4
|
-
passphera_core/interfaces.py,sha256=uwHjPd1uhnA02X9h39IrHuNS-_M8j_RyKMVdxi3DUak,2036
|
5
|
-
passphera_core-0.9.0.dist-info/METADATA,sha256=LoH3ACZT9O7vI15hlwhA0psp16_FnNaCU5eOfIr3CCY,671
|
6
|
-
passphera_core-0.9.0.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
7
|
-
passphera_core-0.9.0.dist-info/top_level.txt,sha256=aDUX2iWGOyfzyf6XakLWTbgeWqNrypMHO074Qratyds,15
|
8
|
-
passphera_core-0.9.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|