mirror of
https://github.com/fosrl/olm.git
synced 2026-03-05 18:26:44 +00:00
Compare commits
1 Commits
jit
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c7b590a23e |
@@ -1,4 +1,4 @@
|
|||||||
FROM golang:1.25-alpine AS builder
|
FROM golang:1.26-alpine AS builder
|
||||||
|
|
||||||
# Set the working directory inside the container
|
# Set the working directory inside the container
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|||||||
59
api/api.go
59
api/api.go
@@ -78,13 +78,6 @@ type MetadataChangeRequest struct {
|
|||||||
Postures map[string]any `json:"postures"`
|
Postures map[string]any `json:"postures"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// JITConnectionRequest defines the structure for a dynamic Just-In-Time connection request.
|
|
||||||
// Either SiteID or ResourceID must be provided (but not necessarily both).
|
|
||||||
type JITConnectionRequest struct {
|
|
||||||
Site string `json:"site,omitempty"`
|
|
||||||
Resource string `json:"resource,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// API represents the HTTP server and its state
|
// API represents the HTTP server and its state
|
||||||
type API struct {
|
type API struct {
|
||||||
addr string
|
addr string
|
||||||
@@ -99,7 +92,6 @@ type API struct {
|
|||||||
onExit func() error
|
onExit func() error
|
||||||
onRebind func() error
|
onRebind func() error
|
||||||
onPowerMode func(PowerModeRequest) error
|
onPowerMode func(PowerModeRequest) error
|
||||||
onJITConnect func(JITConnectionRequest) error
|
|
||||||
|
|
||||||
statusMu sync.RWMutex
|
statusMu sync.RWMutex
|
||||||
peerStatuses map[int]*PeerStatus
|
peerStatuses map[int]*PeerStatus
|
||||||
@@ -151,7 +143,6 @@ func (s *API) SetHandlers(
|
|||||||
onExit func() error,
|
onExit func() error,
|
||||||
onRebind func() error,
|
onRebind func() error,
|
||||||
onPowerMode func(PowerModeRequest) error,
|
onPowerMode func(PowerModeRequest) error,
|
||||||
onJITConnect func(JITConnectionRequest) error,
|
|
||||||
) {
|
) {
|
||||||
s.onConnect = onConnect
|
s.onConnect = onConnect
|
||||||
s.onSwitchOrg = onSwitchOrg
|
s.onSwitchOrg = onSwitchOrg
|
||||||
@@ -160,7 +151,6 @@ func (s *API) SetHandlers(
|
|||||||
s.onExit = onExit
|
s.onExit = onExit
|
||||||
s.onRebind = onRebind
|
s.onRebind = onRebind
|
||||||
s.onPowerMode = onPowerMode
|
s.onPowerMode = onPowerMode
|
||||||
s.onJITConnect = onJITConnect
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start starts the HTTP server
|
// Start starts the HTTP server
|
||||||
@@ -179,7 +169,6 @@ func (s *API) Start() error {
|
|||||||
mux.HandleFunc("/health", s.handleHealth)
|
mux.HandleFunc("/health", s.handleHealth)
|
||||||
mux.HandleFunc("/rebind", s.handleRebind)
|
mux.HandleFunc("/rebind", s.handleRebind)
|
||||||
mux.HandleFunc("/power-mode", s.handlePowerMode)
|
mux.HandleFunc("/power-mode", s.handlePowerMode)
|
||||||
mux.HandleFunc("/jit-connect", s.handleJITConnect)
|
|
||||||
|
|
||||||
s.server = &http.Server{
|
s.server = &http.Server{
|
||||||
Handler: mux,
|
Handler: mux,
|
||||||
@@ -644,54 +633,6 @@ func (s *API) handleRebind(w http.ResponseWriter, r *http.Request) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleJITConnect handles the /jit-connect endpoint.
|
|
||||||
// It initiates a dynamic Just-In-Time connection to a site identified by either
|
|
||||||
// a site or a resource. Exactly one of the two must be provided.
|
|
||||||
func (s *API) handleJITConnect(w http.ResponseWriter, r *http.Request) {
|
|
||||||
if r.Method != http.MethodPost {
|
|
||||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var req JITConnectionRequest
|
|
||||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
||||||
http.Error(w, fmt.Sprintf("Invalid request body: %v", err), http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate that exactly one of site or resource is provided
|
|
||||||
if req.Site == "" && req.Resource == "" {
|
|
||||||
http.Error(w, "Missing required field: either site or resource must be provided", http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if req.Site != "" && req.Resource != "" {
|
|
||||||
http.Error(w, "Ambiguous request: provide either site or resource, not both", http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if req.Site != "" {
|
|
||||||
logger.Info("Received JIT connection request via API: site=%s", req.Site)
|
|
||||||
} else {
|
|
||||||
logger.Info("Received JIT connection request via API: resource=%s", req.Resource)
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.onJITConnect != nil {
|
|
||||||
if err := s.onJITConnect(req); err != nil {
|
|
||||||
http.Error(w, fmt.Sprintf("JIT connection failed: %v", err), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
http.Error(w, "JIT connect handler not configured", http.StatusNotImplemented)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
w.WriteHeader(http.StatusAccepted)
|
|
||||||
_ = json.NewEncoder(w).Encode(map[string]string{
|
|
||||||
"status": "JIT connection request accepted",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// handlePowerMode handles the /power-mode endpoint
|
// handlePowerMode handles the /power-mode endpoint
|
||||||
// This allows changing the power mode between "normal" and "low"
|
// This allows changing the power mode between "normal" and "low"
|
||||||
func (s *API) handlePowerMode(w http.ResponseWriter, r *http.Request) {
|
func (s *API) handlePowerMode(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
2
olm.iss
2
olm.iss
@@ -32,7 +32,7 @@ DefaultGroupName={#MyAppName}
|
|||||||
DisableProgramGroupPage=yes
|
DisableProgramGroupPage=yes
|
||||||
; Uncomment the following line to run in non administrative install mode (install for current user only).
|
; Uncomment the following line to run in non administrative install mode (install for current user only).
|
||||||
;PrivilegesRequired=lowest
|
;PrivilegesRequired=lowest
|
||||||
OutputBaseFilename=olm_windows_installer
|
OutputBaseFilename=mysetup
|
||||||
SolidCompression=yes
|
SolidCompression=yes
|
||||||
WizardStyle=modern
|
WizardStyle=modern
|
||||||
; Add this to ensure PATH changes are applied and the system is prompted for a restart if needed
|
; Add this to ensure PATH changes are applied and the system is prompted for a restart if needed
|
||||||
|
|||||||
@@ -220,7 +220,6 @@ func (o *Olm) handleSync(msg websocket.WSMessage) {
|
|||||||
logger.Info("Sync: Adding new peer for site %d", siteId)
|
logger.Info("Sync: Adding new peer for site %d", siteId)
|
||||||
|
|
||||||
o.holePunchManager.TriggerHolePunch()
|
o.holePunchManager.TriggerHolePunch()
|
||||||
o.holePunchManager.ResetServerHolepunchInterval() // start sending immediately again so we fill in the endpoint on the cloud
|
|
||||||
|
|
||||||
// // TODO: do we need to send the message to the cloud to add the peer that way?
|
// // TODO: do we need to send the message to the cloud to add the peer that way?
|
||||||
// if err := o.peerManager.AddPeer(expectedSite); err != nil {
|
// if err := o.peerManager.AddPeer(expectedSite); err != nil {
|
||||||
|
|||||||
11
olm/olm.go
11
olm/olm.go
@@ -66,7 +66,6 @@ type Olm struct {
|
|||||||
updateRegister func(newData any)
|
updateRegister func(newData any)
|
||||||
|
|
||||||
stopPeerSend func()
|
stopPeerSend func()
|
||||||
stopPeerInit func()
|
|
||||||
|
|
||||||
// WaitGroup to track tunnel lifecycle
|
// WaitGroup to track tunnel lifecycle
|
||||||
tunnelWg sync.WaitGroup
|
tunnelWg sync.WaitGroup
|
||||||
@@ -285,16 +284,6 @@ func (o *Olm) registerAPICallbacks() {
|
|||||||
logger.Info("Processing power mode change request via API: mode=%s", req.Mode)
|
logger.Info("Processing power mode change request via API: mode=%s", req.Mode)
|
||||||
return o.SetPowerMode(req.Mode)
|
return o.SetPowerMode(req.Mode)
|
||||||
},
|
},
|
||||||
func(req api.JITConnectionRequest) error {
|
|
||||||
logger.Info("Processing JIT connect request via API: site=%s resource=%s", req.Site, req.Resource)
|
|
||||||
|
|
||||||
o.stopPeerInit, _ = o.websocket.SendMessageInterval("olm/wg/server/peer/init", map[string]interface{}{
|
|
||||||
"siteId": req.Site,
|
|
||||||
"resourceId": req.Resource,
|
|
||||||
}, 2*time.Second, 10)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user