-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementing logic #7
Merged
grzegorz-leszczynski-reef
merged 32 commits into
bactensor:master
from
ggleszczynski:features/implementation
Jan 3, 2025
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
0dbf21f
feat: implement enabling shield
9648ecb
fix: fixes after code review
6f321c7
feat: shield logic finished
23fccc4
fix: code review fixes
290fc3d
feat: add serialization logic
1c69b99
feat: logic finished
6b4abe1
feat: encryption manager refactored
34a9cf7
feat: add memory implementation for some managers
168de86
feat: finish memory implementations for all managers along with full …
8f975a7
fix: finish tests for shield with needed fixes (there is still proble…
7f1873c
feat: back to EncryptionManager using ECIES library
4d7fba3
fix: added hash to manifest file to verify if content is the same
9802e2d
feat: implemented Route53AddressManager
16603b6
feat: implemented SQLAlchemyMinerShieldStateManager
6b24602
feat: implemented S3ManifestManager
82e330c
feat: added integration test
968f045
feat: filling AwsAddressManager, work in progress
935c2e6
feat: added possibility of specyfing IP in AwsAddressManager
6ba1675
feat: filling AwsAddressManager - creating ELB is working
2ac5dd7
feat: filling AwsAddressManager - creating HostedZone during ELB crea…
097b2de
feat: filling AwsAddressManager - creating alias DNS entry in Route53
dc62a30
feat: finished AwsAddressManager - added creating firewall
c9d3b75
feat: back to passing hosted_zone_id to AwsAddressManager
845ec8a
fix: tiny code review fixes
44ebe33
Add AWSClientFactory
grzegorz-leszczynski-reef 840941e
Use pytest fixture in TestAddressManager
grzegorz-leszczynski-reef 54de75f
Simplify code after CR
grzegorz-leszczynski-reef d2bc4a4
Upgrade handling AWS API errors
grzegorz-leszczynski-reef 030cba1
Add project dependencies
grzegorz-leszczynski-reef 5e27248
Apply ruff linter fixes
grzegorz-leszczynski-reef 78ad8f2
Add MinerShieldFactory
grzegorz-leszczynski-reef 4af7d75
Implement Validator
grzegorz-leszczynski-reef File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,98 @@ | ||
from abc import ABC, abstractmethod | ||
from dataclasses import dataclass | ||
from enum import Enum | ||
|
||
|
||
class AddressType(Enum): | ||
""" | ||
Possible types of address. | ||
""" | ||
IP = "ip" # IPv4 address | ||
IPV6 = "ipv6" # IPv6 address | ||
DOMAIN = "domain" # domain name | ||
IP = "ip" # IPv4 address | ||
IPV6 = "ipv6" # IPv6 address | ||
DOMAIN = "domain" # domain name | ||
S3 = "s3" # address identifies S3 object (id is object name) | ||
EC2 = "ec2" # address identifies EC2 instance (id is instance id) | ||
|
||
|
||
class Address(ABC): | ||
@dataclass | ||
class Address: | ||
""" | ||
Class describing address, which redirects to original miner's server. | ||
Class describing some address - domain or IP. | ||
""" | ||
|
||
def __init__(self, address_id, address_type: AddressType, address: str, port: int): | ||
""" | ||
Args: | ||
address_id: Identifier (used by AddressManager) of the address. Type depends on the implementation. | ||
address_type: Type of the address. | ||
address: Address. | ||
port: Port of the address. | ||
""" | ||
self.address_id = address_id | ||
self.address_type = address_type | ||
self.address = address | ||
self.port = port | ||
address_id: str | ||
""" identifier (used by AbstractAddressManager implementation) of the address """ | ||
address_type: AddressType | ||
address: str | ||
port: int | ||
|
||
def __repr__(self): | ||
return f"Address(id={self.address_id}, type={self.address_type}, address={self.address}:{self.port})" | ||
|
||
|
||
class AddressSerializerException(Exception): | ||
pass | ||
|
||
|
||
class AddressDeserializationException(AddressSerializerException): | ||
""" | ||
Exception thrown when deserialization of address data fails. | ||
""" | ||
pass | ||
|
||
|
||
class AbstractAddressSerializer(ABC): | ||
""" | ||
Class used to serialize and deserialize addresses. | ||
""" | ||
|
||
@abstractmethod | ||
def encrypt(self) -> bytes: | ||
def serialize(self, address: Address) -> bytes: | ||
""" | ||
Encrypts address data. | ||
|
||
Returns: | ||
bytes: Encrypted address data. | ||
Serialize address data. Output format depends on the implementation. | ||
""" | ||
pass | ||
|
||
@classmethod | ||
@abstractmethod | ||
def decrypt(cls, encrypted_data: bytes) -> Address: | ||
def deserialize(self, serialized_data: bytes) -> Address: | ||
""" | ||
Create address from encrypted address data. | ||
Deserialize address data. Throws AddressDeserializationException if data format is not recognized. | ||
|
||
Args: | ||
encrypted_data: Encrypted address data. | ||
|
||
Returns: | ||
Address: Created address. | ||
serialized_data: Data serialized before by serialize method. | ||
""" | ||
pass | ||
|
||
|
||
class DefaultAddressSerializer(AbstractAddressSerializer): | ||
""" | ||
Address serializer implementation which serialize address to string. | ||
""" | ||
|
||
encoding: str | ||
|
||
def __init__(self, encoding: str = "utf-8"): | ||
""" | ||
Args: | ||
encoding: Encoding used for transforming generated address string to bytes. | ||
""" | ||
self.encoding = encoding | ||
|
||
def serialize(self, address: Address) -> bytes: | ||
assert address.address.find(":") == -1, "Address should not contain colon character" | ||
address_str: str = f"{address.address_type.value}:{address.address}:{address.port}:{address.address_id}" | ||
return address_str.encode(self.encoding) | ||
|
||
def deserialize(self, serialized_data: bytes) -> Address: | ||
try: | ||
address_str: str = serialized_data.decode(self.encoding) | ||
parts = address_str.split(":") | ||
if len(parts) < 4: | ||
raise AddressDeserializationException(f"Invalid number of parts, address_str='{address_str}'") | ||
address_type: AddressType = AddressType(parts[0]) | ||
address: str = parts[1] | ||
port: int = int(parts[2]) | ||
address_id: str = ":".join(parts[3:]) # there can possibly be some colons in address_id | ||
return Address(address_id=address_id, address_type=address_type, address=address, port=port) | ||
except Exception as e: | ||
raise AddressDeserializationException(f"Failed to deserialize address, error='{e}'") from e |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.