The-Nazara-Project / Nazara

A CLI application to create and update machines and VMs in Netbox.
GNU General Public License v3.0
11 stars 2 forks source link

[PLAYGROUND:] Generate openapi client #33

Closed ByteOtter closed 12 months ago

ByteOtter commented 1 year ago

What does this PR change?

This PR serves as a playground to check if the openAPI code generator which generated our api client works correctly and which parts of it could be removed.

Tick the applicable box:

Links

Fixes:

Documentation

ByteOtter commented 1 year ago

@SchoolGuy So, thanks to some help I was able to integrate the API client as a local crate. There are still some things left to do: Triage what code from the client we actually need and fix the program crashing.

In my test setup, the requests fail because of some referrer header missing and something about CSRF tokens - We're unsure if there's something to fix locally or if the configuration would have to be changed in the netbox config.

SchoolGuy commented 1 year ago

@ByteOtter It could be both actually.

One interesting thread is https://github.com/netbox-community/netbox/discussions/9043. It describes that this is more of a server-side problem. It could also be client-side as Rust could drop the CSRF token when doing multiple calls after each other. I suggest you use a Dockerized Netbox container and test for this behaviour locally. Depending on those results I would then ask internally if I can get some time to update (and fix) our Netbox instance or if someone else could do that.

ByteOtter commented 1 year ago

@ByteOtter It could be both actually.

One interesting thread is https://github.com/netbox-community/netbox/discussions/9043. It describes that this is more of a server-side problem. It could also be client-side as Rust could drop the CSRF token when doing multiple calls after each other. I suggest you use a Dockerized Netbox container and test for this behaviour locally. Depending on those results I would then ask internally if I can get some time to update (and fix) our Netbox instance or if someone else could do that.

Thanks for taking the time to look into this. We habe tried using a docker container of netbox before but it didn't work either. So maybe this needs some more digging. Could also be that we did something wrong on our end though. I will try again and update you here.

ByteOtter commented 1 year ago

@SchoolGuy So, the current version is configured to try to connect to the netbox demo api at https://demo.netbox.dev

which fails with this output:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ResponseError(ResponseContent { status: 403, content: "\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n  <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">\n  <meta name=\"robots\" content=\"NONE,NOARCHIVE\">\n  <title>403 Forbidden</title>\n  <style type=\"text/css\">\n    html * { padding:0; margin:0; }\n    body * { padding:10px 20px; }\n    body * * { padding:0; }\n    body { font:small sans-serif; background:#eee; color:#000; }\n    body>div { border-bottom:1px solid #ddd; }\n    h1 { font-weight:normal; margin-bottom:.4em; }\n    h1 span { font-size:60%; color:#666; font-weight:normal; }\n    #info { background:#f6f6f6; }\n    #info ul { margin: 0.5em 4em; }\n    #info p, #summary p { padding-top:10px; }\n    #summary { background: #ffc; }\n    #explanation { background:#eee; border-bottom: 0px none; }\n  </style>\n</head>\n<body>\n<div id=\"summary\">\n  <h1>Forbidden <span>(403)</span></h1>\n  <p>CSRF verification failed. Request aborted.</p>\n\n  <p>You are seeing this message because this HTTPS site requires a “Referer header” to be sent by your web browser, but none was sent. This header is required for security reasons, to ensure that your browser is not being hijacked by third parties.</p>\n  <p>If you have configured your browser to disable “Referer” headers, please re-enable them, at least for this site, or for HTTPS connections, or for “same-origin” requests.</p>\n  <p>If you are using the &lt;meta name=&quot;referrer&quot; content=&quot;no-referrer&quot;&gt; tag or including the “Referrer-Policy: no-referrer” header, please remove them. The CSRF protection requires the “Referer” header to do strict referer checking. If you’re concerned about privacy, use alternatives like &lt;a rel=&quot;noreferrer&quot; …&gt; for links to third-party sites.</p>\n\n\n</div>\n\n<div id=\"explanation\">\n  <p><small>More information is available with DEBUG=True.</small></p>\n</div>\n\n</body>\n</html>\n", entity: None })', src/main.rs:66:10
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

It's a webpage that says:

You are seeing this message because this HTTPS site requires a “Referer header” to be sent by your web browser, but none was sent. This header is required for security reasons, to ensure that your browser is not being hijacked by third parties. If you have configured your browser to disable “Referer” headers, please re-enable them, at least for this site, or for HTTPS connections, or for “same-origin” requests. If you are using the <meta name="referrer" content="no-referrer"> tag or including the “Referrer-Policy: no-referrer” header, please remove them. The CSRF protection requires the “Referer” header to do strict referer checking. If you’re concerned about privacy, use alternatives like <a rel="noreferrer" …> for links to third-party sites.

ByteOtter commented 12 months ago

As discussed earlier this PR is more trouble than it is worth and it would be best to implement our own logic to connect to NetBox.