Skip to content

Commit f33308d

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 6e561ec + bddb912 commit f33308d

8 files changed

+45
-40
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
## [0.0.8] - 2020-06-30
1111

1212
### Changed
13-
- BUGFIX: exception on first run after initialization
13+
- BUGFIX: exception on first run after initialization #30
1414

1515
## [0.0.7] - 2020-06-25
1616

dyndns/command_line.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
def main():
1313
parser = argparse.ArgumentParser(description="Config domain for DynDNS")
1414

15-
parser.add_argument('action', choices=['setup', 'update', 'status', 'remove'], help="action to be performed on domain(s)")
15+
parser.add_argument('action', choices=['setup', 'update', 'status', 'remove'], help="action to be performed on "
16+
"domain(s)")
1617
parser.add_argument('--config', type=str, default='settings.txt', help="config file path")
1718
parser.add_argument('--backup_file', default=None, help="backup file path for remove domain")
1819
parser.add_argument('--ignore-previous-ip', action='store_true', dest='ignore_previous_ip',

dyndns/domain_remove.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,3 @@ def main(domain, settings='settings.txt', backup_file=None):
4343
with open(settings, "w") as settings_file:
4444
json.dump(config, settings_file, sort_keys=True, indent=1)
4545
return "Domain {} successfully removed.".format(domain)
46-

dyndns/domain_setup.py

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import json
22
import os.path
3-
import sys
4-
5-
import requests
6-
from domainconnect import DomainConnect, DomainConnectAsyncCredentials, TemplateNotSupportedException
7-
from builtins import input
83
import webbrowser
4+
from builtins import input
5+
6+
from domainconnect import DomainConnect, DomainConnectAsyncCredentials, TemplateNotSupportedException, \
7+
NoDomainConnectRecordException, NoDomainConnectSettingsException
98

109
dc = DomainConnect()
1110

@@ -66,24 +65,26 @@ def main(domain, protocols, settings='settings.txt'):
6665
mode = 'r+'
6766
if not os.path.exists(settings):
6867
mode = 'w+'
69-
with open(settings, mode) as settings_file:
70-
try:
71-
existing_config = json.load(settings_file)
72-
except ValueError:
73-
existing_config = {}
74-
settings_file.seek(0)
75-
settings_file.truncate()
76-
existing_config.update({
77-
domain: {
78-
'provider_name': config.providerName,
79-
'url_api': config.urlAPI,
80-
'access_token': context.access_token,
81-
'refresh_token': context.refresh_token,
82-
'iat': context.iat,
83-
'access_token_expires_in': context.access_token_expires_in,
84-
'protocols': protocols
85-
}
86-
})
87-
json.dump(existing_config, settings_file, sort_keys=True, indent=1)
88-
return "Domain {} has been successfully configured.".format(domain)
89-
return "Could not store domain config."
68+
try:
69+
with open(settings, mode) as settings_file:
70+
try:
71+
existing_config = json.load(settings_file)
72+
except ValueError:
73+
existing_config = {}
74+
settings_file.seek(0)
75+
settings_file.truncate()
76+
existing_config.update({
77+
domain: {
78+
'provider_name': config.providerName,
79+
'url_api': config.urlAPI,
80+
'access_token': context.access_token,
81+
'refresh_token': context.refresh_token,
82+
'iat': context.iat,
83+
'access_token_expires_in': context.access_token_expires_in,
84+
'protocols': protocols
85+
}
86+
})
87+
json.dump(existing_config, settings_file, sort_keys=True, indent=1)
88+
return "Domain {} has been successfully configured.".format(domain)
89+
except Exception as e:
90+
return "Could not store domain config: {}".format(e)

dyndns/domain_status.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import datetime
22
import json
3-
import time
43

54

65
def main(domain, settings='settings.txt'):

dyndns/domain_update.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def allowed_gai_family_ipv6():
2727
family = socket.AF_INET6
2828
return family
2929

30+
3031
# END Force requests to use IPv4 / IPv6
3132

3233

@@ -63,8 +64,8 @@ def main(domain, settings='settings.txt', ignore_previous_ip=False):
6364
print("Read {} config.".format(domain))
6465

6566
protocols = {
66-
'IP': {'version': 4, 'api': 'https://api.ipify.org', 'record_type': 'A',
67-
'protocol_enforce': allowed_gai_family_ipv4},
67+
'IP': {'version': 4, 'api': 'https://api.ipify.org', 'record_type': 'A',
68+
'protocol_enforce': allowed_gai_family_ipv4},
6869
'IPv4': {'version': 4, 'api': 'https://api.ipify.org', 'record_type': 'A',
6970
'protocol_enforce': allowed_gai_family_ipv4},
7071
'IPv6': {'version': 6, 'api': 'https://api6.ipify.org', 'record_type': 'AAAA',
@@ -123,8 +124,8 @@ def main(domain, settings='settings.txt', ignore_previous_ip=False):
123124

124125
# get public ip
125126
try:
127+
allowed_gai_family_orig = urllib3_cn.allowed_gai_family
126128
try:
127-
allowed_gai_family_orig = urllib3_cn.allowed_gai_family
128129
urllib3_cn.allowed_gai_family = protocols[proto]['protocol_enforce']
129130
response = requests.get(protocols[proto]['api'], params={'format': 'json'})
130131
finally:
@@ -180,7 +181,6 @@ def main(domain, settings='settings.txt', ignore_previous_ip=False):
180181
settings_file.write(new_settings)
181182
return "All records up to date. No update required."
182183

183-
184184
# update DNS records
185185
success = True
186186
try:

dyndns/tests/test_dyndns.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from __future__ import print_function
2+
23
import json
34
import os
5+
import unittest
46
from sys import stdin
57

6-
from domainconnect import DomainConnect
78
from unittest2 import TestCase
8-
import unittest
99

1010
from dyndns import domain_setup, domain_update
1111

@@ -23,8 +23,9 @@ def tearDown(self):
2323
if os.path.exists('settings.txt'):
2424
os.remove('settings.txt')
2525

26-
def _setup_domain(self, domain):
27-
domain_setup.main(domain)
26+
@staticmethod
27+
def _setup_domain(domain):
28+
domain_setup.main(domain, ['ipv4'])
2829

2930
@unittest.skipIf(not stdin.isatty(), "Skipping interactive test.")
3031
def test_setup_one_domain(self):
@@ -62,7 +63,7 @@ def test_setup_two_domains(self):
6263

6364
@unittest.skipIf(not stdin.isatty(), "Skipping interactive test.")
6465
def test_update_domain(self):
65-
domain_setup.main(self.host + self.domain)
66+
domain_setup.main(self.host + self.domain, ['ipv4'])
6667
assert (os.path.exists('settings.txt')), 'Settings file missing'
6768
result = domain_update.main(self.host + self.domain)
6869
assert (result in ['A record up to date.', 'DNS record successfully updated.']), result

requirements.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ coveralls==1.5.0
33
domain-connect==0.0.7
44
pytest==3.7.4
55
unittest2==1.1.0
6-
validators==0.12.6
6+
validators~=0.14.0
77
mock==2.0.0
88
requests==2.21.0
99
ipaddress==1.0.23; python_version < '3.3'
10+
11+
argparse~=1.4.0
12+
dnspython~=1.16.0
13+
setuptools~=40.8.0

0 commit comments

Comments
 (0)