46 lines
1.6 KiB
Python
46 lines
1.6 KiB
Python
class Backend(object):
|
|
def __init__(self, config):
|
|
self.config = config
|
|
|
|
def add(self, name, value):
|
|
raise NotImplemented
|
|
|
|
def remove(self, name):
|
|
raise NotImplemented
|
|
|
|
|
|
class OVHBackend(Backend):
|
|
def __init__(self, config):
|
|
import ovh
|
|
import ovh.exceptions
|
|
|
|
self.config = config
|
|
self.client = ovh.Client()
|
|
try:
|
|
self.client.get('/auth/currentCredential')
|
|
except (ovh.exceptions.InvalidKey, ovh.exceptions.InvalidCredential):
|
|
req = ovh.Client().request_consumerkey([
|
|
{'method': 'GET', 'path': '/domain/zone/*/record'},
|
|
{'method': 'POST', 'path': '/domain/zone/*/record'},
|
|
{'method': 'POST', 'path': '/domain/zone/*/refresh'},
|
|
{'method': 'DELETE', 'path': '/domain/zone/*/record/*'},
|
|
])
|
|
print(req)
|
|
|
|
def add(self, name, value):
|
|
if not name.endswith(self.config['OVH_ZONE']):
|
|
raise Exception()
|
|
|
|
v = self.client.post('/domain/zone/%s/record' % (self.config['OVH_ZONE'],),
|
|
fieldType='TXT', subDomain=name+'.', target=value)
|
|
print(v)
|
|
self.client.post('/domain/zone/%s/refresh' % (self.config['OVH_ZONE'],))
|
|
|
|
def remove(self, name):
|
|
ids = self.client.get(
|
|
'/domain/zone/%s/record' % (self.config['OVH_ZONE'],), fieldType='TXT', subDomain=name+'.')
|
|
for i in ids:
|
|
print('Removing', i)
|
|
self.client.delete('/domain/zone/%s/record/%d' % (self.config['OVH_ZONE'], i))
|
|
self.client.post('/domain/zone/%s/refresh' % (self.config['OVH_ZONE'],))
|