def add_txt_record(self, domain, record_name, record_content, record_ttl): """ Add a TXT record using the supplied information. :param str domain: The domain to use to look up the Alidns zone. :param str record_name: The record name (typically beginning with '_acme-challenge.'). :param str record_content: The record content (typically the challenge validation). :param int record_ttl: The record TTL (number of seconds that the record may be cached). :raises certbot.errors.PluginError: if an error occurs communicating with the Aliyun API """ if self._find_txt_record_id(domain, record_name, record_content): logger.debug('TXT record exited; no add needed.') return request = AddDomainRecordRequest() domain_root = '.'.join(domain.split('.')[-2:]) doamin_rr = record_name[:record_name.find(domain_root) - 1] request.set_accept_format('json') request.set_DomainName(domain_root) request.set_Type("TXT") request.set_RR(doamin_rr) request.set_Value(record_content) request.set_TTL(record_ttl) try: self.ac.do_action_with_exception(request) except ClientException as e: logger.error( 'Encountered ClientException adding TXT record: %d %s', e, e) raise errors.PluginError( 'Error communicating with the aliyun API: {0}'.format(e))
def create_domain_record(self, domain, rr, record_type, value, ttl): request = AddDomainRecordRequest() if ttl is not None: request.set_TTL(ttl) request.set_Type(record_type) request.set_RR(rr) request.set_Value(value) request.set_DomainName(domain) request.set_accept_format("JSON") return json.loads(self.clt.do_action_with_exception(request))
def add_record(self, *args, **kwargs): request = AddDomainRecordRequest() request.set_accept_format('json') request.set_DomainName(kwargs.get('domain_name')) request.set_RR(kwargs.get('domain_rr')) request.set_Type(kwargs.get('domain_type')) request.set_Value(kwargs.get('domain_value')) request.set_TTL(kwargs.get('domain_ttl')) request.set_Line(kwargs.get('line')) response = self.__client.do_action_with_exception(request) return json.loads(str(response, encoding="utf8")).get('RecordId')
def __add_record(self, record, value, record_type, ttl): '''Add record.''' req = AddDomainRecordRequest() req.set_DomainName(self.__domain) req.set_accept_format('json') req.set_RR(record) req.set_Type(record_type) req.set_TTL(ttl) req.set_Value(value) js = json.loads(self.__bs.do_action_with_exception(req).decode()) print('[+]%8s.%s -> %-16s; %-8s;%s' % (record, self.__domain, value, record_type, ttl))
def add_txt_record(self, domain, record_name, record_value, ttl): rr = record_name[:record_name.rindex('.' + domain)] request = AddDomainRecordRequest() request.set_accept_format("json") request.set_DomainName(domain) request.set_Type("TXT") request.set_RR(rr) request.set_Value(record_value) request.set_TTL(ttl) self._client.do_action_with_exception(request)
def add_record(self, rr=None, type=None, line=None, value=None, ttl=600, mx=None): """ 添加记录 :return: True|False """ try: if type == "显示URL": type = "REDIRECT_URL" if type == "隐性URL": type = "FORWARD_URL" client = AcsClient(self.key, self.secret, 'cn-hangzhou') request = AddDomainRecordRequest() request.set_accept_format('json') request.set_Line(self.record_line(value=line)) request.set_TTL(600 if int(ttl) < 600 else int(ttl)) request.set_Value(value) request.set_Type(type) # request.set_RR(RR + ("." + self.prefix_domain if self.prefix_domain else "")) if self.prefix_domain: rr = ''.join([rr, ".", self.prefix_domain]) request.set_RR(rr) request.set_DomainName(self.second_level_domain) if type == "MX": request.set_Priority(mx) response = client.do_action_with_exception(request) response = json.loads(response) if "Code" in response.keys(): print(F"add record failed: {response}") return False print(F"add record success: {rr}") return True except Exception: print("add record unknown exception") print(traceback.format_exc()) return False
def add_record(self, priority, ttl, record_type, value, rr, domain_name): logging.info("添加域名解析记录") from aliyunsdkalidns.request.v20150109.AddDomainRecordRequest import AddDomainRecordRequest request = AddDomainRecordRequest() request.set_accept_format('json') request.set_Priority(priority) request.set_TTL(ttl) request.set_Value(value) request.set_Type(record_type) request.set_RR(rr) request.set_DomainName(domain_name) response = self.client.do_action_with_exception(request) response = str(response, encoding='utf-8') result = json.loads(response) logging.debug(result) return result
def add_record(self, obj): self.client = AcsClient(obj.domain_name.account.access_id, obj.domain_name.account.access_key, 'cn-hangzhou') request = AddDomainRecordRequest() request.set_accept_format('json') request.set_TTL(obj.ttl) request.set_Line(obj.line) request.set_Value(obj.value) request.set_Type(obj.type) request.set_RR(obj.rr) request.set_DomainName(obj.domain_name.domain_name) if obj.priority: request.set_Priority(obj.priority) try: response = self.client.do_action_with_exception(request) ret = json.loads(str(response, encoding='utf-8')) return {'code': 1, 'message': ret} except Exception as e: return {'code': 0, 'message': e}