/
azure.py
65 lines (52 loc) · 2.06 KB
/
azure.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from functools import lru_cache
from opwen_email_server import config
from opwen_email_server.constants import azure as constants
from opwen_email_server.services.auth import AzureAuth
from opwen_email_server.services.sendgrid import SendgridEmailSender
from opwen_email_server.services.storage import AzureFileStorage
from opwen_email_server.services.storage import AzureObjectStorage
from opwen_email_server.services.storage import AzureObjectsStorage
from opwen_email_server.services.storage import AzureTextStorage
from opwen_email_server.utils.collections import singleton
@singleton
def get_auth() -> AzureAuth:
return AzureAuth(
storage=AzureTextStorage(
account=config.TABLES_ACCOUNT,
key=config.TABLES_KEY,
container=constants.TABLE_AUTH,
provider=config.STORAGE_PROVIDER))
@singleton
def get_client_storage() -> AzureObjectsStorage:
return AzureObjectsStorage(
file_storage=AzureFileStorage(
account=config.CLIENT_STORAGE_ACCOUNT,
key=config.CLIENT_STORAGE_KEY,
container=constants.CONTAINER_CLIENT_PACKAGES,
provider=config.STORAGE_PROVIDER))
@singleton
def get_raw_email_storage() -> AzureTextStorage:
return AzureTextStorage(
account=config.BLOBS_ACCOUNT,
key=config.BLOBS_KEY,
container=constants.CONTAINER_SENDGRID_MIME,
provider=config.STORAGE_PROVIDER)
@singleton
def get_email_sender() -> SendgridEmailSender:
return SendgridEmailSender(
key=config.SENDGRID_KEY)
@singleton
def get_email_storage() -> AzureObjectStorage:
return AzureObjectStorage(
text_storage=AzureTextStorage(
account=config.BLOBS_ACCOUNT,
key=config.BLOBS_KEY,
container=constants.CONTAINER_EMAILS,
provider=config.STORAGE_PROVIDER))
@lru_cache(maxsize=128)
def get_pending_storage(domain: str) -> AzureTextStorage:
return AzureTextStorage(
account=config.TABLES_ACCOUNT,
key=config.TABLES_KEY,
container=domain,
provider=config.STORAGE_PROVIDER)