-
Notifications
You must be signed in to change notification settings - Fork 832
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import logging | ||
from .main import ItemProvider | ||
from .views import Handler | ||
from .providers.gandi import * | ||
|
||
|
||
logging.info('dns_api.__init__.py: dns_api loaded') |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import requests | ||
import json | ||
|
||
from jadi import component | ||
from aj.plugins.dns_api.api import ApiDnsManager | ||
from aj.plugins.dns_api.record import Record | ||
import aj | ||
|
||
@component(ApiDnsManager) | ||
class GandiApiDnsProvider(ApiDnsManager): | ||
id = 'gandi' | ||
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"]: | ||
return | ||
|
||
func = getattr(requests, method) | ||
if data is None: | ||
resp = func(f"{self.baseUrl}{apiurl}", headers=self.headers) | ||
else: | ||
resp = func(f"{self.baseUrl}{apiurl}", data=data, headers=self.headers) | ||
|
||
return resp | ||
|
||
def get_domains(self): | ||
domains = json.loads(self._req("get").content) | ||
return [domain['fqdn'] for domain in domains] | ||
|
||
def get_records(self, domain): | ||
resp = self._req('get', apiurl=f"/{domain.fqdn}/records") | ||
records = json.loads(resp.content) | ||
|
||
for record in sorted(records, key=lambda d: d['rrset_name']): | ||
domain.records.append(Record(domain.fqdn, record)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
angular.module('ajenti.dns_api').controller('DnsAPIIndexController', function($scope, $http, pageTitle, gettext, notify) { | ||
pageTitle.set(gettext('DNS API')); | ||
|
||
$http.get('/api/dns_api'); | ||
|
||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters