def renew_domain_request(self, domain, period): request = E.renewDomainRequest( _domain(domain), E.period(period), ) response = self.request(request) return response.as_model(Model)
def request(self, tree, **kwargs): """ Construct a new request with the given tree as its contents, then ship it to the OpenProvider API. """ apirequest = lxml.etree.tostring( E.openXML( E.credentials( E.username(self.username), OE('password', self.password), OE('hash', self.password_hash), ), tree ), method='c14n' ) try: apiresponse = self.session.post(self.url, data=apirequest) apiresponse.raise_for_status() except requests.RequestException as e: raise ServiceUnavailable(str(e)) tree = lxml.objectify.fromstring(apiresponse.content) if tree.reply.code == 0: return Response(tree) else: klass = from_code(tree.reply.code) desc = tree.reply.desc code = tree.reply.code data = getattr(tree.reply, 'data', '') raise klass(u"{0} ({1}) {2}".format(desc, code, data), code)
def create_domain_request(self, domain, period, owner_handle, admin_handle, tech_handle, billing_handle=None, reseller_handle=None, ns_group=None, ns_template_name=None, name_servers=None, use_domicile=False, promo_code=None, autorenew=None, comments=None, dnssec_keys=None, application_mode=None, is_private_whois_enabled=None, additional_data=None): request = E.createDomainRequest( _domain(domain), E.period(period), E.ownerHandle(owner_handle), E.adminHandle(admin_handle), E.techHandle(tech_handle), OE('billingHandle', billing_handle), OE('resellerHandle', reseller_handle), OE('nsGroup', ns_group), OE('nsTemplateName', ns_template_name), OE('nameServers', name_servers, transform=_nameservers), OE('useDomicile', use_domicile, transform=int), OE('promoCode', promo_code), OE('autorenew', autorenew), OE('comments', comments), OE('dnssecKeys', dnssec_keys, transform=_dnssec_keys), OE('applicationMode', application_mode), OE('isPrivateWhoisEnabled', is_private_whois_enabled, transform=int), _additional_data(additional_data), ) response = self.request(request) return response.as_model(Model)
def retrieve_product(self, product_id): """Retrieve details on a single product.""" response = self.request( E.retrieveProductSslCertRequest(E.id(product_id))) return response.as_model(SSLProduct)
def _domain(domain): sld, tld = domain.split('.', 1) return E.domain( E.name(sld), E.extension(tld), )
def trade_domain_request(self, domain, period, owner_handle, admin_handle, tech_handle, billing_handle=None, reseller_handle=None, auth_code=None, ns_group=None, ns_template_name=None, name_servers=None, use_domicile=None, promo_code=None, dnssec_keys=None): request = E.tradeDomainRequest( _domain(domain), E.period(period), E.ownerHandle(owner_handle), E.adminHandle(admin_handle), E.techHandle(tech_handle), OE('billingHandle', billing_handle), OE('resellerHandle', reseller_handle), OE('authCode', auth_code), OE('nsGroup', ns_group), OE('nsTemplateName', ns_template_name), OE('nameServers', name_servers, transform=_nameservers), OE('useDomicile', use_domicile, transform=int), OE('promoCode', promo_code), OE('dnssecKeys', dnssec_keys, transform=_dnssec_keys), ) response = self.request(request) return response.as_model(Model)
def resend_approver_email(self, order_id): """Resend the activation email to the approver.""" response = self.request( E.resendApproverEmailSslCertRequest(E.id(order_id))) return int(response.data.id)
def reissue(self, order_id, csr, software_id, organization_handle, approver_email=None, signature_hash_algorithm=None, domain_validation_methods=None, hostnames=None, technical_handle=None): """Reissue an SSL certificate order""" response = self.request( E.reissueSslCertRequest( E.id(order_id), E.csr(csr), E.softwareId(software_id), E.organizationHandle(organization_handle), OE('approverEmail', approver_email), OE('signatureHashAlgorithm', signature_hash_algorithm), OE('domainValidationMethods', domain_validation_methods, transform=_domain_validation_methods), OE('hostNames', hostnames, transform=_simple_array), OE('technicalHandle', technical_handle), )) return int(response.data.id)
def search_customer_email_verification_request(self, email): request = E.searchCustomerEmailVerificationRequest(E.email(email)) response = self.request(request) try: return [Model(item) for item in response.data.results.array.item] except AttributeError: return []
def retrieve_domain_request(self, domain, additional_data=False, registry_details=False): request = E.retrieveDomainRequest( _domain(domain), E.withAdditionalData(int(additional_data)), E.withRegistryDetails(int(registry_details)), ) response = self.request(request) return response.as_model(DomainDetails)
def change_approver_email_address(self, order_id, approver_email): """Change the approver email address for an ordered SSL certificate.""" response = self.request( E.changeApproverEmailAddressSslCertRequest( E.id(order_id), E.approverEmail(approver_email))) return int(response.data.id)
def approve_transfer_domain_request(self, domain, approve, registrar_tag=None): request = E.approveTransferDomainRequest( _domain(domain), E.approve(int(approve)), OE('registrarTag', registrar_tag), ) response = self.request(request) return response.as_model(Model)
def retrieve_approver_email_list(self, domain, product_id): """Retrieve the list of allowed approver email addresses.""" response = self.request( E.retrieveApproverEmailListSslCertRequest(E.domain(domain), E.productId(product_id))) return [str(i) for i in response.data.array[0].item]
def _domain_validation_methods(methods): if not methods: return None items = [ E.item(E.hostName(hostname), E.method(method)) for hostname, method in methods.items() ] return E.array(*items)
def retrieve_customer(self, handle, with_additional_data=False): """Retrieve information of an existing customer.""" response = self.request(E.retrieveCustomerRequest( E.handle(handle), E.withAdditionalData(int(with_additional_data)), )) return response.as_model(Customer)
def retrieve_customer(self, handle, with_additional_data=False): """Retrieve information of an existing customer.""" response = self.request( E.retrieveCustomerRequest( E.handle(handle), E.withAdditionalData(int(with_additional_data)), )) return response.as_model(Customer)
def _get_phone_xml(parent, number): if not number: return '' country, area, subscriber = parse_phone_number(number) return E(parent, E.countryCode(country), E.areaCode(area), E.subscriberNumber(subscriber), )
def _get_phone_xml(parent, number): if not number: return '' country, area, subscriber = parse_phone_number(number) return E( parent, E.countryCode(country), E.areaCode(area), E.subscriberNumber(subscriber), )
def retrieve_extension(self, name, **kw): """Retrieve details on a single extension.""" response = self.request( E.retrieveExtensionRequest( E.name(name), E.withDescription(int(kw.get('with_description', 0))), E.withPrice(int(kw.get('with_price', 0))), E.withUsageCount(int(kw.get('with_usage_count', 0))), )) return response.as_model(Extension)
def modify_master_zone_dns_request(self, domain, records=None): """Modify DNS Records""" self.request( E.modifyZoneDnsRequest( _domain(domain), E.type('master'), _records(records), ), ) return True
def _additional_data(data): if data is None: return None element = E.additionalData() for key, value in data.items(): if key == 'birth_date': try: value = value.strftime('%Y-%m-%d') except AttributeError: pass element.append(E(snake_to_camel(key), value)) return element
def retrieve_extension(self, name, **kw): """Retrieve details on a single extension.""" response = self.request( E.retrieveExtensionRequest( E.name(name), E.withDescription(int(kw.get("with_description", 0))), E.withPrice(int(kw.get("with_price", 0))), E.withUsageCount(int(kw.get("with_usage_count", 0))), ) ) return response.as_model(Extension)
def request_auth_code_domain_request(self, domain, auth_code_type=None): request = E.requestAuthCodeDomainRequest( _domain(domain), OE('authCodeType', auth_code_type), ) response = self.request(request) return response.as_model(Model)
def retrieve_price_domain_request(self, domain, operation=None): request = E.retrievePriceDomainRequest( _domain(domain), OE('operation', operation), ) response = self.request(request) return response.as_model(Model)
def modify(self, order_id, approver_email=None, domain_validation_methods=None): """Modify an ordered SSL certificate.""" response = self.request( E.modifySslCertRequest( E.id(order_id), OE('approverEmail', approver_email), OE('domainValidationMethods', domain_validation_methods, transform=_domain_validation_methods), )) return response.data
def create(self, product_id, period, csr, software_id, organization_handle, approver_email, signature_hash_algorithm=None, domain_validation_methods=None, hostnames=None, technical_handle=None): """Order a new SSL certificate.""" response = self.request( E.createSslCertRequest( E.productId(product_id), E.period(period), E.csr(csr), E.softwareId(software_id), E.organizationHandle(organization_handle), E.approverEmail(approver_email), OE('signatureHashAlgorithm', signature_hash_algorithm), OE('domainValidationMethods', domain_validation_methods, transform=_domain_validation_methods), OE('hostNames', hostnames, transform=_simple_array), OE('technicalHandle', technical_handle), )) return int(response.data.id)
def search_order(self, limit=100, offset=0, common_name_pattern=None, status=None, contact_handle=None): """Search all SSL certificate orders.""" response = self.request( E.searchOrderSslCertRequest( E.limit(limit), E.offset(offset), OE('commonNamePattern', common_name_pattern), OE('status', status, transform=_simple_array), OE('contactHandle', contact_handle), )) return response.as_models(SSLOrder)
def retrieve_zone_dns_request(self, name, with_records=True, with_history=False): request = E.retrieveZoneDnsRequest( OE('name', name), OE('withRecords', with_records), OE('withHistory', with_history), ) response = self.request(request) return response.as_model(ZoneDetails)
def _dnssec_keys(keys): items = [ E.item(E.flags(key.flags), E.alg(key.alg), E.protocol(getattr(key, 'protocol', 3)), E.pubKey(key.pubkey)) for key in keys ] return E.array(*items)
def search_zone_dns_request(self, limit=None, offset=None, extension=None, name_pattern=None, type=None, with_records=None, with_history=None): request = E.searchZoneDnsRequest( OE('limit', limit), OE('offset', offset), OE('namePattern', name_pattern), OE('type', type), OE('withRecords', with_records), OE('withHistory', with_history), ) response = self.request(request) return response.as_models(ZoneDetails)
def search_domain_request(self, limit=None, offset=None, extension=None, domain_name_pattern=None, contact_handle=None, ns_group_pattern=None, status=None, with_addition_data=None): request = E.searchDomainRequest( OE('limit', limit), OE('offset', offset), OE('extension', extension), OE('domainNamePattern', domain_name_pattern), OE('contactHandle', contact_handle), OE('nsGroupPattern', ns_group_pattern), OE('status', status), OE('withAdditionalData', with_addition_data), ) response = self.request(request) return response.as_models(DomainDetails)
def search_customer(self, limit=100, offset=0, email_pattern=None, last_name_pattern=None, company_name_pattern=None, with_additional_data=False): """Search the list of customers.""" response = self.request(E.searchCustomerRequest( E.limit(limit), E.offset(offset), E.emailPattern(email_pattern or ''), E.lastNamePattern(last_name_pattern or ''), E.companyNamePattern(company_name_pattern or ''), E.withAdditionalData(int(with_additional_data)), )) return response.as_models(Customer)
def search_extension(self, limit=100, offset=0, **kw): """Search the list of available extensions.""" response = self.request( E.searchExtensionRequest( E.limit(limit), E.offset(offset), E.withDescription(int(kw.get('with_description', 0))), E.withPrice(int(kw.get('with_price', 0))), E.withUsageCount(int(kw.get('with_usage_count', 0))), )) return response.as_models(Extension)
def search_extension(self, limit=100, offset=0, **kw): """Search the list of available extensions.""" response = self.request( E.searchExtensionRequest( E.limit(limit), E.offset(offset), E.withDescription(int(kw.get("with_description", 0))), E.withPrice(int(kw.get("with_price", 0))), E.withUsageCount(int(kw.get("with_usage_count", 0))), ) ) return response.as_models(Extension)
def search_customer(self, limit=100, offset=0, email_pattern=None, last_name_pattern=None, company_name_pattern=None, with_additional_data=False): """Search the list of customers.""" response = self.request( E.searchCustomerRequest( E.limit(limit), E.offset(offset), E.emailPattern(email_pattern or ''), E.lastNamePattern(last_name_pattern or ''), E.companyNamePattern(company_name_pattern or ''), E.withAdditionalData(int(with_additional_data)), )) return response.as_models(Customer)
def check_domain_request(self, domains): """ Return the availability of one or more domain names. The availability is a model containing a domain and a status. It can also have a premium attribute in case the domain has non-default costs. """ request = E.checkDomainRequest( E.domains( E.array(*[ E.item(E.name(domain.split(".")[0]), E.extension(domain.split(".")[1])) for domain in domains ]))) response = self.request(request) return [Model(item) for item in response.data.array.item]
def search_product(self, limit=100, offset=0, with_price=0, with_supported_software=0, with_description=0): """Search the list of available products.""" response = self.request( E.searchProductSslCertRequest( E.limit(limit), E.offset(offset), E.withPrice(int(with_price)), E.withSupportedSoftware(int(with_supported_software)), E.withDescription(int(with_description)), )) return response.as_models(SSLProduct)
def check_domain_request(self, domains): """ Return the availability of one or more domain names. The availability is a model containing a domain and a status. It can also have a premium attribute in case the domain has non-default costs. """ request = E.checkDomainRequest( E.domains( E.array( *[E.item( E.name(domain.split(".")[0]), E.extension(domain.split(".")[1]) ) for domain in domains] ) ) ) response = self.request(request) return [Model(item) for item in response.data.array.item]
def _dnssec_keys(keys): items = [E.item(E.flags(key.flags), E.alg(key.alg), E.protocol(getattr(key, 'protocol', 3)), E.pubKey(key.pubkey)) for key in keys] return E.array(*items)
def _nameservers(nameservers): items = [E.item(E.name(ns.name), OE('ip', ns.ip), OE('ip6', ns.ip6)) for ns in nameservers] return E.array(*items)
def restore_domain_request(self, domain): request = E.restoreDomainRequest(_domain(domain)) response = self.request(request) return response.as_model(Model)
def modify_customer(self, handle, address, phone, email=None, vat=None, fax=None, company_name=None, additional_data=None, extension_additional_data=None): """Modify a customer.""" self.request(E.modifyCustomerRequest( E.handle(handle), E.vat(vat or ''), _get_phone_xml('phone', phone), _get_phone_xml('fax', fax), E.address( E.street(address.street), E.number(address.number), E.suffix(address.suffix or ''), E.zipcode(address.zipcode), E.city(address.city), E.state(address.state or ''), E.country(address.country), ), E.email(email or ''), _additional_data(additional_data), _extension_additional_data(extension_additional_data), )) return True
def delete_customer(self, handle): """Delete a customer.""" self.request(E.deleteCustomerRequest(E.handle(handle))) return True
def modify_customer(self, handle, address, phone, email=None, vat=None, fax=None, company_name=None, additional_data=None, extension_additional_data=None): """Modify a customer.""" self.request( E.modifyCustomerRequest( E.handle(handle), E.vat(vat or ''), _get_phone_xml('phone', phone), _get_phone_xml('fax', fax), E.address( E.street(address.street), E.number(address.number), E.suffix(address.suffix or ''), E.zipcode(address.zipcode), E.city(address.city), E.state(address.state or ''), E.country(address.country), ), E.email(email or ''), _additional_data(additional_data), _extension_additional_data(extension_additional_data), )) return True
def _extension_additional_data(data): if data is None: return None return E.extensionAdditionalData(E(snake_to_camel(key), value) for key, value in data.items())
def _additional_data(data): if not data: return None items = [E(key, value) for key, value in data.items()] return E.additionalData(*items)
def reset_auth_code_domain_request(self, domain): request = E.resetAuthCodeDomainRequest(_domain(domain)) response = self.request(request) return response.as_model(Model)
def create_customer(self, name, gender, address, phone, email, vat=None, fax=None, company_name=None, additional_data=None, extension_additional_data=None): """Create a customer""" response = self.request(E.createCustomerRequest( E.companyName(company_name), E.vat(vat), E.name( E.initials(name.initials), E.firstName(name.first_name), E.prefix(name.prefix or ''), E.lastName(name.last_name), ), E.gender(gender), _get_phone_xml('phone', phone), _get_phone_xml('fax', fax), E.address( E.street(address.street), E.number(address.number), E.suffix(address.suffix or ''), E.zipcode(address.zipcode), E.city(address.city), E.state(address.state or ''), E.country(address.country), ), E.email(email), _additional_data(additional_data), _extension_additional_data(extension_additional_data), )) return str(response.data.handle)
def try_again_domain_request(self, domain): request = E.tryAgainDomainRequest(_domain(domain)) response = self.request(request) return response.as_model(Model)