Skip to content

Make cloud API/web/MQTT hosts configurable via build flag and env var#32

Open
dalsh wants to merge 4 commits into
ClusterM:masterfrom
dalsh:feat/configurable-cloud-hosts
Open

Make cloud API/web/MQTT hosts configurable via build flag and env var#32
dalsh wants to merge 4 commits into
ClusterM:masterfrom
dalsh:feat/configurable-cloud-hosts

Conversation

@dalsh

@dalsh dalsh commented May 21, 2026

Copy link
Copy Markdown

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 !

@dalsh dalsh force-pushed the feat/configurable-cloud-hosts branch from 17eca35 to da30357 Compare May 21, 2026 13:49
@ClusterM ClusterM requested a review from Copilot May 24, 2026 13:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 from OBN_CLOUD_* environment variables or compiled-in defaults.
  • Adds CMake cache options (and configure / configure.ps1 wrapper 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.

Comment thread configure Outdated
Comment on lines +100 to +103
--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.
Comment thread configure Outdated
Comment thread configure.ps1 Outdated
@arekm

arekm commented May 24, 2026

Copy link
Copy Markdown

IMO there should be configuration file (+ env variables) and whole hardcoding in code, in configure should be dropped.

Like

  │  Platform   │                user_config_dir                │   system_config_dir   │
  ├─────────────┼───────────────────────────────────────────────┼───────────────────────┤
  │ Linux/macOS │ $XDG_CONFIG_HOME/xyz or ~/.config/xyz.        │ /etc/xyz              │
  ├─────────────┼───────────────────────────────────────────────┼───────────────────────┤
  │ Windows     │ %APPDATA%\xyz                                 │ %PROGRAMDATA%\xyz    │

@ClusterM

Copy link
Copy Markdown
Owner

@dalsh thank you! But I think that @arekm is right, we should make a config file. Especially when precompiled binaries will be distributed.

Also, build tests are failed, can you fix it? And check Copilot's comments.

@dalsh dalsh force-pushed the feat/configurable-cloud-hosts branch from 9bd6abb to e03d15c Compare May 26, 2026 11:15
@dalsh

dalsh commented May 26, 2026

Copy link
Copy Markdown
Author

@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.

@ClusterM

Copy link
Copy Markdown
Owner

I think that I'll make a config file on my own

@ClusterM ClusterM force-pushed the master branch 2 times, most recently from 5dbd9e2 to 1c4bb8e Compare June 1, 2026 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants