selfprivacy-rest-api/selfprivacy_api/resources/services/mailserver.py

42 lines
968 B
Python
Raw Normal View History

2021-11-11 18:31:28 +00:00
#!/usr/bin/env python3
2021-11-16 16:14:01 +00:00
"""Mail server management module"""
2021-11-11 18:31:28 +00:00
import base64
import subprocess
import os
2021-11-16 16:14:01 +00:00
from flask_restful import Resource
2021-11-11 18:31:28 +00:00
from selfprivacy_api.resources.services import api
2022-07-05 05:14:37 +00:00
from selfprivacy_api.utils import get_dkim_key, get_domain
2021-11-11 18:31:28 +00:00
2021-11-16 16:14:01 +00:00
2021-11-11 18:31:28 +00:00
class DKIMKey(Resource):
2021-11-16 16:14:01 +00:00
"""Get DKIM key from file"""
2021-11-11 18:31:28 +00:00
def get(self):
2021-11-16 16:14:01 +00:00
"""
Get DKIM key from file
---
tags:
- Email
security:
- bearerAuth: []
responses:
200:
description: DKIM key encoded in base64
401:
description: Unauthorized
404:
description: DKIM key not found
2021-11-16 16:14:01 +00:00
"""
2021-11-11 18:31:28 +00:00
domain = get_domain()
2022-07-05 05:14:37 +00:00
dkim = get_dkim_key(domain)
if dkim is None:
2022-07-07 13:53:19 +00:00
return "DKIM file not found", 404
2022-07-05 05:14:37 +00:00
dkim = base64.b64encode(dkim.encode("utf-8")).decode("utf-8")
return dkim
2021-11-11 18:31:28 +00:00
api.add_resource(DKIMKey, "/mailserver/dkim")