Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: nbuchwitz/nc_dnsapi
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.1.3
Choose a base ref
...
head repository: nbuchwitz/nc_dnsapi
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 18 commits
  • 3 files changed
  • 6 contributors

Commits on Aug 13, 2018

  1. Check if record is not None

    Nicolai Buchwitz committed Aug 13, 2018
    Copy the full SHA
    3bb3aa7 View commit details
  2. Fix error in DNSRecord comparison

    Nicolai Buchwitz committed Aug 13, 2018
    Copy the full SHA
    273b6dc View commit details
  3. Handle empty zones correctly

    Nicolai Buchwitz committed Aug 13, 2018
    Copy the full SHA
    c131a77 View commit details
  4. v0.1.4 release

    Nicolai Buchwitz committed Aug 13, 2018
    Copy the full SHA
    873e98e View commit details

Commits on Aug 17, 2018

  1. Copy the full SHA
    799c952 View commit details
  2. Copy the full SHA
    d6d90ee View commit details
  3. Nicer formatting

    coldfix committed Aug 17, 2018
    Copy the full SHA
    033ab41 View commit details
  4. Merge pull request #1 from coldfix/master

    minor fix in README and nicer formatting
    nbuchwitz authored Aug 17, 2018
    Copy the full SHA
    16c6b6b View commit details
  5. Merge branch 'master' of github.com:nbuchwitz/nc_dnsapi

    Nicolai Buchwitz committed Aug 17, 2018
    Copy the full SHA
    2ff893e View commit details
  6. Raise version

    Nicolai Buchwitz committed Aug 17, 2018
    Copy the full SHA
    f093798 View commit details

Commits on Jan 25, 2019

  1. Copy the full SHA
    58b9e0b View commit details
  2. Merge pull request #3 from tuxmaster5000/master

    Fix sample for dns records
    nbuchwitz authored Jan 25, 2019
    Copy the full SHA
    e3e6a28 View commit details

Commits on Apr 16, 2019

  1. Add DNS record types for OPENPGPKEY and SMIMEA

    Netcup allows to store public keys (OPENPGPKEY) and certificates (SMIMEA) in DNS, cannot be published/ deleted as types are not part of the valid types list and nc_dnsapi will fail if such records exist.
    jp-coding authored Apr 16, 2019
    Copy the full SHA
    b79f0bf View commit details
  2. Merge pull request #4 from jp-coding/patch-1

    Add DNS record types for OPENPGPKEY and SMIMEA to list of valid record types
    nbuchwitz authored Apr 16, 2019
    Copy the full SHA
    3c5238e View commit details

Commits on Mar 12, 2023

  1. fix: Hint for wrong credentials

    The rate limit error from the API does also occur during login if the
    provided credentials are wrong. Help the user by adding a hint if this
    happens during login.
    
    Fixes #5
    nbuchwitz committed Mar 12, 2023
    Copy the full SHA
    49ce284 View commit details
  2. Copy the full SHA
    9a409fe View commit details
  3. Merge pull request #8 from nbuchwitz/devel/add-SSHFP-type

    feat: Add support for SSHFP record type
    nbuchwitz authored Mar 12, 2023
    Copy the full SHA
    0e3cc09 View commit details

Commits on Mar 16, 2023

  1. Merge pull request #7 from nbuchwitz/devel/state-possible-credential-…

    …error
    
    fix: Hint for wrong credentials
    nbuchwitz authored Mar 16, 2023
    Copy the full SHA
    f0f99c9 View commit details
Showing with 32 additions and 10 deletions.
  1. +4 −3 README.md
  2. +27 −6 nc_dnsapi/__init__.py
  3. +1 −1 setup.py
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -2,16 +2,17 @@
A simple API wrapper for the netcup DNS API

```python
import nc_dnsapi
from nc_dnsapi import Client, DNSRecord

customer = 123456
api_key = "your-personal-api-key"
api_password = "your-private-api-password"

with nc_dnsapi.Client(customer, api_key, api_password) as api:
with Client(customer, api_key, api_password) as api:
# fetch records
records = api.dns_records("example.com")
print(records)
for record in records:
print(record)

# fetch zone details
zone = api.dns_zone("example.com")
33 changes: 27 additions & 6 deletions nc_dnsapi/__init__.py
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ def __eq__(self, other):


class DNSRecord(object):
__valid_types = ['A', 'AAAA', 'MX', 'CNAME', 'CAA', 'SRV', 'TXT', 'TLSA', 'NS', 'DS']
__valid_types = ['A', 'AAAA', 'MX', 'CNAME', 'CAA', 'SRV', 'TXT', 'TLSA', 'NS', 'DS', 'OPENPGPKEY', 'SMIMEA', 'SSHFP']

def __init__(self, hostname, type, destination, **kwargs):
self.hostname = hostname
@@ -37,7 +37,13 @@ def __init__(self, hostname, type, destination, **kwargs):
raise TypeError("Invalid record type: {}".format(self.type))

def __str__(self):
return str(self.__dict__)
return '{}({})'.format(self.__class__.__name__, ', '.join(
'{}={!r}'.format(k, v)
for k, v in self.__dict__.items()
if v is not None
))

__repr__ = __str__

def __eq__(self, other):
if not isinstance(other, DNSRecord):
@@ -48,7 +54,7 @@ def __eq__(self, other):
if self.type == 'MX' and other.type == self.type and self.priority:
result = result and int(self.priority) == int(other.priority)

if self.id:
if self.id and other.id:
result = result and self.id == other.id

return result
@@ -85,10 +91,18 @@ def request(self, action, **kwargs):

if data['status'] == 'success':
return data
elif data['statuscode'] == 5029:
# empty dns zone
return []
else:
raise Exception("{} ({})".format(data['longmessage'], data['statuscode']))
exception_message = f"{data['longmessage']} ({data['statuscode']})"
if data['statuscode'] == 4013 and action == "login":
exception_message += ". This error occured during login and is usually caused" \
" by wrong API credentials. Please check the provided values."

raise Exception(exception_message)
else:
raise Exception("{} ({})".format(response.reason, response.status_code))
raise Exception("f{response.reason} ({response.status_code})")

def logout(self):
self.request("logout")
@@ -116,6 +130,9 @@ def update_dns_records(self, domain, records):
"dnsrecordset": {"dnsrecords": [record.__dict__ for record in records]}
})

if 'responsedata' not in data:
return []

return [DNSRecord(**r) for r in data['responsedata']['dnsrecords']]

def dns_record_exists(self, domain, record):
@@ -131,7 +148,7 @@ def dns_record(self, domain, record):
return None

def delete_dns_record(self, domain, record, ignore_unknown=True):
if not record.id:
if not record or not record.id:
raise ValueError("Missing id of record to update")

record.deleterecord = True
@@ -152,6 +169,10 @@ def delete_dns_records(self, domain, records):

def dns_records(self, domain):
data = self.request("infoDnsRecords", params={"domainname": domain})

if 'responsedata' not in data:
return []

return [DNSRecord(**r) for r in data['responsedata']['dnsrecords']]

def update_dns_zone(self, domain, zone):
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@

setuptools.setup(
name='nc_dnsapi',
version='0.1.3',
version='0.1.5',
description='API wrapper for the netcup DNS api',
long_description=long_description,
long_description_content_type="text/markdown",