Skip to content

Commit

Permalink
Merge pull request #323 from markkuleinio/change-path-parsing
Browse files Browse the repository at this point in the history
Change Record._endpoint_from_url() path parsing to ignore host:port
  • Loading branch information
Zach Moody authored Jan 4, 2021
2 parents 243208b + a3b5d22 commit e91d12f
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pynetbox/core/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,13 @@ def list_parser(list_item):
setattr(self, k, v)

def _endpoint_from_url(self, url):
# Remove the base URL from the beginning
url = url[len(self.api.base_url) :]
if url.startswith("/"):
url = url[1:]
app, name = urlsplit(url).path.split("/")[:2]
url_path = urlsplit(url).path
base_url_path_parts = urlsplit(self.api.base_url).path.split("/")
if len(base_url_path_parts) > 2:
# There are some extra directories in the path, remove them from url
extra_path = "/".join(base_url_path_parts[:-1])
url_path = url_path[len(extra_path) :]
app, name = url_path.split("/")[2:4]
return getattr(pynetbox.core.app.App(self.api, app), name)

def full_details(self):
Expand Down

0 comments on commit e91d12f

Please sign in to comment.