From 963d8abad52a3cade3269a30b625a46d10dfaf6f Mon Sep 17 00:00:00 2001 From: Owen Date: Mon, 3 Nov 2025 20:54:55 -0800 Subject: [PATCH] Add org id in the status Former-commit-id: da1e4911bdf68a854fdfc788f6657c25ebe6a5b8 --- api/api.go | 12 +++++++++++- olm/olm.go | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/api/api.go b/api/api.go index adc613e..969513d 100644 --- a/api/api.go +++ b/api/api.go @@ -40,6 +40,7 @@ type StatusResponse struct { Registered bool `json:"registered"` TunnelIP string `json:"tunnelIP,omitempty"` Version string `json:"version,omitempty"` + OrgID string `json:"orgId,omitempty"` PeerStatuses map[int]*PeerStatus `json:"peers,omitempty"` } @@ -59,6 +60,7 @@ type API struct { isRegistered bool tunnelIP string version string + orgID string } // NewAPI creates a new HTTP server that listens on a TCP address @@ -212,6 +214,13 @@ func (s *API) SetVersion(version string) { s.version = version } +// SetOrgID sets the organization ID +func (s *API) SetOrgID(orgID string) { + s.statusMu.Lock() + defer s.statusMu.Unlock() + s.orgID = orgID +} + // UpdatePeerRelayStatus updates only the relay status of a peer func (s *API) UpdatePeerRelayStatus(siteID int, endpoint string, isRelay bool) { s.statusMu.Lock() @@ -275,6 +284,7 @@ func (s *API) handleStatus(w http.ResponseWriter, r *http.Request) { Registered: s.isRegistered, TunnelIP: s.tunnelIP, Version: s.version, + OrgID: s.orgID, PeerStatuses: s.peerStatuses, } @@ -341,7 +351,7 @@ func (s *API) handleSwitchOrg(w http.ResponseWriter, r *http.Request) { // Return a success response w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusAccepted) + w.WriteHeader(http.StatusOK) json.NewEncoder(w).Encode(map[string]string{ "status": "org switch request accepted", }) diff --git a/olm/olm.go b/olm/olm.go index 746f350..bb3433a 100644 --- a/olm/olm.go +++ b/olm/olm.go @@ -110,6 +110,7 @@ func Run(ctx context.Context, config Config) { } apiServer.SetVersion(config.Version) + apiServer.SetOrgID(config.OrgID) if err := apiServer.Start(); err != nil { logger.Fatal("Failed to start HTTP server: %v", err) } @@ -755,6 +756,7 @@ func Run(ctx context.Context, config Config) { if apiServer != nil { apiServer.SetRegistered(false) apiServer.SetTunnelIP("") + apiServer.SetOrgID(config.OrgID) } // Trigger re-registration with new orgId