1212from opwen_email_server .constants import events
1313from opwen_email_server .constants import mailbox
1414from opwen_email_server .constants import sync
15- from opwen_email_server .services .auth import AzureAuth
16- from opwen_email_server .services .auth import NoAuth
15+ from opwen_email_server .services .auth import Auth
1716from opwen_email_server .services .sendgrid import SendSendgridEmail
1817from opwen_email_server .services .storage import AzureObjectsStorage
1918from opwen_email_server .services .storage import AzureObjectStorage
@@ -214,9 +213,7 @@ def _decode_attachments(cls, email: dict) -> dict:
214213
215214
216215class ReceiveInboundEmail (_Action ):
217- def __init__ (self , auth : Union [AzureAuth , NoAuth ], raw_email_storage : AzureTextStorage , next_task : Callable [[str ],
218- None ]):
219-
216+ def __init__ (self , auth : Auth , raw_email_storage : AzureTextStorage , next_task : Callable [[str ], None ]):
220217 self ._auth = auth
221218 self ._raw_email_storage = raw_email_storage
222219 self ._next_task = next_task
@@ -289,7 +286,7 @@ def _action(self, resource_id): # type: ignore
289286
290287
291288class DownloadClientEmails (_Action ):
292- def __init__ (self , auth : AzureAuth , client_storage : AzureObjectsStorage , email_storage : AzureObjectStorage ,
289+ def __init__ (self , auth : Auth , client_storage : AzureObjectsStorage , email_storage : AzureObjectStorage ,
293290 pending_storage : AzureTextStorage ):
294291
295292 self ._auth = auth
@@ -347,8 +344,7 @@ def _mark_emails_as_delivered(self, domain: str, email_ids: Iterable[str]) -> No
347344
348345
349346class UploadClientEmails (_Action ):
350- def __init__ (self , auth : AzureAuth , next_task : Callable [[str ], None ]):
351-
347+ def __init__ (self , auth : Auth , next_task : Callable [[str ], None ]):
352348 self ._auth = auth
353349 self ._next_task = next_task
354350
@@ -367,9 +363,8 @@ def _action(self, client_id, upload_info): # type: ignore
367363
368364
369365class RegisterClient (_Action ):
370- def __init__ (self , auth : AzureAuth , client_storage : AzureObjectsStorage , setup_mailbox : Callable [[str , str ], None ],
366+ def __init__ (self , auth : Auth , client_storage : AzureObjectsStorage , setup_mailbox : Callable [[str , str ], None ],
371367 setup_mx_records : Callable [[str ], None ], client_id_source : Callable [[], str ]):
372-
373368 self ._auth = auth
374369 self ._client_storage = client_storage
375370 self ._setup_mailbox = setup_mailbox
@@ -389,25 +384,25 @@ def _action(self, domain, owner): # type: ignore
389384
390385
391386class CreateClient (_Action ):
392- def __init__ (self , auth : AzureAuth , task : Callable [[str , str ], None ]):
387+ def __init__ (self , auth : Auth , task : Callable [[str , str ], None ]):
393388 self ._auth = auth
394389 self ._task = task
395390
396- def _action (self , client , ** auth_args ): # type: ignore
391+ def _action (self , client , user , ** auth_args ): # type: ignore
397392 domain = client ['domain' ]
398393 if not is_lowercase (domain ):
399394 return 'domain must be lowercase' , 400
400395 if self ._auth .client_id_for (domain ) is not None :
401396 return 'client already exists' , 409
402397
403- self ._task (domain , auth_args . get ( ' user' ) )
398+ self ._task (domain , user )
404399
405400 self .log_event (events .CLIENT_CREATED , {'domain' : domain }) # noqa: E501 # yapf: disable
406401 return 'accepted' , 201
407402
408403
409404class ListClients (_Action ):
410- def __init__ (self , auth : AzureAuth ):
405+ def __init__ (self , auth : Auth ):
411406 self ._auth = auth
412407
413408 def _action (self , ** auth_args ): # type: ignore
@@ -420,19 +415,19 @@ def _action(self, **auth_args): # type: ignore
420415
421416
422417class GetClient (_Action ):
423- def __init__ (self , auth : AzureAuth , client_storage : AzureObjectsStorage ):
418+ def __init__ (self , auth : Auth , client_storage : AzureObjectsStorage ):
424419 self ._auth = auth
425420 self ._client_storage = client_storage
426421
427- def _action (self , domain , ** auth_args ): # type: ignore
422+ def _action (self , domain , user , ** auth_args ): # type: ignore
428423 if not is_lowercase (domain ):
429424 return 'domain must be lowercase' , 400
430425
431426 client_id = self ._auth .client_id_for (domain )
432427 if client_id is None :
433428 return 'client does not exist' , 404
434429
435- if not self ._auth .is_owner (domain , auth_args . get ( ' user' ) ):
430+ if not self ._auth .is_owner (domain , user ):
436431 return 'client does not belong to the user' , 403
437432
438433 access_info = self ._client_storage .access_info ()
@@ -447,26 +442,25 @@ def _action(self, domain, **auth_args): # type: ignore
447442
448443
449444class DeleteClient (_Action ):
450- def __init__ (self , auth : AzureAuth , delete_mailbox : Callable [[str , str ], None ],
451- delete_mx_records : Callable [[str ], None ], mailbox_storage : AzureTextStorage ,
452- pending_storage : AzureTextStorage , user_storage : AzureObjectStorage ):
453-
445+ def __init__ (self , auth : Auth , delete_mailbox : Callable [[str , str ], None ], delete_mx_records : Callable [[str ], None ],
446+ mailbox_storage : AzureTextStorage , pending_storage : AzureTextStorage ,
447+ user_storage : AzureObjectStorage ):
454448 self ._auth = auth
455449 self ._delete_mailbox = delete_mailbox
456450 self ._delete_mx_records = delete_mx_records
457451 self ._mailbox_storage = mailbox_storage
458452 self ._pending_storage = pending_storage
459453 self ._user_storage = user_storage
460454
461- def _action (self , domain , ** auth_args ): # type: ignore
455+ def _action (self , domain , user , ** auth_args ): # type: ignore
462456 if not is_lowercase (domain ):
463457 return 'domain must be lowercase' , 400
464458
465459 client_id = self ._auth .client_id_for (domain )
466460 if client_id is None :
467461 return 'client does not exist' , 404
468462
469- if not self ._auth .is_owner (domain , auth_args . get ( ' user' ) ):
463+ if not self ._auth .is_owner (domain , user ):
470464 return 'client does not belong to the user' , 403
471465
472466 self ._delete_mailbox (client_id , domain )
@@ -486,12 +480,12 @@ def _delete_index(cls, storage: Union[AzureTextStorage, AzureObjectStorage], dom
486480
487481
488482class CalculateNumberOfUsersMetric (_Action ):
489- def __init__ (self , auth : AzureAuth , user_storage : AzureObjectStorage ):
483+ def __init__ (self , auth : Auth , user_storage : AzureObjectStorage ):
490484 self ._auth = auth
491485 self ._user_storage = user_storage
492486
493- def _action (self , domain , ** auth_args ): # type: ignore
494- if not self ._auth .is_owner (domain , auth_args . get ( ' user' ) ):
487+ def _action (self , domain , user , ** auth_args ): # type: ignore
488+ if not self ._auth .is_owner (domain , user ):
495489 return 'client does not belong to the user' , 403
496490
497491 users = sum (1 for _ in self ._user_storage .iter (f'{ domain } /' ))
@@ -502,12 +496,12 @@ def _action(self, domain, **auth_args): # type: ignore
502496
503497
504498class CalculatePendingEmailsMetric (_Action ):
505- def __init__ (self , auth : AzureAuth , pending_storage : AzureTextStorage ):
499+ def __init__ (self , auth : Auth , pending_storage : AzureTextStorage ):
506500 self ._auth = auth
507501 self ._pending_storage = pending_storage
508502
509- def _action (self , domain , ** auth_args ): # type: ignore
510- if not self ._auth .is_owner (domain , auth_args . get ( ' user' ) ):
503+ def _action (self , domain , user , ** auth_args ): # type: ignore
504+ if not self ._auth .is_owner (domain , user ):
511505 return 'client does not belong to the user' , 403
512506
513507 pending_emails = sum (1 for _ in self ._pending_storage .iter (f'{ domain } /' ))
0 commit comments