def setUp(self):
     self._folder = mkdtemp()
     self._auth = AzureAuth(storage=AzureTextStorage(
         account=self._folder,
         key='key',
         container='auth',
         provider='LOCAL',
     ))
Beispiel #2
0
def get_raw_email_storage() -> AzureTextStorage:
    return AzureTextStorage(
        account=config.BLOBS_ACCOUNT,
        key=config.BLOBS_KEY,
        host=config.BLOBS_HOST,
        secure=config.BLOBS_SECURE,
        container=constants.CONTAINER_SENDGRID_MIME,
        provider=config.STORAGE_PROVIDER,
    )
Beispiel #3
0
def get_auth() -> AzureAuth:
    return AzureAuth(storage=AzureTextStorage(
        account=config.TABLES_ACCOUNT,
        key=config.TABLES_KEY,
        host=config.TABLES_HOST,
        secure=config.TABLES_SECURE,
        container=constants.TABLE_AUTH,
        provider=config.STORAGE_PROVIDER,
    ))
 def setUp(self):
     self._folder = mkdtemp()
     self._container = 'container'
     self._storage = AzureTextStorage(
         account=self._folder,
         key='key',
         container=self._container,
         provider='LOCAL',
     )
Beispiel #5
0
def get_pending_storage() -> AzureTextStorage:
    return AzureTextStorage(
        account=config.TABLES_ACCOUNT,
        key=config.TABLES_KEY,
        host=config.TABLES_HOST,
        secure=config.TABLES_SECURE,
        container=config.CONTAINER_PENDING,
        provider=config.STORAGE_PROVIDER,
    )
Beispiel #6
0
def get_pending_storage(domain: str) -> AzureTextStorage:
    container = domain.replace('.', '-')
    return AzureTextStorage(
        account=config.TABLES_ACCOUNT,
        key=config.TABLES_KEY,
        host=config.TABLES_HOST,
        secure=config.TABLES_SECURE,
        container=container,
        provider=config.STORAGE_PROVIDER,
    )
Beispiel #7
0
 def setUp(self):
     self._folder = mkdtemp()
     self._container = 'container'
     mkdir(join(self._folder, self._container))
     self._storage = AzureObjectStorage(
         text_storage=AzureTextStorage(
             account=self._folder,
             key='unused',
             container=self._container,
             provider='LOCAL'))
Beispiel #8
0
def get_mailbox_storage() -> AzureTextStorage:
    return AzureTextStorage(
        account=config.BLOBS_ACCOUNT,
        key=config.BLOBS_KEY,
        host=config.BLOBS_HOST,
        secure=config.BLOBS_SECURE,
        container=config.CONTAINER_MAILBOX,
        provider=config.STORAGE_PROVIDER,
        case_sensitive=False,
    )
    def given_storage(cls, content=None):
        client_mock = MagicMock()
        storage = AzureTextStorage(account='account',
                                   key='key',
                                   container='name',
                                   factory=lambda *args, **kwargs: client_mock)

        if content:
            build_blob = namedtuple('Blob', 'content')
            data = gzip_string(content)
            client_mock.get_blob_to_bytes.return_value = build_blob(data)

        return storage, client_mock
from typing import Tuple
from uuid import uuid4

from opwen_email_server import azure_constants as constants
from opwen_email_server import config
from opwen_email_server import events
from opwen_email_server.services.auth import AzureAuth
from opwen_email_server.services.queue import AzureQueue
from opwen_email_server.services.storage import AzureTextStorage
from opwen_email_server.utils.log import LogMixin

STORAGE = AzureTextStorage(account=config.BLOBS_ACCOUNT,
                           key=config.BLOBS_KEY,
                           container=constants.CONTAINER_SENDGRID_MIME)

QUEUE = AzureQueue(namespace=config.QUEUES_NAMESPACE,
                   sas_key=config.QUEUES_SAS_KEY,
                   sas_name=config.QUEUES_SAS_NAME,
                   name=constants.QUEUE_SENDGRID_MIME)

CLIENTS = AzureAuth(account=config.TABLES_ACCOUNT, key=config.TABLES_KEY,
                    table=constants.TABLE_AUTH)


class _Receiver(LogMixin):
    def __call__(self, client_id: str, email: str) -> Tuple[str, int]:
        domain = CLIENTS.domain_for(client_id)
        if not domain:
            self.log_event(events.UNREGISTERED_CLIENT, {'client_id': client_id})  # noqa: E501
            return 'client is not registered', 403
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))
 def _mark_emails_as_delivered(cls, pending_storage: AzureTextStorage,
                               email_ids: Iterable[str]):
     for email_id in email_ids:
         pending_storage.delete(email_id)
 def _fetch_pending_emails(self, pending_storage: AzureTextStorage):
     for email_id in pending_storage.iter():
         yield self._email_storage.fetch_object(email_id)