22
33from lexicon .interfaces import Provider as BaseProvider
44
5-
6- _ZONES_API = 'https://api.hosting.ionos.com/dns/v1/zones'
5+ _ZONES_API = "https://api.hosting.ionos.com/dns/v1/zones"
76
87
98class Provider (BaseProvider ):
109
1110 @staticmethod
1211 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" ]
1413
1514 @staticmethod
1615 def configure_parser (parser ):
1716 parser .add_argument (
18- ' --api-key' ,
17+ " --api-key" ,
1918 required = True ,
20- help = ' IONOS api key: public prefix + period + key proper' ,
19+ help = " IONOS api key: public prefix + period + key proper" ,
2120 )
2221
2322 def authenticate (self ):
2423 zones = self ._get (_ZONES_API )
2524 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" ]
2827 return
29- raise Exception (' domain not found: ' + self .domain )
28+ raise Exception (" domain not found: " + self .domain )
3029
3130 def create_record (self , rtype , name , content ):
3231 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+ ],
4243 )
4344 return True
4445
4546 def list_records (self , rtype = None , name = None , content = None ):
4647 query_params = {}
4748 if rtype :
48- query_params [' recordType' ] = rtype
49+ query_params [" recordType" ] = rtype
4950 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+ ]
6064 for record in records :
6165 self ._clean_TXT_record (record )
6266 if content :
63- records = [r for r in records if r [' content' ] == content ]
67+ records = [r for r in records if r [" content" ] == content ]
6468 return records
6569
6670 def update_record (self , identifier , rtype , name , content ):
@@ -71,25 +75,20 @@ def delete_record(self, identifier=None, rtype=None, name=None, content=None):
7175 if identifier :
7276 identifiers = [identifier ]
7377 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 )]
7879 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 )
8281 return True
8382
84- def _request (self , action = ' GET' , url = '/' , data = None , query_params = None ):
83+ def _request (self , action = " GET" , url = "/" , data = None , query_params = None ):
8584 response = requests .request (
8685 action ,
8786 url ,
8887 params = query_params ,
8988 json = data ,
9089 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" ),
9392 },
9493 )
9594 response .raise_for_status ()
0 commit comments