Skip to content
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

Dash-separated Plugins Endpoint name support #332

Closed
iDebugAll opened this issue Feb 19, 2021 · 2 comments · Fixed by #397
Closed

Dash-separated Plugins Endpoint name support #332

iDebugAll opened this issue Feb 19, 2021 · 2 comments · Fixed by #397

Comments

@iDebugAll
Copy link

Hello. First of all, thank you for a useful tool.

I faced with a limitation in current plugin endpoint name resolution approach for dash-separated plugin names.
Plugin namespaces under /api/plugins/ do technically allow dash-separated base urls.
For example, /api/plugins/some-dash-separated/endpoints/ is valid and working option in NetBox.
However, Python does not support dash-separated method names by design.

Current workaround is to pass such plugin name to __getattr__:

nb.plugins.__getattr__('some-dash-separated').endpoints.all()

Calling dunder methods directly might be not that pythonic though.
Would adding some optional name getter function in PluginsApp (and probably to App) be a better solution? Something like:

class PluginsApp(object):
    def get_endpoint_name(name):
        return App(self.api, "plugins/{}".format(name))

So that is could be used as:

nb.plugins.get_endpoint_name('some-dash-separated').endpoints.all()
@markkuleinio
Copy link
Contributor

Would replacing this:

https://github.com/digitalocean/pynetbox/blob/d2c6b165c2277ff3b9cbccf4ca134f8c9dd27eb2/pynetbox/core/app.py#L152

with

return App(self.api, "plugins/{}".format(name.replace("_", "-")))

be enough? Then you would call it like nb.plugins.some_dash_separated.endpoints.all().

This is the technique that is used in Endpoint.__init__() as well (https://github.com/digitalocean/pynetbox/blob/master/pynetbox/core/endpoint.py#L45), to support API endpoints like /ipam/ip-addresses.

(Sorry, I haven't worked with plugins myself so I don't maybe get all the details that need to be considered.)

@artscout
Copy link

artscout commented Apr 5, 2022

But what about plugins with underscores in name/url? netbox_secretstore for example - it doesn't work with this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants