2019-03-01 22:49:31 +00:00
|
|
|
import requests
|
|
|
|
from urllib.parse import urljoin
|
2019-12-02 03:32:03 +00:00
|
|
|
from flask import request, current_app
|
2019-03-01 22:49:31 +00:00
|
|
|
|
2019-12-02 03:32:03 +00:00
|
|
|
from ..models import Setting
|
2019-03-01 22:49:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
def forward_request():
|
|
|
|
pdns_api_url = Setting().get('pdns_api_url')
|
|
|
|
pdns_api_key = Setting().get('pdns_api_key')
|
|
|
|
headers = {}
|
|
|
|
data = None
|
|
|
|
|
|
|
|
msg_str = "Sending request to powerdns API {0}"
|
|
|
|
|
|
|
|
if request.method != 'GET' and request.method != 'DELETE':
|
2022-10-12 06:10:35 +00:00
|
|
|
msg = msg_str.format(request.get_json(force=True, silent=True))
|
2019-12-02 03:32:03 +00:00
|
|
|
current_app.logger.debug(msg)
|
2022-10-12 06:10:35 +00:00
|
|
|
data = request.get_json(force=True, silent=True)
|
2019-03-01 22:49:31 +00:00
|
|
|
|
|
|
|
verify = False
|
|
|
|
|
|
|
|
headers = {
|
2019-12-02 03:32:03 +00:00
|
|
|
'user-agent': 'powerdns-admin/api',
|
2019-03-01 22:49:31 +00:00
|
|
|
'pragma': 'no-cache',
|
|
|
|
'cache-control': 'no-cache',
|
|
|
|
'accept': 'application/json; q=1',
|
|
|
|
'X-API-KEY': pdns_api_key
|
|
|
|
}
|
|
|
|
|
2020-02-28 15:25:19 +00:00
|
|
|
url = urljoin(pdns_api_url, request.full_path)
|
2019-03-01 22:49:31 +00:00
|
|
|
|
2019-12-02 03:32:03 +00:00
|
|
|
resp = requests.request(request.method,
|
|
|
|
url,
|
|
|
|
headers=headers,
|
|
|
|
verify=verify,
|
|
|
|
json=data)
|
2019-03-01 22:49:31 +00:00
|
|
|
|
|
|
|
return resp
|