From 1f7301c89f46ec1c3f00aed3fada3ba21f461f08 Mon Sep 17 00:00:00 2001 From: Milos Mikalacki Date: Wed, 31 Oct 2018 22:09:26 +0100 Subject: [PATCH 01/12] added list dns records --- namesilo/core.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/namesilo/core.py b/namesilo/core.py index 465ce02..83d7a05 100644 --- a/namesilo/core.py +++ b/namesilo/core.py @@ -380,3 +380,17 @@ def remove_domain_privacy(self, domain_name): f"domain={domain_name}" self._process_data(url_extend) return True + + def dns_list_records(self, domain_name): + """ + List all DNS records for specified domain name + + :param str domain_name: Domain name for listing DNS records + :return: list + """ + + url_extend = f"dnsListRecords?version=1&type=xml&key={self._token}" \ + f"&domain={domain_name}" + parsed_context = self._process_data(url_extend) + records = parsed_context['namesilo']['reply']['resource_record'] + return records From 3193097ef9952dd70f00ee1848bfc674e5109210 Mon Sep 17 00:00:00 2001 From: Milos Mikalacki Date: Wed, 31 Oct 2018 23:37:46 +0100 Subject: [PATCH 02/12] added add dns records and update dns records --- namesilo/core.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/namesilo/core.py b/namesilo/core.py index 83d7a05..e9bf375 100644 --- a/namesilo/core.py +++ b/namesilo/core.py @@ -381,12 +381,13 @@ def remove_domain_privacy(self, domain_name): self._process_data(url_extend) return True - def dns_list_records(self, domain_name): + def list_dns_records(self, domain_name): """ List all DNS records for specified domain name :param str domain_name: Domain name for listing DNS records - :return: list + :return: Returns a list of DNS records for specified domain name + :rtype: list """ url_extend = f"dnsListRecords?version=1&type=xml&key={self._token}" \ @@ -394,3 +395,48 @@ def dns_list_records(self, domain_name): parsed_context = self._process_data(url_extend) records = parsed_context['namesilo']['reply']['resource_record'] return records + + def add_dns_records( + self, domain_name, record_type, record_host, record_value, + ttl=7207): + """ + Add DNS record to specified domain name + + :param str domain_name: Domain name for adding DNS record + :param str record_type: The type of resources record to add + :param str record_host: The hostname for the new record + :param str record_value: The value for the resource record + :param int ttl: The TTL for the new record + :return: Returns record id for specified domain record + :rtype: int + """ + + url_extend = f"dnsAddRecord?version=1&type=xml&key={self._token}" \ + f"&domain={domain_name}&rrtype={record_type}" \ + f"&rrhost={record_host}&rrvalue={record_value}&rrttl={ttl}" + parsed_context = self._process_data(url_extend) + record_id = parsed_context['namesilo']['reply']['record_id'] + return record_id + + def update_dns_records( + self, domain_name, record_id, record_host, record_value, + ttl=7207): + """ + Update an existing DNS resource record + + :param str domain_name: Domain name for updating DNS record + :param int record_id: The unique ID of the resource record + :param str record_host: The hostname to use + :param str record_value: The value for the resource record + :param int ttl: The TTL for this record + :return: Returns record id for updated domain record + :rtype: int + """ + + url_extend = f"dnsUpdateRecord?version=1&type=xml" \ + f"&key={self._token}&domain={domain_name}&" \ + f"rrid={record_id}&rrhost={record_host}" \ + f"&rrvalue={record_value}&rrttl={ttl}" + parsed_context = self._process_data(url_extend) + new_record_id = parsed_context['namesilo']['reply']['record_id'] + return new_record_id From 29cc97cd4cbe86c585b5f8190a9ce410ab1fd868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Goran=20Vrba=C5=A1ki?= Date: Mon, 27 May 2019 14:49:17 +0200 Subject: [PATCH 03/12] added tests for dns operation --- goran.py | 0 namesilo/core.py | 2 +- tests/mocked_data.py | 11 ++++++++++- tests/test_namesilo.py | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 goran.py diff --git a/goran.py b/goran.py new file mode 100644 index 0000000..e69de29 diff --git a/namesilo/core.py b/namesilo/core.py index e9bf375..625f0d5 100644 --- a/namesilo/core.py +++ b/namesilo/core.py @@ -425,7 +425,7 @@ def update_dns_records( Update an existing DNS resource record :param str domain_name: Domain name for updating DNS record - :param int record_id: The unique ID of the resource record + :param str record_id: The unique ID of the resource record :param str record_host: The hostname to use :param str record_value: The value for the resource record :param int ttl: The TTL for this record diff --git a/tests/mocked_data.py b/tests/mocked_data.py index 1840dc4..9342dac 100644 --- a/tests/mocked_data.py +++ b/tests/mocked_data.py @@ -69,7 +69,16 @@ }, 'domains': { 'domain': ['some-example-domain.com', 'example.com'] - } + }, + 'resource_record': [ + { + 'record_id': 'e3f383786a647e83c49c6082c7ce8015', + 'type': 'A', + 'host': 'some-domain.com', + 'value': '107.161.23.204' + } + ], + 'record_id': 'e3f383786a647e83c49c6082c7ce8014' } } } diff --git a/tests/test_namesilo.py b/tests/test_namesilo.py index 831a726..473b404 100644 --- a/tests/test_namesilo.py +++ b/tests/test_namesilo.py @@ -299,6 +299,39 @@ def test_remove_auto_renew_domain(self, mock_content_xml): "domain=some-domain.com" ) + @mock.patch('namesilo.core.NameSilo._process_data') + def test_list_dns_records(self, mock_content_xml): + domain_name = "some-domain.com" + mock_content_xml.return_value = mocked_data + result = self.ns.list_dns_records(domain_name) + self.assertIsInstance(result, list) + self.assertListEqual(mocked_data['namesilo']['reply']['resource_record'], result) + + @mock.patch('namesilo.core.NameSilo._process_data') + def test_add_dns_record(self, mock_content_xml): + mock_content_xml.return_value = mocked_data + record_id = self.ns.add_dns_records( + "some-domain.com", "A", "test.some-domain.com", "192.168.71.50", 86400 + ) + mock_content_xml.assert_called_once_with( + "dnsAddRecord?version=1&type=xml&key=name-silo-token&domain=some-domain.com&" + "rrtype=A&rrhost=test.some-domain.com&rrvalue=192.168.71.50&rrttl=86400" + ) + self.assertEqual(record_id, 'e3f383786a647e83c49c6082c7ce8014') + + @mock.patch('namesilo.core.NameSilo._process_data') + def test_update_dns_record(self, mock_content_xml): + mock_content_xml.return_value = mocked_data + record_id = self.ns.update_dns_records( + "some-domain.com", "e3f383786a647e83c49c6082c7ce8014", "test.some-domain.com", "192.168.71.55" + ) + mock_content_xml.assert_called_once_with( + "dnsUpdateRecord?version=1&type=xml&key=name-silo-token&domain=some-domain.com&" + "rrid=e3f383786a647e83c49c6082c7ce8014&rrhost=test.some-domain.com&" + "rrvalue=192.168.71.55&rrttl=7207" + ) + self.assertEqual(record_id, 'e3f383786a647e83c49c6082c7ce8014') + if __name__ == '__main__': unittest.main() From 104633b6ab5e02145d36733440035d043896f94b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Goran=20Vrba=C5=A1ki?= Date: Fri, 26 Jun 2020 11:17:05 +0200 Subject: [PATCH 04/12] Create python-package.yml --- .github/workflows/python-package.yml | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/python-package.yml diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml new file mode 100644 index 0000000..584620f --- /dev/null +++ b/.github/workflows/python-package.yml @@ -0,0 +1,30 @@ +name: Python package + +on: + push: + branches: [ master, develop, 'release/*', 'feature/*', 'bugfix/*' ] + pull_request: + branches: [ master, develop ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.6, 3.7, 3.8] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install codecov coverage + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Run tests with coverage + run: | + coverage run tests/test_namesilo.py From d0ede368353cca8c14c6e9b0194618aea5f82ecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Goran=20Vrba=C5=A1ki?= Date: Fri, 26 Jun 2020 11:18:50 +0200 Subject: [PATCH 05/12] Update python-package.yml --- .github/workflows/python-package.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 584620f..8c67185 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -27,4 +27,5 @@ jobs: if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Run tests with coverage run: | + export PYTHONPATH=$HOME/build/goranvrbaski/python-namesilo coverage run tests/test_namesilo.py From afa34414077d5a93281f8baf25e2d3bcf46af1d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Goran=20Vrba=C5=A1ki?= Date: Mon, 10 Oct 2022 15:41:48 +0200 Subject: [PATCH 06/12] add new python version --- .github/workflows/python-package.yml | 35 ++++++++++++++-------------- goran.py | 0 2 files changed, 17 insertions(+), 18 deletions(-) delete mode 100644 goran.py diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 8c67185..3214be5 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -2,30 +2,29 @@ name: Python package on: push: - branches: [ master, develop, 'release/*', 'feature/*', 'bugfix/*' ] + branches: [master, develop, "release/*", "feature/*", "bugfix/*"] pull_request: - branches: [ master, develop ] + branches: [master, develop] jobs: build: - runs-on: ubuntu-latest strategy: matrix: - python-version: [3.6, 3.7, 3.8] + python-version: [3.6, 3.7, 3.8, 3.9, 3.10] steps: - - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install codecov coverage - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - name: Run tests with coverage - run: | - export PYTHONPATH=$HOME/build/goranvrbaski/python-namesilo - coverage run tests/test_namesilo.py + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install codecov coverage + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Run tests with coverage + run: | + export PYTHONPATH=$HOME/build/goranvrbaski/python-namesilo + coverage run tests/test_namesilo.py diff --git a/goran.py b/goran.py deleted file mode 100644 index e69de29..0000000 From d96eb3fff96d278bffb30a9a0ba3572da24466d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Goran=20Vrba=C5=A1ki?= Date: Mon, 10 Oct 2022 15:43:28 +0200 Subject: [PATCH 07/12] update python package --- .github/workflows/python-package.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 3214be5..bf0d732 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.6, 3.7, 3.8, 3.9, 3.10] + python-version: [3.6, 3.7, 3.8, 3.9, "3.10"] steps: - uses: actions/checkout@v2 From 2cf761ef7b3c4136a49c053c733d64a728808ed3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Goran=20Vrba=C5=A1ki?= Date: Mon, 10 Oct 2022 15:46:45 +0200 Subject: [PATCH 08/12] remove export of path --- .github/workflows/python-package.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index bf0d732..9b85062 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -26,5 +26,4 @@ jobs: if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Run tests with coverage run: | - export PYTHONPATH=$HOME/build/goranvrbaski/python-namesilo coverage run tests/test_namesilo.py From 9b7836aadb2150ccf22efe609401b94fa264c7e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Goran=20Vrba=C5=A1ki?= Date: Mon, 10 Oct 2022 15:51:27 +0200 Subject: [PATCH 09/12] add workdir to pythonpath --- .github/workflows/python-package.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 9b85062..4b08f65 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -26,4 +26,5 @@ jobs: if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Run tests with coverage run: | + export PYTHONPATH=/home/runner/work/python-namesilo/python-namesilo coverage run tests/test_namesilo.py From 3d3e87777206eb2e6898335efec26ef3ef729d1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Goran=20Vrba=C5=A1ki?= Date: Mon, 10 Oct 2022 16:28:37 +0200 Subject: [PATCH 10/12] update version, python versions, readme and setup.py --- .codecov.yml | 11 ---------- .github/workflows/python-package.yml | 31 +++++++++++++++++----------- .github/workflows/python-test.yml | 29 ++++++++++++++++++++++++++ README.md | 7 +++---- setup.py | 9 ++++++-- 5 files changed, 58 insertions(+), 29 deletions(-) delete mode 100644 .codecov.yml create mode 100644 .github/workflows/python-test.yml diff --git a/.codecov.yml b/.codecov.yml deleted file mode 100644 index c1a29f5..0000000 --- a/.codecov.yml +++ /dev/null @@ -1,11 +0,0 @@ -codecov: - branch: master - strict_yaml_branch: master - -coverage: - range: 80..100 - round: down - precision: 2 - -ignore: - - tests \ No newline at end of file diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 4b08f65..f72af89 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -2,29 +2,36 @@ name: Python package on: push: - branches: [master, develop, "release/*", "feature/*", "bugfix/*"] - pull_request: - branches: [master, develop] + branches: + - master + - "feature/**" jobs: - build: + publish: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.6, 3.7, 3.8, 3.9, "3.10"] + python-version: ["3.10"] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | python -m pip install --upgrade pip - pip install codecov coverage + python -m pip install build if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - name: Run tests with coverage - run: | - export PYTHONPATH=/home/runner/work/python-namesilo/python-namesilo - coverage run tests/test_namesilo.py + - name: Build a binary wheel and a source tarball + run: >- + python -m + build + --sdist + --wheel + --outdir dist/ + - name: Publish a Python distribution to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml new file mode 100644 index 0000000..c3cb083 --- /dev/null +++ b/.github/workflows/python-test.yml @@ -0,0 +1,29 @@ +name: Python Test + +on: + push: + branches: [master, develop, "release/*", "feature/*", "bugfix/*"] + pull_request: + branches: [master, develop] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.6, 3.7, 3.8, 3.9, "3.10"] + + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Run tests with coverage + run: | + export PYTHONPATH=/home/runner/work/python-namesilo/python-namesilo + python -m unittest --verbose tests/test_namesilo.py diff --git a/README.md b/README.md index a92d1e8..d372e94 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,11 @@ # Python Namesilo Module - -[![Build Status Badge][BuildStatus]](https://travis-ci.org/goranvrbaski/python-namesilo.svg?branch=master) -[![Code Coverage Badge][CodeCov]](https://codecov.io/gh/goranvrbaski/python-namesilo) [![PyPiVersion Badge][PyPiVersion]](https://pypi.org/project/python-namesilo) [![Read The Docs][ReadtheDocs]](https://python-namesilo.readthedocs.io) [![DonateMe][PaypalBadge]](https://paypal.me/goranvrbaski) -This code is written in Python 3.6 If you want to contribute to this +This code is written in Python, and the following versions are supported: `3.6`, `3.7`, `3.8`, `3.9`, `3.10`. + + If you want to contribute to this project feel free to contact me at any time. If you're using this module and you like it, consider [buying me a beer.](https://paypal.me/goranvrbaski) :beer: diff --git a/setup.py b/setup.py index 925f02d..bba9bbf 100644 --- a/setup.py +++ b/setup.py @@ -9,16 +9,21 @@ setup( name='python-namesilo', - version='1.1.3', + version='1.4.0', packages=find_packages(exclude=['docs', 'tests']), install_requires=['requests', 'xmltodict'], - python_requires='>=3.6', + python_requires='>=3.6,<=3.10', py_modules=['namesilo'], classifiers=[ 'Development Status :: 5 - Production/Stable', 'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)', 'Operating System :: OS Independent', + 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', 'Topic :: Internet :: WWW/HTTP', 'Topic :: Software Development :: Libraries :: Python Modules' ], From 4424aa4ba0a76436ac64749974045125c9ce9c35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Goran=20Vrba=C5=A1ki?= Date: Mon, 10 Oct 2022 16:37:57 +0200 Subject: [PATCH 11/12] trigger publish on pypi only on master branch --- .github/workflows/python-package.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index f72af89..4277b7a 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -1,10 +1,10 @@ name: Python package on: - push: - branches: - - master - - "feature/**" + workflow_run: + workflows: ["Python Test"] + types: [completed] + branches: [master] jobs: publish: From 44fe807314cfb2ac69dc558f4337b98e44bcb490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Goran=20Vrba=C5=A1ki?= Date: Mon, 10 Oct 2022 16:53:18 +0200 Subject: [PATCH 12/12] bump version to 1.4.1 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index bba9bbf..3bd0e64 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ setup( name='python-namesilo', - version='1.4.0', + version='1.4.1', packages=find_packages(exclude=['docs', 'tests']), install_requires=['requests', 'xmltodict'], python_requires='>=3.6,<=3.10',