5858 pdns_api_key:
5959 description:
6060 - API Key to authenticate through PowerDNS API
61+ strict_ssl_checking:
62+ description:
63+ - Disables strict certificate checking
64+ default: false
6165author: "Thomas Krahn (@nosmoht)"
6266'''
6367
@@ -86,16 +90,22 @@ def __init__(self, url, status_code, message):
8690
8791
8892class PowerDNSClient :
89- def __init__ (self , host , port , prot , api_key ):
90- self .url = '{prot}://{host}:{port}' .format (prot = prot , host = host , port = port )
93+ def __init__ (self , host , port , prot , api_key , verify ):
94+ self .url = '{prot}://{host}:{port}/api/v1 ' .format (prot = prot , host = host , port = port )
9195 self .headers = {'X-API-Key' : api_key ,
9296 'content-type' : 'application/json' ,
9397 'accept' : 'application/json'
9498 }
99+ self .verify = verify
95100
96101 def _handle_request (self , req ):
97102 if req .status_code in [200 , 201 , 204 ]:
98- return json .loads (req .text )
103+ if req .text :
104+ try :
105+ return json .loads (req .text )
106+ except Exception as e :
107+ print (e ) # same as yield
108+ return dict ()
99109 elif req .status_code == 404 :
100110 error_message = 'Not found'
101111 else :
@@ -122,7 +132,7 @@ def _get_zone_url(self, server, name):
122132 return '{url}/{name}' .format (url = self ._get_zones_url (server ), name = name )
123133
124134 def get_zone (self , server , name ):
125- req = requests .get (url = self ._get_zone_url (server , name ), headers = self .headers )
135+ req = requests .get (url = self ._get_zone_url (server , name ), headers = self .headers , verify = self . verify )
126136 if req .status_code == 422 : # zone does not exist
127137 return None
128138 return self ._handle_request (req )
@@ -144,14 +154,14 @@ def create_record(self, server, zone, name, rtype, content, disabled, ttl):
144154 url = self ._get_zone_url (server = server , name = zone )
145155 data = self ._get_request_data (changetype = 'REPLACE' , server = server , zone = zone , name = name , rtype = rtype ,
146156 content = content , disabled = disabled , ttl = ttl )
147- req = requests .patch (url = url , data = json .dumps (data ), headers = self .headers )
157+ req = requests .patch (url = url , data = json .dumps (data ), headers = self .headers , verify = self . verify )
148158 return self ._handle_request (req )
149159
150160 def delete_record (self , server , zone , name , rtype ):
151161 url = self ._get_zone_url (server = server , name = zone )
152162 data = self ._get_request_data (changetype = 'DELETE' , server = server , zone = zone , name = name , rtype = rtype )
153163 # module.fail_json(msg=json.dumps(data))
154- req = requests .patch (url = url , data = json .dumps (data ), headers = self .headers )
164+ req = requests .patch (url = url , data = json .dumps (data ), headers = self .headers , verify = self . verify )
155165 return self ._handle_request (req )
156166
157167
@@ -230,14 +240,16 @@ def main():
230240 pdns_port = dict (type = 'int' , default = 8081 ),
231241 pdns_prot = dict (type = 'str' , default = 'http' , choices = ['http' , 'https' ]),
232242 pdns_api_key = dict (type = 'str' , required = False ),
243+ strict_ssl_checking = dict (type = 'boolean' , default = True ),
233244 ),
234245 supports_check_mode = True ,
235246 )
236247
237248 pdns_client = PowerDNSClient (host = module .params ['pdns_host' ],
238249 port = module .params ['pdns_port' ],
239250 prot = module .params ['pdns_prot' ],
240- api_key = module .params ['pdns_api_key' ])
251+ api_key = module .params ['pdns_api_key' ],
252+ verify = module .params ['strict_ssl_checking' ])
241253
242254 try :
243255 changed , record = ensure (module , pdns_client )
0 commit comments