-
Notifications
You must be signed in to change notification settings - Fork 25
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
Zone file import - support missing params. #126
Conversation
Since this will need an update to the changelog before releasing I've added my proposed changelog update below. (It is a bit wordy because of the need to differentiate between behaviour changes when creating a zone and new things when creating a zone with a zonefile.)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a typo (zone
instead of name
in a docstring), but more important is that this changes order of parameters passed to the API.
ns1/__init__.py
Outdated
@@ -371,7 +377,8 @@ def createZone( | |||
If zoneFile is specified, upload the specific zone definition file | |||
to populate the zone with. | |||
|
|||
:param str zone: zone name, like 'example.com' | |||
:param str zone: zone FQDN, like 'example.com' | |||
:param str zone: zone name override, name will be zone FQDN if omitted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:param str zone: zone name override, name will be zone FQDN if omitted | |
:param str name: zone name override, name will be zone FQDN if omitted |
It is possible in Python to declare keyword-only arguments:
https://peps.python.org/pep-3102/
But we don't have that now, so order matters.
If you want to reorder the parameters like this you'll need to make a major release, as it can break the API. Alternately you can put it at the end. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're < 1.0 so we don't have to do a major release for such things (I think). But we will be breaking stuff!
ns1/rest/zones.py
Outdated
def _buildBody(self, zone, **kwargs): | ||
body = {} | ||
body["zone"] = zone | ||
self._buildStdBody(body, kwargs) | ||
return body | ||
|
||
def import_file( | ||
self, zone, zoneFile, callback=None, errback=None, **kwargs | ||
self, zone, zoneFile, name=None, callback=None, errback=None, **kwargs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the change in __init__.py
, this reorders the parameters and is a breaking change.
ns1/rest/zones.py
Outdated
# parameter but the zonefile API expects parameters containing comma | ||
# seperated values. | ||
if fields.get("networks") is not None: | ||
networksStrs = map(str, fields["networks"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is because people may pass networks as numbers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our API takes a list of network numbers.
Unfortunately it takes them in a single query parameter of the form networks=1,2,3
which is not how you should pass an array via parameters, as I've found out while working on the other side of our import API, and not how the request library will pass an array. So we need to convert the array to a string.
If allowed to the libs will pass an array using multiple params of the same name:
networks=1&networks=2&networks=3
but our API won't accept that.
ns1/rest/zones.py
Outdated
params["name"] = name | ||
return params | ||
|
||
def create(self, zone, name=None, callback=None, errback=None, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here also, changing the order of parameters may break things for some users.
ns1/zones.py
Outdated
@@ -90,14 +90,21 @@ def success(result, *args): | |||
self.zone, callback=success, errback=errback, **kwargs | |||
) | |||
|
|||
def create(self, zoneFile=None, callback=None, errback=None, **kwargs): | |||
def create( | |||
self, name=None, zoneFile=None, callback=None, errback=None, **kwargs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may break the API for folks.
ns1/rest/zones.py
Outdated
# parameter but the zonefile API expects parameters containing comma | ||
# seperated values. | ||
if fields.get("networks") is not None: | ||
networksStrs = map(str, fields["networks"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Snake case in Python.
ns1/rest/zones.py
Outdated
return self._make_request( | ||
"PUT", | ||
"%s/%s" % (self.ROOT, zone), | ||
"%s/%s" % (self.ROOT, name), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use f-strings. I know you're just changing a variable name, but might as well update while we're at it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, on this function, create()
, and on import()
. I've left the others in this file as those were the two I altered and (more importantly) wrote tests for. There aren't specific tests for the other functions in this file.
if name is not None: | ||
params["name"] = name | ||
|
||
zoneFilePath = "{}/../../examples/importzone.db".format( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f-string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remaining comment, but also a nitpick. So change it if you'd like, but I won't block on it.
Add support for missing parameters when importing zone files: - networks - views - name Support for the "name" field also added to create without zonefile.
4728a24
to
f9e89a9
Compare
Use f-strings and be more pythonic... Co-authored-by: Shane Kerr <133137948+shane-ns1@users.noreply.github.com>
This PR adds support for missing parameters when importing zone files:
As both zone creation with or without a zone file to prepopulate it use the same call, just with or without the zonefile specificed, the "name" field also added to the api to create a zone and "views" is added to the list of fields passed through on zone creation.