mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-04-28 03:20:11 +00:00
Pass setup token in Proxmox auto-register requests (#1303)
This commit is contained in:
parent
83f8e93543
commit
930738593b
2 changed files with 18 additions and 0 deletions
|
|
@ -817,6 +817,12 @@ func (p *ProxmoxSetup) registerWithPulse(ctx context.Context, ptype, hostURL, to
|
|||
"tokenValue": tokenValue,
|
||||
"source": "agent", // Indicates this was registered via agent
|
||||
}
|
||||
if token := strings.TrimSpace(p.apiToken); token != "" {
|
||||
// Auto-register accepts one-time setup tokens via the JSON body. The
|
||||
// agent initially only has that setup token, not a persisted API token,
|
||||
// so send it here as well as the auth header.
|
||||
payload["authToken"] = token
|
||||
}
|
||||
|
||||
body, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package hostagent
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
|
|
@ -349,9 +350,17 @@ func TestRegisterWithPulseRetry(t *testing.T) {
|
|||
var attempt int32
|
||||
var gotAuth string
|
||||
var gotAPIToken string
|
||||
var gotAuthToken string
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
gotAuth = r.Header.Get("Authorization")
|
||||
gotAPIToken = r.Header.Get("X-API-Token")
|
||||
var payload map[string]interface{}
|
||||
if err := json.NewDecoder(r.Body).Decode(&payload); err != nil {
|
||||
t.Fatalf("decode payload: %v", err)
|
||||
}
|
||||
if token, _ := payload["authToken"].(string); token != "" {
|
||||
gotAuthToken = token
|
||||
}
|
||||
n := atomic.AddInt32(&attempt, 1)
|
||||
if n <= 2 {
|
||||
w.WriteHeader(http.StatusServiceUnavailable)
|
||||
|
|
@ -383,6 +392,9 @@ func TestRegisterWithPulseRetry(t *testing.T) {
|
|||
if gotAPIToken != "test-token" {
|
||||
t.Fatalf("X-API-Token = %q, want %q", gotAPIToken, "test-token")
|
||||
}
|
||||
if gotAuthToken != "test-token" {
|
||||
t.Fatalf("authToken payload = %q, want %q", gotAuthToken, "test-token")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegisterWithPulseNoRetryOn4xx(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue