enhance rest-api/work-with-secrets.md #4840

Closed
opened 2025-12-29 19:21:09 +01:00 by adam · 6 comments
Owner

Originally created by @muellerbe on GitHub (Apr 28, 2021).

Change Type

Correction

Area

REST API

Proposed Changes

I use netbox in version v2.10.8

I create a secret with the following curl call

$ curl -s -XPOST 
       -H "Authorization: Token lesssecure"
       -H "Accept: application/json"
       -H "Content-Type: application/json"
       -H "X-Session-Key: lesssecure"
       http://<IP>/api/secrets/secrets/
       -d '{"assigned_object_type": "dcim.device",
            "assigned_object_id": "4",
            "role": { "name": "ipmi-secrets" },
            "name": "<hostname>-ipmi",
            "plaintext": "lesssecure",
            "tags": [ { "name": "<tag>" } ] }'

return
{                                              
  "id": 2,                                                                                                                                                                                                        
  "url": "http://<IP>/api/secrets/secrets/2/",                                                                                                                                                                    "assigned_object_type": "dcim.device",                                                                                                                                                                            "assigned_object_id": 5,                                                                                                                                                                                        
  "assigned_object": {                                                                                                                                                                                            
    "id": 5,                                                                                             
    "url": "http://<IP>/api/dcim/devices/5/",                                              
    "name": "<hostname>",                                                                                                                                                                          
    "display_name": "<hostname>"                                                                                                                                                                   
  },                                                                                                                                                                                                              
  "role": {                                                                                                                                                                                                       
    "id": 3,                  
    "url": "http://<IP>/api/secrets/secret-roles/3/",                                                                                                                                                   "name": "ipmi-secrets",                                                                                                                                                                                           "slug": "ipmi-secrets"                                                                                                                                                                                        
  },                                                                                                     
  "name": "<hostname>-ipmi",                                                              
  "plaintext": "lesssecure",                                                                             
  "hash": "lesssecure",                
  "tags": [                                                                                              
    {                                                                                                    
      "id": 3,              
      "url": "http://<IP>/api/extras/tags/3/",                                             
      "name": "<tag>",                                                                                                                                                                                                "slug": "slug",                                                                                                                                                                                                "color": "2196f3"                                                                                                                                                                                           
    }                                       
  ],                                               
  "custom_fields": {},                                                                                   
  "created": "2021-04-28",
  "last_updated": "2021-04-28T13:02:12.905247Z"                                                          
}

documentation for this says something like device. Where is this device above? There is a assigned_object* no device.

the following call works

$ curl -s -XPATCH
       -H "Authorization: Token lesssecure"
       -H "Accept: application/json"
       -H "Content-Type: application/json"
       -H "X-Session-Key: lesssecure"
       http://<IP>/api/secrets/secrets/1/
       -d '{ "assigned_object_type": "dcim.device", (optional)
             "device": 4, (also "assigned_object_id": 4 works)
             "name": "<hostname>-ipmi", (optional)
             "role": 3, (optional)
             "plaintext": "newlesssecret" }'

please change the creating command and maybe a hint for also using assigned_object_id or device, in my point of view, assigned_object_id is better to use. thanks

Originally created by @muellerbe on GitHub (Apr 28, 2021). ### Change Type Correction ### Area REST API ### Proposed Changes I use netbox in version v2.10.8 I create a secret with the following curl call ```bash $ curl -s -XPOST -H "Authorization: Token lesssecure" -H "Accept: application/json" -H "Content-Type: application/json" -H "X-Session-Key: lesssecure" http://<IP>/api/secrets/secrets/ -d '{"assigned_object_type": "dcim.device", "assigned_object_id": "4", "role": { "name": "ipmi-secrets" }, "name": "<hostname>-ipmi", "plaintext": "lesssecure", "tags": [ { "name": "<tag>" } ] }' return { "id": 2, "url": "http://<IP>/api/secrets/secrets/2/", "assigned_object_type": "dcim.device", "assigned_object_id": 5, "assigned_object": { "id": 5, "url": "http://<IP>/api/dcim/devices/5/", "name": "<hostname>", "display_name": "<hostname>" }, "role": { "id": 3, "url": "http://<IP>/api/secrets/secret-roles/3/", "name": "ipmi-secrets", "slug": "ipmi-secrets" }, "name": "<hostname>-ipmi", "plaintext": "lesssecure", "hash": "lesssecure", "tags": [ { "id": 3, "url": "http://<IP>/api/extras/tags/3/", "name": "<tag>", "slug": "slug", "color": "2196f3" } ], "custom_fields": {}, "created": "2021-04-28", "last_updated": "2021-04-28T13:02:12.905247Z" } ``` documentation for this says something like device. Where is this device above? There is a assigned_object* no device. the following call works ```bash $ curl -s -XPATCH -H "Authorization: Token lesssecure" -H "Accept: application/json" -H "Content-Type: application/json" -H "X-Session-Key: lesssecure" http://<IP>/api/secrets/secrets/1/ -d '{ "assigned_object_type": "dcim.device", (optional) "device": 4, (also "assigned_object_id": 4 works) "name": "<hostname>-ipmi", (optional) "role": 3, (optional) "plaintext": "newlesssecret" }' ``` please change the creating command and maybe a hint for also using assigned_object_id or device, in my point of view, assigned_object_id is better to use. thanks
adam added the type: documentation label 2025-12-29 19:21:09 +01:00
adam closed this issue 2025-12-29 19:21:09 +01:00
Author
Owner

@muellerbe commented on GitHub (Apr 29, 2021):

enhance get-session-key with option preserve_key, e.g. /api/secrets/get-session-key/?preserve_key=True
found here
https://github.com/netbox-community/pynetbox/blob/master/pynetbox/core/query.py#L206

@muellerbe commented on GitHub (Apr 29, 2021): enhance get-session-key with option preserve_key, e.g. /api/secrets/get-session-key/?preserve_key=True found here https://github.com/netbox-community/pynetbox/blob/master/pynetbox/core/query.py#L206
Author
Owner

@jeremystretch commented on GitHub (Apr 29, 2021):

Could you please clean up your original post so that it is legible? It is not clear what you're proposing. Please see GitHub's Markdown documentation here for formatting help.

@jeremystretch commented on GitHub (Apr 29, 2021): Could you please clean up your original post so that it is legible? It is not clear what you're proposing. Please see GitHub's Markdown documentation [here](https://guides.github.com/features/mastering-markdown/) for formatting help.
Author
Owner

@muellerbe commented on GitHub (Apr 29, 2021):

@jeremystretch thanks for this hint

@muellerbe commented on GitHub (Apr 29, 2021): @jeremystretch thanks for this hint
Author
Owner

@jeremystretch commented on GitHub (May 4, 2021):

Tagging this as needs owner in case someone would like to tackle it, however do note that the secrets functionality is being removed in v2.12 (see #5278).

@jeremystretch commented on GitHub (May 4, 2021): Tagging this as `needs owner` in case someone would like to tackle it, however do note that the secrets functionality is being removed in v2.12 (see #5278).
Author
Owner

@muellerbe commented on GitHub (May 5, 2021):

I can create a PR for this, so someone could check and merge it. OK?
OK, sorry, I do not found this issue. Would the documentation part also be migrated to plugin? So the work will not be obsolete and can modified as needed.

@muellerbe commented on GitHub (May 5, 2021): I can create a PR for this, so someone could check and merge it. OK? OK, sorry, I do not found this issue. Would the documentation part also be migrated to plugin? So the work will not be obsolete and can modified as needed.
Author
Owner

@jeremystretch commented on GitHub (Jul 1, 2021):

I'm going to proceed with closing this as the secrets app is being split off into a separate plugin for NetBox v3.0.

@jeremystretch commented on GitHub (Jul 1, 2021): I'm going to proceed with closing this as the secrets app is being split off into a separate plugin for NetBox v3.0.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4840