mirror of
https://github.com/bb-Ricardo/netbox-sync.git
synced 2026-05-08 11:00:12 -05:00
Merge pull request #500 from dsvetlov/feature/netbox-4.5-v2-token-support
feat: add support for NetBox 4.5+ v2 API tokens (Bearer auth)
This commit is contained in:
@@ -79,6 +79,8 @@ In order to updated data in NetBox you need a NetBox API token.
|
||||
* auth
|
||||
* secrets
|
||||
* users
|
||||
* Both v1 (legacy) and v2 tokens (NetBox 4.5+, `nbt_` prefix) are supported.
|
||||
The correct authorization header (`Token` or `Bearer`) is detected automatically.
|
||||
|
||||
A short description can be found [here](https://docs.netbox.dev/en/stable/integrations/rest-api/#authentication)
|
||||
|
||||
|
||||
@@ -26,7 +26,8 @@ class NetBoxConfig(ConfigBase):
|
||||
ConfigOption("api_token",
|
||||
str,
|
||||
description="""Requires an NetBox API token with full permissions on all objects except
|
||||
'auth', 'secrets' and 'users'
|
||||
'auth', 'secrets' and 'users'.
|
||||
Both v1 (legacy) and v2 (NetBox 4.5+, nbt_ prefix) tokens are supported.
|
||||
""",
|
||||
config_example="XYZ",
|
||||
mandatory=True,
|
||||
|
||||
@@ -152,8 +152,10 @@ class NetBoxHandler:
|
||||
requests.Session: session handler of new NetBox session
|
||||
"""
|
||||
|
||||
token = self.settings.api_token
|
||||
keyword = "Bearer" if token.startswith("nbt_") else "Token"
|
||||
header = {
|
||||
"Authorization": f"Token {self.settings.api_token}",
|
||||
"Authorization": f"{keyword} {token}",
|
||||
"User-Agent": f"netbox-sync/{__version__}",
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
|
||||
@@ -44,7 +44,8 @@
|
||||
[netbox]
|
||||
|
||||
; Requires an NetBox API token with full permissions on all objects except 'auth',
|
||||
; 'secrets' and 'users'
|
||||
; 'secrets' and 'users'. Both v1 (legacy) and v2 (NetBox 4.5+, nbt_ prefix) tokens are
|
||||
; supported.
|
||||
api_token = XYZ
|
||||
|
||||
; Requires a hostname or IP which points to your NetBox instance
|
||||
|
||||
Reference in New Issue
Block a user