''' @see https://www.inwx.de/de/help/apidoc/f/ch02.html#account.login ''' def api_macro_login( environment : str, username : str, password : str ): if ((username is None) or (password is None)): raise ValueError("username or password not given") else: response = ( api_call( environment, None, "account", "login", { "user": username, "pass": password, } ) ) return response["_accesstoken"] ''' @see https://www.inwx.de/de/help/apidoc/f/ch02.html#account.logout ''' def api_macro_logout( environment : str, accesstoken : str ): response = api_call( environment, accesstoken, "account", "logout", { } ) return None ''' @see https://www.inwx.de/de/help/apidoc/f/ch02.html#account.info ''' def api_macro_info( environment : str, username : str, password : str ): accesstoken = api_macro_login(environment, username, password) info = api_call( environment, accesstoken, "account", "info", { } ) api_macro_logout(environment, accesstoken) return info ''' @see https://www.inwx.de/de/help/apidoc/f/ch02s15.html#nameserver.info ''' def api_macro_list( environment : str, username : str, password : str, domain : str ): accesstoken = api_macro_login(environment, username, password) info = api_call( environment, accesstoken, "nameserver", "info", { "domain": domain, } ) api_macro_logout(environment, accesstoken) return info ''' @see https://www.inwx.de/de/help/apidoc/f/ch02s15.html#nameserver.info @see https://www.inwx.de/de/help/apidoc/f/ch02s15.html#nameserver.createRecord @see https://www.inwx.de/de/help/apidoc/f/ch02s15.html#nameserver.updateRecord ''' def api_macro_save( environment : str, username : str, password : str, domain_base : str, domain_path, type_ : str, content : str ): accesstoken = api_macro_login(environment, username, password) info = api_call( environment, accesstoken, "nameserver", "info", { "domain": domain_base, } ) matching = list( filter( lambda record: ( ( ( (domain_path is None) and (record["name"] == domain_base) ) or ( (domain_path is not None) and (record["name"] == (domain_path + "." + domain_base)) ) ) and (record["type"] == type_) ), info["record"] ) ) count = len(matching) if (count == 0): result = api_call( environment, accesstoken, "nameserver", "createRecord", { "domain": domain_base, "name": domain_path, "type": type_, "content": content, } ) id_ = result["id"] log("created record %u" % id_) elif (count == 1): id_ = matching[0]["id"] result = api_call( environment, accesstoken, "nameserver", "updateRecord", { "id": id_, "content": content, } ) log("updated record %u" % id_) else: log("found multiple records with this name and type") api_macro_logout(environment, accesstoken) ''' @see https://www.inwx.de/de/help/apidoc/f/ch02s15.html#nameserver.info @see https://www.inwx.de/de/help/apidoc/f/ch02s15.html#nameserver.deleteRecord ''' def api_macro_delete( environment : str, username : str, password : str, domain_base : str, domain_path, type_ ): accesstoken = api_macro_login(environment, username, password) info = api_call( environment, accesstoken, "nameserver", "info", { "domain": domain_base, } ) matching = list( filter( lambda record: ( ( ( (domain_path is None) and (record["name"] == domain_base) ) or ( (domain_path is not None) and (record["name"] == (domain_path + "." + domain_base)) ) ) and ( (type_ is None) or (record["type"] == type_) ) ), info["record"] ) ) for entry in matching: id_ = entry["id"] result = api_call( environment, accesstoken, "nameserver", "deleteRecord", { "id": id_, } ) api_macro_logout(environment, accesstoken)