passphera-core 0.9.0__tar.gz → 0.9.1__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {passphera-core-0.9.0 → passphera-core-0.9.1}/PKG-INFO +1 -1
- passphera-core-0.9.1/passphera_core/application/__init__.py +0 -0
- passphera-core-0.9.1/passphera_core/application/generator.py +78 -0
- passphera-core-0.9.1/passphera_core/application/password.py +118 -0
- passphera-core-0.9.1/passphera_core/application/user.py +56 -0
- {passphera-core-0.9.0 → passphera-core-0.9.1}/passphera_core.egg-info/PKG-INFO +1 -1
- {passphera-core-0.9.0 → passphera-core-0.9.1}/passphera_core.egg-info/SOURCES.txt +5 -1
- {passphera-core-0.9.0 → passphera-core-0.9.1}/setup.py +3 -3
- {passphera-core-0.9.0 → passphera-core-0.9.1}/README.md +0 -0
- {passphera-core-0.9.0 → passphera-core-0.9.1}/passphera_core/__init__.py +0 -0
- {passphera-core-0.9.0 → passphera-core-0.9.1}/passphera_core/entities.py +0 -0
- {passphera-core-0.9.0 → passphera-core-0.9.1}/passphera_core/exceptions.py +0 -0
- {passphera-core-0.9.0 → passphera-core-0.9.1}/passphera_core/interfaces.py +0 -0
- {passphera-core-0.9.0 → passphera-core-0.9.1}/passphera_core.egg-info/dependency_links.txt +0 -0
- {passphera-core-0.9.0 → passphera-core-0.9.1}/passphera_core.egg-info/requires.txt +0 -0
- {passphera-core-0.9.0 → passphera-core-0.9.1}/passphera_core.egg-info/top_level.txt +0 -0
- {passphera-core-0.9.0 → passphera-core-0.9.1}/setup.cfg +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
|
@@ -8,4 +8,8 @@ passphera_core.egg-info/PKG-INFO
|
|
8
8
|
passphera_core.egg-info/SOURCES.txt
|
9
9
|
passphera_core.egg-info/dependency_links.txt
|
10
10
|
passphera_core.egg-info/requires.txt
|
11
|
-
passphera_core.egg-info/top_level.txt
|
11
|
+
passphera_core.egg-info/top_level.txt
|
12
|
+
passphera_core/application/__init__.py
|
13
|
+
passphera_core/application/generator.py
|
14
|
+
passphera_core/application/password.py
|
15
|
+
passphera_core/application/user.py
|
@@ -1,18 +1,18 @@
|
|
1
|
-
from setuptools import setup
|
1
|
+
from setuptools import setup, find_packages
|
2
2
|
|
3
3
|
with open("README.md", "r") as fh:
|
4
4
|
long_description = fh.read()
|
5
5
|
|
6
6
|
setup(
|
7
7
|
name='passphera-core',
|
8
|
-
version='0.9.
|
8
|
+
version='0.9.1',
|
9
9
|
author='Fathi Abdelmalek',
|
10
10
|
author_email='abdelmalek.fathi.2001@gmail.com',
|
11
11
|
url='https://github.com/passphera/core',
|
12
12
|
description='The core system of passphera project',
|
13
13
|
long_description=long_description,
|
14
14
|
long_description_content_type="text/markdown",
|
15
|
-
packages=
|
15
|
+
packages=find_packages(),
|
16
16
|
python_requires='>=3',
|
17
17
|
install_requires=['cipherspy'],
|
18
18
|
classifiers=[
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|