Closed MalfuncEddie closed 8 months ago
Hi.
You can use fn.fnRestJw to do token based authentication. See the following example I'm using a call to get the token based on u/p and the 2nd will use the token for auth.
On Wed, Dec 6, 2023 at 3:40 PM MalfuncEddie @.***> wrote:
Is your feature request related to a problem? Please describe.
I'm trying to ducktape netbox (https://github.com/netbox-community/netbox) together with ansible forms. A lot of my automation data is stored in netbox.
- Currently (I think) only username/password are supported as credential but netbox uses a token based approach. ( https://demo.netbox.dev/static/docs/rest-api/authentication/)
- The results are situated in in the results array and is not a flat object?
{ "count": 101, "next": "https://netbox/api/tenancy/tenants/?limit=100&offset=100", "previous": null, "results": [ { "id": 73, "name": "tenantA" ...
Describe the solution you'd like
It would be a great improvement if token based authentication could be used. and you can select what field you need and value
eg:
Get every "name" of "results" in the dropdown.
Netbox has a great api that can be used and it would be nice if ansible forms can integrate with netbox since it does have an hierarchy (region -> site- > ...). Example:
dropdown select tenant if tenant is selected the 2nd drop down shows only the sites of the tenant. https://netbox/api/dcim/sites/?tenant=(field from dropdown 1)
Describe alternatives you've considered Still figuring this project out so could be I just missed things in the documentation :)
alternative: dump the api fields to json every night and use json files? alternative2: user custom scripts in netbox but that does not have the features rich features of this project
Additional context I really like this project since it fills in a gap left by the awx team, but Javascript front end / typescript is an unexplored field for me ;(
— Reply to this email directly, view it on GitHub https://github.com/ansibleguy76/ansibleforms/issues/122, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFK2OVVM4TJA7YYJMFOLTJLYIBYTTAVCNFSM6AAAAABAJMXP2CVHI2DSMVQWIX3LMV43ASLTON2WKOZSGAZDQNJYGYYTCMY . You are receiving this because you are subscribed to this thread.Message ID: @.***>
-- Best Regards,
Haim Marko
this is exactly what I want but correct me if I am wrong but netbox uses a token in its header and is not a jwt token?
curl -H "Authorization: Token $TOKEN" \
-H "Accept: application/json; indent=4" \
https://netbox/api/dcim/sites/
{
"count": 10,
"next": null,
"previous": null,
"results": [...]
}
ugly hack in default.js
exports.fnRestNetbox = async function (action, url, body, token, jqe = null, sort = null, hasBigInt = false) {
var headers = {}
if (token) {
headers.Authorization = "Token censored"
}
return await exports.fnRestAdvanced(action, url, body, headers, jqe, sort, hasBigInt)
}
why not using advanced directly. why the wrap?
ugly hack in default.js
exports.fnRestNetbox = async function (action, url, body, token, jqe = null, sort = null, hasBigInt = false) { var headers = {} if (token) { headers.Authorization = "Token censored" } return await exports.fnRestAdvanced(action, url, body, headers, jqe, sort, hasBigInt) }
Just use fn.fnRestAdvanced twice (post => token => get with headers)
No need to for the "if (token)".
name: test form
type: awx
template: template tst
description: ""
roles:
- admin
categories: []
tileClass: has-background-info-light
icon: bullseye
fields:
- type: enum
name: Tenant
expression: fn.fnRestAdvanced( 'get', 'https://netbox/api/tenancy/tenants/','',{ 'Authorization':'Token aaaaaaaaaaaaaaaaa'}, '[.results[]]')
columns:
- name
valueColumn: id
Thanks for the info. I got it working. Only issue i have is that I would have liked the "aaaaaaaa" token to come from a ansible forms credential but not sure if fnRestAdvanced supports that. either case it is a read only credential so no big woop :)
the restjwtsecure does it bit with Bearer. i could extend that one with the prefix word (token in your case)
I would welcome this but I got it working and don't want to be an extra burden so if you could do it is would be greatly appreciated.
I would welcome this but I got it working and don't want to be an extra burden so if you could do it is would be greatly appreciated.
Will be in 5.0.0 => building beta now with this feature. functions fnRestJwt and fnRestJwtSecure now have the extra property "tokenPrefix"
Is your feature request related to a problem? Please describe.
I'm trying to ducktape netbox (https://github.com/netbox-community/netbox) together with ansible forms. A lot of my automation data is stored in netbox.
Describe the solution you'd like
It would be a great improvement if token based authentication could be used. and you can select what field you need and value
eg:
Get every "name" of "results" in the dropdown.
Netbox has a great api that can be used and it would be nice if ansible forms can integrate with netbox since it does have an hierarchy (region -> site- > ...). Example:
dropdown select tenant if tenant is selected the 2nd drop down shows only the sites of the tenant. https://netbox/api/dcim/sites/?tenant=(field from dropdown 1)
Describe alternatives you've considered Still figuring this project out so could be I just missed things in the documentation :)
alternative: dump the api fields to json every night and use json files? alternative2: user custom scripts in netbox but that does not have the features rich features of this project
Additional context I really like this project since it fills in a gap left by the awx team, but Javascript front end / typescript is an unexplored field for me ;(