Skip to content

Commit

Permalink
Merge 1e9863f into 8a8934e
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogJ committed Apr 3, 2016
2 parents 8a8934e + 1e9863f commit d836ade
Show file tree
Hide file tree
Showing 22 changed files with 1,775 additions and 32 deletions.
114 changes: 114 additions & 0 deletions lexicon/providers/namesilo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
from base import Provider as BaseProvider
import requests
from xml.etree import ElementTree

class Provider(BaseProvider):

def __init__(self, options, provider_options={}):
super(Provider, self).__init__(options)
self.domain_id = None
self.api_endpoint = provider_options.get('api_endpoint') or 'https://www.namesilo.com/api'

def authenticate(self):

payload = self._get('/getDomainInfo', {'domain': self.options['domain']})
self.domain_id = self.options['domain']


# Create record. If record already exists with the same content, do nothing'
def create_record(self, type, name, content):
record = {
'domain': self.domain_id,
'rrhost': self._relative_name(name),
'rrtype': type,
'rrvalue': content
}
payload = self._get('/dnsAddRecord', record)
print 'create_record: {0}'.format(True)
return True

# List all records. Return an empty list if no records found
# type, name and content are used to filter records.
# If possible filter during the query, otherwise filter after response is received.
def list_records(self, type=None, name=None, content=None):
query = {'domain': self.domain_id}

payload = self._get('/dnsListRecords', query)
records = []
for record in payload.find('reply').findall('resource_record'):
processed_record = {
'type': record.find('type').text,
'name': record.find('host').text,
'ttl': record.find('ttl').text,
'content': record.find('value').text,
'id': record.find('record_id').text
}
records.append(processed_record)

if type:
records = [record for record in records if record['type'] == type]
if name:
records = [record for record in records if record['name'] == self._full_name(name)]
if content:
records = [record for record in records if record['content'] == content]

print 'list_records: {0}'.format(records)
return records

# Create or update a record.
def update_record(self, identifier, type=None, name=None, content=None):

data = {
'domain': self.domain_id,
'rrid': identifier
}
# if type:
# data['rtype'] = type
if name:
data['rrhost'] = self._relative_name(name)
if content:
data['rdata'] = content

payload = self._get('/dnsUpdateRecord', data)

print 'update_record: {0}'.format(True)
return True

# Delete an existing record.
# If record does not exist, do nothing.
def delete_record(self, identifier=None, type=None, name=None, content=None):
data = {
'domain': self.domain_id
}
if not identifier:
records = self.list_records(type, name, content)
print records
if len(records) == 1:
data['rrid'] = records[0]['id']
else:
raise StandardError('Record identifier could not be found.')
else:
data['rrid'] = identifier
payload = self._get('/dnsDeleteRecord', data)

print 'delete_record: {0}'.format(True)
return True


# Helpers
def _request(self, action='GET', url='/', data={}, query_params={}):

query_params['version'] = 1
query_params['type'] = 'xml'
query_params['key'] = self.options.get('auth_password') or self.options.get('auth_token')
r = requests.request(action, self.api_endpoint + url, params=query_params)
#data=json.dumps(data))
r.raise_for_status() # if the request fails for any reason, throw an error.
# TODO: check if the response is an error using
tree = ElementTree.ElementTree(ElementTree.fromstring(r.content))
root = tree.getroot()
if root.find('reply').find('code').text != '300':
raise StandardError('An error occurred: {0}, {1}'.format(root.find('reply').find('detail').text, root.find('reply').find('code').text))


return root
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
User-Agent: [python-requests/2.9.1]
method: GET
uri: http://sandbox.namesilo.com/api/getDomainInfo?domain=capsulecdfake.com&version=1&type=xml
response:
body: {string: !!python/unicode '<?xml version="1.0"?>

<namesilo><request><operation>getDomainInfo</operation><ip>208.72.142.184</ip></request><reply><code>300</code><detail>success</detail><created>2016-04-02</created><expires>2018-04-02</expires><status>Active</status><locked>Yes</locked><private>Yes</private><auto_renew>Yes</auto_renew><traffic_type>Parked</traffic_type><forward_url>N/A</forward_url><forward_type>N/A</forward_type><nameservers><nameserver
position="1">NS1.NAMESILO.COM</nameserver><nameserver position="2">NS2.NAMESILO.COM</nameserver></nameservers><contact_ids><registrant>1321</registrant><administrative>1321</administrative><technical>1321</technical><billing>1321</billing></contact_ids></reply></namesilo>

'}
headers:
cache-control: ['no-store, no-cache, must-revalidate, post-check=0, pre-check=0']
connection: [keep-alive]
content-length: ['703']
content-type: [text/xml]
date: ['Sun, 03 Apr 2016 02:35:27 GMT']
expires: ['Thu, 19 Nov 1981 08:52:00 GMT']
pragma: [no-cache]
server: [nginx]
set-cookie: [PHPSESSID=28e8686ba8abbccb0f9a652331a76c21; path=/; domain=dev.namesilo.com]
transfer-encoding: [chunked]
vary: [Accept-Encoding]
x-proxy-cache: [MISS]
status: {code: 200, message: OK}
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
User-Agent: [python-requests/2.9.1]
method: GET
uri: http://sandbox.namesilo.com/api/getDomainInfo?domain=thisisadomainidonotown.com&version=1&type=xml
response:
body: {string: !!python/unicode '<?xml version="1.0"?>

<namesilo><request><operation>getDomainInfo</operation><ip>208.72.142.184</ip></request><reply><code>200</code><detail>Domain
is not active, or does not belong to this user</detail></reply></namesilo>

'}
headers:
cache-control: ['no-store, no-cache, must-revalidate, post-check=0, pre-check=0']
connection: [keep-alive]
content-length: ['223']
content-type: [text/xml]
date: ['Sun, 03 Apr 2016 02:35:28 GMT']
expires: ['Thu, 19 Nov 1981 08:52:00 GMT']
pragma: [no-cache]
server: [nginx]
set-cookie: [PHPSESSID=65e1ce568b1e4c4f96e2f90a519edc49; path=/; domain=dev.namesilo.com]
transfer-encoding: [chunked]
vary: [Accept-Encoding]
x-proxy-cache: [MISS]
status: {code: 200, message: OK}
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
User-Agent: [python-requests/2.9.1]
method: GET
uri: http://sandbox.namesilo.com/api/getDomainInfo?domain=capsulecdfake.com&version=1&type=xml
response:
body: {string: !!python/unicode '<?xml version="1.0"?>

<namesilo><request><operation>getDomainInfo</operation><ip>208.72.142.184</ip></request><reply><code>300</code><detail>success</detail><created>2016-04-02</created><expires>2018-04-02</expires><status>Active</status><locked>Yes</locked><private>Yes</private><auto_renew>Yes</auto_renew><traffic_type>Parked</traffic_type><forward_url>N/A</forward_url><forward_type>N/A</forward_type><nameservers><nameserver
position="1">NS1.NAMESILO.COM</nameserver><nameserver position="2">NS2.NAMESILO.COM</nameserver></nameservers><contact_ids><registrant>1321</registrant><administrative>1321</administrative><technical>1321</technical><billing>1321</billing></contact_ids></reply></namesilo>

'}
headers:
cache-control: ['no-store, no-cache, must-revalidate, post-check=0, pre-check=0']
connection: [keep-alive]
content-length: ['703']
content-type: [text/xml]
date: ['Sun, 03 Apr 2016 02:47:33 GMT']
expires: ['Thu, 19 Nov 1981 08:52:00 GMT']
pragma: [no-cache]
server: [nginx]
set-cookie: [PHPSESSID=cac2fe2a37a859758021618cfad01f10; path=/; domain=dev.namesilo.com]
vary: [Accept-Encoding]
x-proxy-cache: [MISS]
status: {code: 200, message: OK}
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
User-Agent: [python-requests/2.9.1]
method: GET
uri: http://sandbox.namesilo.com/api/dnsAddRecord?rrvalue=127.0.0.1&domain=capsulecdfake.com&rrhost=localhost&rrtype=A&version=1&type=xml
response:
body: {string: !!python/unicode '<?xml version="1.0"?>

<namesilo><request><operation>dnsAddRecord</operation><ip>208.72.142.184</ip></request><reply><code>300</code><detail>success</detail><record_id>b318260397dd3e024bedb73f3eeee938</record_id></reply></namesilo>

'}
headers:
cache-control: ['no-store, no-cache, must-revalidate, post-check=0, pre-check=0']
connection: [keep-alive]
content-length: ['231']
content-type: [text/xml]
date: ['Sun, 03 Apr 2016 02:55:42 GMT']
expires: ['Thu, 19 Nov 1981 08:52:00 GMT']
pragma: [no-cache]
server: [nginx]
set-cookie: [PHPSESSID=2990773d9b81a0f1f543b7e0dfeaca0d; path=/; domain=dev.namesilo.com]
transfer-encoding: [chunked]
vary: [Accept-Encoding]
x-proxy-cache: [MISS]
status: {code: 200, message: OK}
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
User-Agent: [python-requests/2.9.1]
method: GET
uri: http://sandbox.namesilo.com/api/getDomainInfo?domain=capsulecdfake.com&version=1&type=xml
response:
body: {string: !!python/unicode '<?xml version="1.0"?>

<namesilo><request><operation>getDomainInfo</operation><ip>208.72.142.184</ip></request><reply><code>300</code><detail>success</detail><created>2016-04-02</created><expires>2018-04-02</expires><status>Active</status><locked>Yes</locked><private>Yes</private><auto_renew>Yes</auto_renew><traffic_type>Parked</traffic_type><forward_url>N/A</forward_url><forward_type>N/A</forward_type><nameservers><nameserver
position="1">NS1.NAMESILO.COM</nameserver><nameserver position="2">NS2.NAMESILO.COM</nameserver></nameservers><contact_ids><registrant>1321</registrant><administrative>1321</administrative><technical>1321</technical><billing>1321</billing></contact_ids></reply></namesilo>

'}
headers:
cache-control: ['no-store, no-cache, must-revalidate, post-check=0, pre-check=0']
connection: [keep-alive]
content-length: ['703']
content-type: [text/xml]
date: ['Sun, 03 Apr 2016 02:47:33 GMT']
expires: ['Thu, 19 Nov 1981 08:52:00 GMT']
pragma: [no-cache]
server: [nginx]
set-cookie: [PHPSESSID=bf2cf2bceaa9b7dee5ac5e981b7b6a44; path=/; domain=dev.namesilo.com]
vary: [Accept-Encoding]
x-proxy-cache: [MISS]
status: {code: 200, message: OK}
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
User-Agent: [python-requests/2.9.1]
method: GET
uri: http://sandbox.namesilo.com/api/dnsAddRecord?rrvalue=docs.example.com&domain=capsulecdfake.com&rrhost=docs&rrtype=CNAME&version=1&type=xml
response:
body: {string: !!python/unicode '<?xml version="1.0"?>

<namesilo><request><operation>dnsAddRecord</operation><ip>208.72.142.184</ip></request><reply><code>300</code><detail>success</detail><record_id>f8bcfa159c3386ea456bb083036a10f5</record_id></reply></namesilo>

'}
headers:
cache-control: ['no-store, no-cache, must-revalidate, post-check=0, pre-check=0']
connection: [keep-alive]
content-length: ['231']
content-type: [text/xml]
date: ['Sun, 03 Apr 2016 02:55:43 GMT']
expires: ['Thu, 19 Nov 1981 08:52:00 GMT']
pragma: [no-cache]
server: [nginx]
set-cookie: [PHPSESSID=198c99d7f61eaf7dc854e175521c5c12; path=/; domain=dev.namesilo.com]
transfer-encoding: [chunked]
vary: [Accept-Encoding]
x-proxy-cache: [MISS]
status: {code: 200, message: OK}
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
User-Agent: [python-requests/2.9.1]
method: GET
uri: http://sandbox.namesilo.com/api/getDomainInfo?domain=capsulecdfake.com&version=1&type=xml
response:
body: {string: !!python/unicode '<?xml version="1.0"?>

<namesilo><request><operation>getDomainInfo</operation><ip>208.72.142.184</ip></request><reply><code>300</code><detail>success</detail><created>2016-04-02</created><expires>2018-04-02</expires><status>Active</status><locked>Yes</locked><private>Yes</private><auto_renew>Yes</auto_renew><traffic_type>Parked</traffic_type><forward_url>N/A</forward_url><forward_type>N/A</forward_type><nameservers><nameserver
position="1">NS1.NAMESILO.COM</nameserver><nameserver position="2">NS2.NAMESILO.COM</nameserver></nameservers><contact_ids><registrant>1321</registrant><administrative>1321</administrative><technical>1321</technical><billing>1321</billing></contact_ids></reply></namesilo>

'}
headers:
cache-control: ['no-store, no-cache, must-revalidate, post-check=0, pre-check=0']
connection: [keep-alive]
content-length: ['703']
content-type: [text/xml]
date: ['Sun, 03 Apr 2016 02:47:33 GMT']
expires: ['Thu, 19 Nov 1981 08:52:00 GMT']
pragma: [no-cache]
server: [nginx]
set-cookie: [PHPSESSID=7c93d8fb87ea19f1d7b02cf812849be2; path=/; domain=dev.namesilo.com]
vary: [Accept-Encoding]
x-proxy-cache: [MISS]
status: {code: 200, message: OK}
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
User-Agent: [python-requests/2.9.1]
method: GET
uri: http://sandbox.namesilo.com/api/dnsAddRecord?rrvalue=challengetoken&domain=capsulecdfake.com&rrhost=_acme-challenge.fqdn&rrtype=TXT&version=1&type=xml
response:
body: {string: !!python/unicode '<?xml version="1.0"?>

<namesilo><request><operation>dnsAddRecord</operation><ip>208.72.142.184</ip></request><reply><code>300</code><detail>success</detail><record_id>8bc1c2ab7721caa67c40464bc715dfd9</record_id></reply></namesilo>

'}
headers:
cache-control: ['no-store, no-cache, must-revalidate, post-check=0, pre-check=0']
connection: [keep-alive]
content-length: ['231']
content-type: [text/xml]
date: ['Sun, 03 Apr 2016 02:55:43 GMT']
expires: ['Thu, 19 Nov 1981 08:52:00 GMT']
pragma: [no-cache]
server: [nginx]
set-cookie: [PHPSESSID=a560d05e186348a17321564a7505f2d5; path=/; domain=dev.namesilo.com]
transfer-encoding: [chunked]
vary: [Accept-Encoding]
x-proxy-cache: [MISS]
status: {code: 200, message: OK}
version: 1
Loading

0 comments on commit d836ade

Please sign in to comment.