feat(cli): detect network location and adapt connection method per profile#3304
feat(cli): detect network location and adapt connection method per profile#3304pengpeng wants to merge 1 commit into
Conversation
…ofile Probe where the CLI sits relative to an Olares instance (lan / host / cluster / external) during profile login & import, persist it, and select the fastest reachable connection method (URL scheme + host + DNS resolver) on every command. On a mid-request transport error the location is re-probed and the request retried against the new method, with a short outage cooldown to fail fast during sustained outages. - pkg/olares: Location type + per-location URL/endpoint derivation - pkg/access: ProbeLocation (lan -> host/cluster via 10.233.0.3 + source-IP discrimination -> external), location-aware transports, net-error classification, and a friendly UnreachableError surfaced on outage - pkg/cmdutil: location-aware refreshing transport, re-probe/switch on switchable net errors, outage cooldown - pkg/whoami: unified detect (location + role + backend version) with a single locked config write - pkg/cliconfig: Location fields + cross-process config.json file locking - profile commands: probe on login/import, LOCATION column in `list`, `whoami`/`list --refresh` re-detect Adds unit coverage across access/cliconfig/cmdutil and a probe injection seam for deterministic ordering/short-circuit tests. Co-authored-by: Cursor <cursoragent@cursor.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 3ef6e0c. Configure here.
| OlaresID: olaresID, | ||
| Password: password, | ||
| TOTP: o.totp, | ||
| Location: loc, |
There was a problem hiding this comment.
Probe and auth TLS mismatch
Medium Severity
On profile login and profile import, probeProfileLocation uses the merged profile’s InsecureSkipVerify, but auth.Login / auth.Refresh still use the CLI flag o.insecureSkipVerify. Re-auth on a profile that already has TLS verification disabled in config (without passing the flag again) can pass the probe then fail authentication with certificate errors.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 3ef6e0c. Configure here.
Summary
Teaches
olares-cliwhere it sits on the network relative to an Olares instance and makes every command use the fastest reachable connection method automatically.lan(http://...olares.local),host(public host via the in-cluster DNS10.233.0.3),cluster(in-pod), orexternal(public) — persist it on the profile, and derive scheme + host + DNS resolver from it at runtime.lan->host/cluster(intranet via10.233.0.3, host vs cluster decided by whether the connection source IP falls in100.64.0.0/10) ->external. Any HTTP response counts as reachable; all-fail yields a friendlyUnreachableError.Unwrap).profile whoami(and the post-login eager pass) detect location + role + backend version together and persist them in a single lockedconfig.jsonwrite.config.jsonwriters (login/import,use,remove, location/role/version) go through aflock-guarded read-modify-write.profile list: newLOCATIONcolumn;--refreshre-detects the current profile.Notable files
cli/pkg/olares/location.go—Locationtype + per-location URL/endpoint derivationcli/pkg/access/—ProbeLocation, location-aware transports, net-error classification,UnreachableErrorcli/pkg/cmdutil/factory.go— location-aware refreshing transport, re-probe/switch, cooldowncli/pkg/whoami/detect.go— unified detect with one batched writecli/pkg/cliconfig/—Locationfields +lock.gocross-process lockingTest plan
go build ./...go vet+go testforpkg/access,pkg/cliconfig,pkg/cmdutil,pkg/olares,pkg/credential,cmd/ctl/profileUnreachableErrorsurfacinglocationand the connection method usedMade with Cursor
Note
Medium Risk
Touches all authenticated HTTP traffic (transport, refresh, login) and concurrent config writes; behavior changes when LAN/intranet paths exist, though external-only setups should largely match prior public-URL behavior.
Overview
Adds per-profile network location (
external/lan/host/cluster) so the CLI picks the fastest reachable path (LAN HTTP, intranet via cluster DNS, in-pod, or public HTTPS) instead of always using public URLs.Login/import probe before auth, persist
Locationon the profile, and passLocationintoauth.Login/auth.Refresh. Post-login eager detect is unified (eagerDetectviawhoami.DetectAndCache) for role + backend version at the probed location.profile whoamiandprofile list --refreshre-detect location, role, and version together; list gains a LOCATION column.--refresh-versionis removed in favor of those refresh paths.New
pkg/accessimplementsProbeLocation, location-awareTransport, switchable net-error classification, andUnreachableError.pkg/olaresaddsLocation,Endpoints, andRebaseURL; service URLs derive from location.cmdutil.Factorybackfills unknown locations, shares a mutablelocationState, and on switchable transport errors re-probes, retries once, persists switches, and applies a 30s outage cooldown with friendly errors.config.jsongains location fields plusUpdateLocked/SetDetectResults(single locked write for detect). Profile use/remove/persist mutate config under the same lock to avoid races with background location updates.Reviewed by Cursor Bugbot for commit 3ef6e0c. Bugbot is set up for automated code reviews on this repo. Configure here.