Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ALIDNS_LINE_MAP #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 4 additions & 26 deletions black_dnsync/dns_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ def __str__(self):
return repr(self.msg)


class UnsupportedLineError(Exception):
def __init__(self, msg):
self.msg = msg
def __str__(self):
return repr(self.msg)


class BaseClient(object):

def __init__(self, api_key, api_secret):
Expand Down Expand Up @@ -272,19 +265,6 @@ def update_record(self, domain, record_id, record):
data['mx'] = record.priority
return self.__request('PUT', uri, data)


ALIDNS_LINE_MAP = {
'default': 'default',
'ct': 'telecom',
'cu': 'unicom',
'cm': 'mobile',
'edu': 'edu',
'oversea': 'oversea',
}

ALIDNS_LINE_MAP_REV = {v: k for k, v in ALIDNS_LINE_MAP.items()}


class AliyunClient(BaseClient):
def __init__(self, api_key, api_secret):
super(AliyunClient, self).__init__(api_key, api_secret)
Expand Down Expand Up @@ -341,10 +321,8 @@ def __to_record(self, record):
if record['Status'] == 'Disable':
raise ValueError('Do not support Aliyun DNS record disabled status!')

try:
line = ALIDNS_LINE_MAP_REV[record['Line']]
except KeyError:
raise UnsupportedLineError(record)

line = record['Line']

priority = None
if record['Type'] == 'MX':
Expand Down Expand Up @@ -381,7 +359,7 @@ def add_record(self, domain, record):
'Value': record.value,
'TTL': record.ttl,
}
data['Line'] = ALIDNS_LINE_MAP[record.line]
data['Line'] = record.line
if record.type == 'MX':
data['Priority'] = record.priority
return self.__request(data)
Expand All @@ -402,7 +380,7 @@ def update_record(self, domain, record_id, record):
'Value': record.value,
'TTL': record.ttl,
}
data['Line'] = ALIDNS_LINE_MAP[record.line]
data['Line'] = record.line
if record.type == 'MX':
data['Priority'] = record.priority
return self.__request(data)
Expand Down