Make cloud API/web/MQTT hosts configurable via build flag and env var#32
Make cloud API/web/MQTT hosts configurable via build flag and env var#32dalsh wants to merge 4 commits into
Conversation
17eca35 to
da30357
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds build-time and runtime configuration for Bambu cloud endpoints so the plugin can target alternative API/web/MQTT hosts (e.g., for self-hosted or proxied cloud services), addressing the hardcoded URLs noted in issue #30.
Changes:
- Introduces a small
obn::config::resolve_override()helper to resolve an endpoint fromOBN_CLOUD_*environment variables or compiled-in defaults. - Adds CMake cache options (and
configure/configure.ps1wrapper flags) to bake cloud endpoint overrides into the build. - Applies overrides in cloud HTTP auth host selection and cloud MQTT broker hostname selection.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/cloud_session.cpp |
Uses env/compiled override for MQTT broker hostname before falling back to region defaults. |
src/cloud_auth.cpp |
Uses env/compiled overrides for REST API base URL and web portal base URL. |
include/obn/config.hpp |
Adds inline helper for resolving env var overrides with compiled defaults. |
configure.ps1 |
Adds Windows wrapper parameters and forwards override values to CMake. |
configure |
Adds POSIX wrapper flags, help text, and forwards override values to CMake. |
CMakeLists.txt |
Adds cache variables and compiles their values into the plugin as string macros. |
Comments suppressed due to low confidence (1)
src/cloud_auth.cpp:60
- web_host() is documented/used as a portal base that ends with '/' (see include/obn/cloud_auth.hpp and src/abi_user.cpp), but this implementation returns URLs without a trailing slash (and the override path returns the env/CMake value verbatim). This makes the returned base inconsistent and can produce malformed concatenations like "https://bambulab.comapi/..." depending on how Studio appends paths. Consider normalizing the result to always include exactly one trailing '/' (including override values) and updating the in-function comment accordingly.
if (auto o = config::resolve_override("OBN_CLOUD_WEB_URL", OBN_CLOUD_WEB_URL_DEFAULT)) return *o;
// No trailing slash: Studio appends "/sign-in" (WebUserLoginDialog)
// and "api/sign-in/ticket?..." (bind flow) to this value.
if (region == "CN" || region == "cn") return "https://bambulab.cn";
return "https://bambulab.com";
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| --cloud-web-url=URL Cloud web portal base URL (no trailing slash), | ||
| e.g. https://example.com. Replaces | ||
| https://bambulab.com / .bambulab.cn. | ||
| Runtime env: OBN_CLOUD_WEB_URL. |
|
IMO there should be configuration file (+ env variables) and whole hardcoding in code, in configure should be dropped. Like |
# Conflicts: # configure # Conflicts: # CMakeLists.txt
9bd6abb to
e03d15c
Compare
|
@ClusterM I pushed changes, build seems to look good on my fork : https://github.com/dalsh/open-bamboo-networking/actions/runs/26467266383 Fixed copilot-raised issue about cache stickiness. Regarding the other feedback on the trailing slash: comments in cloud_auth.hpp and cloud_auth.cpp disagreed (one said trailing slash mandatory, the other said no trailing slash). I opted for trailing slash mandatory with this rationale: https://github.com/ClusterM/open-bamboo-networking/pull/32/changes#diff-0fa26d76bab75c8472d26b31f13367ac34dad98ffa0126d4bb04ad8702fc4bb1R57 It's a bit fragile if you want my opinion, I'd rather have the code normalize whatever comes from the config but I wanted to keep the change minimal. Tell me if you want that I look into that. Regarding config files, I was mentioning it too in my original issue, I agree that would be a good thing to have ! That'll make that PR a bit larger than I like however, I'd rather build that in a follow-up PR. Or even one branching from this one if you want to have the full picture before merging. Of course, only my preference, if you prefer I can add commits on top of this PR's branch, your call. |
|
I think that I'll make a config file on my own |
5dbd9e2 to
1c4bb8e
Compare
Follow-up to #30
Add configuration options to use different hostnames for web/api/mqtt in cloud features.
Small inline helper added in (new) config.hpp, is that ok ? I you want me to reshape this in any different way that'll be no issue. Thx !