#!/usr/bin/python3 def fetched(name=None, url="http://pki", username=None, password=None, domains=None, certfile=None, keyfile=None): ret = { 'name': name, 'changes': {}, 'result': False, 'comment': 'Config is up to date' } currentcert = None currentkey = None domain_concat = domains.join(',') currentcert = __salt__['pki.get_file_content'](checkfile=certfile) currentkey = __salt__['pki.get_file_content'](checkfile=keyfile) newcert, newkey = __salt__['pki.get_pki_cert'](url=url, username=username, password=password, domains=domain_concat) if currentcert != newcert or currentkey != newkey: wcert = __salt__['pki.write_file_content'](newcert, certfile) wkey = __salt__['pki.write_file_content'](newkey, keyfile) ret["changes"]["old"] = [currentcert,currentkey].join("\n") ret["changes"]["new"] = [newcert,newkey].join("\n") ret["changes"]["diff"] = salt.utils.stringutils.get_diff([currentcert,currentkey].join("\n"), [newcert,newkey].join("\n")) ret["comment"] = "Updated certificates and keys" ret["result"] = all([wcert, wkey]) return ret