2
2
3
3
from lexicon .interfaces import Provider as BaseProvider
4
4
5
-
6
- _ZONES_API = 'https://api.hosting.ionos.com/dns/v1/zones'
5
+ _ZONES_API = "https://api.hosting.ionos.com/dns/v1/zones"
7
6
8
7
9
8
class Provider (BaseProvider ):
10
9
11
10
@staticmethod
12
11
def get_nameservers ():
13
- return [' ui-dns.com' , ' ui-dns.org' , ' ui-dns.de' , ' ui-dns.biz' ]
12
+ return [" ui-dns.com" , " ui-dns.org" , " ui-dns.de" , " ui-dns.biz" ]
14
13
15
14
@staticmethod
16
15
def configure_parser (parser ):
17
16
parser .add_argument (
18
- ' --api-key' ,
17
+ " --api-key" ,
19
18
required = True ,
20
- help = ' IONOS api key: public prefix + period + key proper' ,
19
+ help = " IONOS api key: public prefix + period + key proper" ,
21
20
)
22
21
23
22
def authenticate (self ):
24
23
zones = self ._get (_ZONES_API )
25
24
for zone in zones :
26
- if zone [' name' ] == self .domain :
27
- self .domain_id = zone ['id' ]
25
+ if zone [" name" ] == self .domain :
26
+ self .domain_id = zone ["id" ]
28
27
return
29
- raise Exception (' domain not found: ' + self .domain )
28
+ raise Exception (" domain not found: " + self .domain )
30
29
31
30
def create_record (self , rtype , name , content ):
32
31
self ._post (
33
- _ZONES_API + '/' + self .domain_id + '/records' ,
34
- data = [{
35
- 'name' : self ._full_name (name ),
36
- 'type' : rtype ,
37
- 'content' : content ,
38
- 'ttl' : self ._get_lexicon_option ('ttl' ),
39
- 'prio' : 0 ,
40
- 'disabled' : False ,
41
- }],
32
+ _ZONES_API + "/" + self .domain_id + "/records" ,
33
+ data = [
34
+ {
35
+ "name" : self ._full_name (name ),
36
+ "type" : rtype ,
37
+ "content" : content ,
38
+ "ttl" : self ._get_lexicon_option ("ttl" ),
39
+ "prio" : 0 ,
40
+ "disabled" : False ,
41
+ }
42
+ ],
42
43
)
43
44
return True
44
45
45
46
def list_records (self , rtype = None , name = None , content = None ):
46
47
query_params = {}
47
48
if rtype :
48
- query_params [' recordType' ] = rtype
49
+ query_params [" recordType" ] = rtype
49
50
if name :
50
- query_params ['recordName' ] = self ._full_name (name )
51
- data = self ._get (_ZONES_API + '/' + self .domain_id , query_params )
52
- records = data ['records' ]
53
- records = [{
54
- 'type' : r ['type' ],
55
- 'name' : r ['name' ],
56
- 'ttl' : r ['ttl' ],
57
- 'content' : r ['content' ],
58
- 'id' : r ['id' ],
59
- } for r in records ]
51
+ query_params ["recordName" ] = self ._full_name (name )
52
+ data = self ._get (_ZONES_API + "/" + self .domain_id , query_params )
53
+ records = data ["records" ]
54
+ records = [
55
+ {
56
+ "type" : r ["type" ],
57
+ "name" : r ["name" ],
58
+ "ttl" : r ["ttl" ],
59
+ "content" : r ["content" ],
60
+ "id" : r ["id" ],
61
+ }
62
+ for r in records
63
+ ]
60
64
for record in records :
61
65
self ._clean_TXT_record (record )
62
66
if content :
63
- records = [r for r in records if r [' content' ] == content ]
67
+ records = [r for r in records if r [" content" ] == content ]
64
68
return records
65
69
66
70
def update_record (self , identifier , rtype , name , content ):
@@ -71,25 +75,20 @@ def delete_record(self, identifier=None, rtype=None, name=None, content=None):
71
75
if identifier :
72
76
identifiers = [identifier ]
73
77
else :
74
- identifiers = [
75
- r ['id' ]
76
- for r in self .list_records (rtype , name , content )
77
- ]
78
+ identifiers = [r ["id" ] for r in self .list_records (rtype , name , content )]
78
79
for identifier in identifiers :
79
- self ._delete (
80
- _ZONES_API + '/' + self .domain_id + '/records/' + identifier
81
- )
80
+ self ._delete (_ZONES_API + "/" + self .domain_id + "/records/" + identifier )
82
81
return True
83
82
84
- def _request (self , action = ' GET' , url = '/' , data = None , query_params = None ):
83
+ def _request (self , action = " GET" , url = "/" , data = None , query_params = None ):
85
84
response = requests .request (
86
85
action ,
87
86
url ,
88
87
params = query_params ,
89
88
json = data ,
90
89
headers = {
91
- ' accept' : ' application/json' ,
92
- ' x-api-key' : self ._get_provider_option (' api_key' ),
90
+ " accept" : " application/json" ,
91
+ " x-api-key" : self ._get_provider_option (" api_key" ),
93
92
},
94
93
)
95
94
response .raise_for_status ()
0 commit comments