✨(dimail) send domain creation request to dimail
Send domain creation request to dimail when someone creates a domain in people.
This commit is contained in:
committed by
Marie
parent
8f30264445
commit
21bf431940
@@ -76,6 +76,40 @@ class DimailAPIClient:
|
||||
|
||||
return self.pass_dimail_unexpected_response(response)
|
||||
|
||||
def send_domain_creation_request(self, domain_name, request_user):
|
||||
"""Send a domain creation request to dimail API."""
|
||||
|
||||
payload = {
|
||||
"domain": domain_name,
|
||||
"context": domain_name, # for now, we put each domain on its own context
|
||||
"features": ["webmail", "mailboxes"],
|
||||
}
|
||||
try:
|
||||
response = session.post(
|
||||
f"{self.API_URL}/domains/",
|
||||
json=payload,
|
||||
headers={"Authorization": f"Basic {self.API_CREDENTIALS}"},
|
||||
verify=True,
|
||||
timeout=10,
|
||||
)
|
||||
except requests.exceptions.ConnectionError as error:
|
||||
logger.error(
|
||||
"Connection error while trying to reach %s.",
|
||||
self.API_URL,
|
||||
exc_info=error,
|
||||
)
|
||||
raise error
|
||||
|
||||
if response.status_code == status.HTTP_201_CREATED:
|
||||
logger.info(
|
||||
"Domain %s successfully created on dimail by user %s",
|
||||
domain_name,
|
||||
request_user,
|
||||
)
|
||||
return response
|
||||
|
||||
return self.pass_dimail_unexpected_response(response)
|
||||
|
||||
def send_mailbox_request(self, mailbox, user_sub=None):
|
||||
"""Send a CREATE mailbox request to mail provisioning API."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user