mirror of
https://github.com/fosrl/olm.git
synced 2026-03-05 02:06:48 +00:00
Add org id in the status
This commit is contained in:
12
api/api.go
12
api/api.go
@@ -40,6 +40,7 @@ type StatusResponse struct {
|
|||||||
Registered bool `json:"registered"`
|
Registered bool `json:"registered"`
|
||||||
TunnelIP string `json:"tunnelIP,omitempty"`
|
TunnelIP string `json:"tunnelIP,omitempty"`
|
||||||
Version string `json:"version,omitempty"`
|
Version string `json:"version,omitempty"`
|
||||||
|
OrgID string `json:"orgId,omitempty"`
|
||||||
PeerStatuses map[int]*PeerStatus `json:"peers,omitempty"`
|
PeerStatuses map[int]*PeerStatus `json:"peers,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,6 +60,7 @@ type API struct {
|
|||||||
isRegistered bool
|
isRegistered bool
|
||||||
tunnelIP string
|
tunnelIP string
|
||||||
version string
|
version string
|
||||||
|
orgID string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewAPI creates a new HTTP server that listens on a TCP address
|
// 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
|
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
|
// UpdatePeerRelayStatus updates only the relay status of a peer
|
||||||
func (s *API) UpdatePeerRelayStatus(siteID int, endpoint string, isRelay bool) {
|
func (s *API) UpdatePeerRelayStatus(siteID int, endpoint string, isRelay bool) {
|
||||||
s.statusMu.Lock()
|
s.statusMu.Lock()
|
||||||
@@ -275,6 +284,7 @@ func (s *API) handleStatus(w http.ResponseWriter, r *http.Request) {
|
|||||||
Registered: s.isRegistered,
|
Registered: s.isRegistered,
|
||||||
TunnelIP: s.tunnelIP,
|
TunnelIP: s.tunnelIP,
|
||||||
Version: s.version,
|
Version: s.version,
|
||||||
|
OrgID: s.orgID,
|
||||||
PeerStatuses: s.peerStatuses,
|
PeerStatuses: s.peerStatuses,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -341,7 +351,7 @@ func (s *API) handleSwitchOrg(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// Return a success response
|
// Return a success response
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.WriteHeader(http.StatusAccepted)
|
w.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode(map[string]string{
|
json.NewEncoder(w).Encode(map[string]string{
|
||||||
"status": "org switch request accepted",
|
"status": "org switch request accepted",
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ func Run(ctx context.Context, config Config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
apiServer.SetVersion(config.Version)
|
apiServer.SetVersion(config.Version)
|
||||||
|
apiServer.SetOrgID(config.OrgID)
|
||||||
if err := apiServer.Start(); err != nil {
|
if err := apiServer.Start(); err != nil {
|
||||||
logger.Fatal("Failed to start HTTP server: %v", err)
|
logger.Fatal("Failed to start HTTP server: %v", err)
|
||||||
}
|
}
|
||||||
@@ -755,6 +756,7 @@ func Run(ctx context.Context, config Config) {
|
|||||||
if apiServer != nil {
|
if apiServer != nil {
|
||||||
apiServer.SetRegistered(false)
|
apiServer.SetRegistered(false)
|
||||||
apiServer.SetTunnelIP("")
|
apiServer.SetTunnelIP("")
|
||||||
|
apiServer.SetOrgID(config.OrgID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trigger re-registration with new orgId
|
// Trigger re-registration with new orgId
|
||||||
|
|||||||
Reference in New Issue
Block a user