dropbox / nsot

Network Source of Truth is an open source IPAM and network inventory database
https://nsot.readthedocs.io
Other
399 stars 66 forks source link

Allow for slashes in Circuit API URLs #258

Closed nickpegg closed 7 years ago

nickpegg commented 7 years ago

This adds a lookup_value_regex to CircuitViewSet to allow for slashes in the URLs, since lookups by natural key could contain these characters as part of the Interface natural keys that make up the default name for Circuits.

The approach I took to this is similar to how @dmar42 did Interfaces: If a slash exists in the Circuit lookup key, ensure that the key does not end in a letter or otherwise it's likely a detail route.

To avoid issues with user-supplied names, I also added logic to raise a validation error if the name contains a period or slash.

This is all to fix a bug I found while implementing the CLI stuff for Circuits (PR on pynsot coming for that very soon!)

nickpegg commented 7 years ago

This regex nonsense is getting worse and worse. After talking to @jathanism I'm going to close this in favor of instead making a slug field based on the name field in Circuit, and have that be the natural key.

The CLI will have to be updated to convert from a name to a slugified name every time the user gives the name as the natural key, but I think that'll be the best for their experience.

jathanism commented 7 years ago

@nickpegg No need to close the PR. Just revise it! :)

nickpegg commented 7 years ago

The changes with the slug are going to be pretty orthogonal to this PR in implementation, so it's better to just open a new one.