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

Add Api.create_token() (for NetBox 3.0+) #415

Merged
merged 2 commits into from Dec 4, 2021

Conversation

markkuleinio
Copy link
Contributor

@markkuleinio markkuleinio commented Nov 27, 2021

NetBox 3.0.0 release notes: https://netbox.readthedocs.io/en/stable/release-notes/version-3.0/#rest-api-token-provisioning-5264

Example with this PR:

>>> import pynetbox
>>> netbox = pynetbox.api("https://netbox-server")
>>> token = netbox.create_token("admin", "netboxpassword")
>>> netbox.token
'96d02e13e3f1fdcd8b4c089094c0191dcb045bef'
>>> from pprint import pprint
>>> pprint(dict(token))
{'created': '2021-11-27T11:26:49.360185+02:00',
 'description': '',
 'display': '045bef (admin)',
 'expires': None,
 'id': 2,
 'key': '96d02e13e3f1fdcd8b4c089094c0191dcb045bef',
 'url': 'https://netbox-server/api/users/tokens/2/',
 'user': {'display': 'admin',
          'id': 1,
          'url': 'https://netbox-server/api/users/users/1/',
          'username': 'admin'},
 'write_enabled': True}
>>>

I also tested implementing this as Endpoint.provision() (just like it is in NetBox API: /api/users/token/provision/), but then an extra if self.name == "token": self.api.token = resp["key"] would be needed to set the token, and I just think this is a clear way to create the token when needed.

@zachmoody zachmoody merged commit 01a390f into netbox-community:master Dec 4, 2021
@markkuleinio markkuleinio deleted the token-provision branch December 5, 2021 12:33
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 this pull request may close these issues.

None yet

2 participants