Skip to content

Commit

Permalink
Read apikey on each request.
Browse files Browse the repository at this point in the history
  • Loading branch information
kiarn committed Apr 29, 2023
1 parent 836ff03 commit 2eb700e
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions plugins/dns_api/providers/gandi.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,26 @@ class GandiApiDnsProvider(ApiDnsManager):
name = 'Gandi DNS API'

def __init__(self, context):
apikey = aj.config.data.get('dns_apikey', '') # TODO : wrong config entry for this
self.baseUrl = 'https://api.gandi.net/v5/livedns/domains'
self.headers = {"Authorization": f"Apikey {apikey}"}

def _req(self, method, apiurl="", data=None):
if method not in ["get", "put", "post", "delete"]:
apikey = aj.config.data.get('dns_api', {}).get('apikey', None)

if method not in ["get", "put", "post", "delete"] or apikey is None:
return

func = getattr(requests, method)
if data is None:
resp = func(f"{self.baseUrl}{apiurl}", headers=self.headers)
resp = func(
f"{self.baseUrl}{apiurl}",
headers={"Authorization": f"Apikey {apikey}"}
)
else:
resp = func(f"{self.baseUrl}{apiurl}", data=data, headers=self.headers)
resp = func(
f"{self.baseUrl}{apiurl}",
data=data,
headers={"Authorization": f"Apikey {apikey}"}
)

return resp

Expand Down

0 comments on commit 2eb700e

Please sign in to comment.