Initial project snapshot
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
|
||||
"github.com/example/remote-access-platform/agents/rap-node-agent/internal/client"
|
||||
"github.com/example/remote-access-platform/agents/rap-node-agent/internal/state"
|
||||
)
|
||||
|
||||
const Version = "0.1.0-c3"
|
||||
|
||||
func EnrollmentPayload(clusterID, joinToken string, identity state.Identity) client.EnrollRequest {
|
||||
return client.EnrollRequest{
|
||||
ClusterID: clusterID,
|
||||
JoinToken: joinToken,
|
||||
NodeName: identity.NodeName,
|
||||
NodeFingerprint: identity.NodeFingerprint,
|
||||
PublicKey: identity.PublicKey,
|
||||
ReportedCapabilities: map[string]any{
|
||||
"can_accept_client_ingress": false,
|
||||
"can_accept_node_ingress": false,
|
||||
"can_route_mesh": false,
|
||||
"can_run_rdp_worker": true,
|
||||
"can_run_vnc_worker": false,
|
||||
"can_run_vpn_exit": false,
|
||||
"can_run_vpn_connector": false,
|
||||
"can_run_file_cache": false,
|
||||
"can_run_update_cache": false,
|
||||
"can_run_video_relay": false,
|
||||
"native_node_agent_version": Version,
|
||||
"service_supervision_enabled": false,
|
||||
},
|
||||
ReportedFacts: map[string]any{
|
||||
"os": runtime.GOOS,
|
||||
"arch": runtime.GOARCH,
|
||||
"agent": "rap-node-agent",
|
||||
"agent_ver": Version,
|
||||
},
|
||||
RequestedRoles: []string{},
|
||||
}
|
||||
}
|
||||
|
||||
func HeartbeatPayload() client.HeartbeatRequest {
|
||||
return client.HeartbeatRequest{
|
||||
HealthStatus: "healthy",
|
||||
ReportedVersion: Version,
|
||||
Capabilities: map[string]any{
|
||||
"native_node_agent": true,
|
||||
},
|
||||
ServiceStates: map[string]any{
|
||||
"workload_supervision": "not_implemented_c3",
|
||||
},
|
||||
Metadata: map[string]any{
|
||||
"stage": "c3",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func MeshSelfObservationPayload(identity state.Identity) client.MeshLinkObservationRequest {
|
||||
return client.MeshLinkObservationRequest{
|
||||
SourceNodeID: identity.NodeID,
|
||||
TargetNodeID: identity.NodeID,
|
||||
LinkStatus: "reachable",
|
||||
Metadata: map[string]any{
|
||||
"stage": "c6",
|
||||
"traffic_forwarding": false,
|
||||
"observation_type": "self",
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/example/remote-access-platform/agents/rap-node-agent/internal/state"
|
||||
)
|
||||
|
||||
func TestEnrollmentPayloadDoesNotRequestRolesByDefault(t *testing.T) {
|
||||
payload := EnrollmentPayload("cluster-1", "join-token", state.Identity{
|
||||
NodeName: "node-a",
|
||||
NodeFingerprint: "fp",
|
||||
PublicKey: "pub",
|
||||
})
|
||||
if payload.ClusterID != "cluster-1" || payload.JoinToken != "join-token" {
|
||||
t.Fatalf("unexpected enrollment payload: %+v", payload)
|
||||
}
|
||||
if len(payload.RequestedRoles) != 0 {
|
||||
t.Fatalf("agent must not self-assign roles: %+v", payload.RequestedRoles)
|
||||
}
|
||||
if payload.ReportedCapabilities["can_run_rdp_worker"] != true {
|
||||
t.Fatalf("expected rdp capability in MVP payload: %+v", payload.ReportedCapabilities)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHeartbeatPayloadIsStatusOnly(t *testing.T) {
|
||||
payload := HeartbeatPayload()
|
||||
if payload.HealthStatus != "healthy" {
|
||||
t.Fatalf("HealthStatus = %q", payload.HealthStatus)
|
||||
}
|
||||
if payload.ServiceStates["workload_supervision"] == "running" {
|
||||
t.Fatal("C3 must not pretend workload supervision is implemented")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMeshSelfObservationDoesNotEnableTrafficForwarding(t *testing.T) {
|
||||
payload := MeshSelfObservationPayload(state.Identity{NodeID: "node-1"})
|
||||
if payload.SourceNodeID != "node-1" || payload.TargetNodeID != "node-1" {
|
||||
t.Fatalf("unexpected mesh self observation payload: %+v", payload)
|
||||
}
|
||||
if payload.Metadata["traffic_forwarding"] != false {
|
||||
t.Fatalf("traffic forwarding must stay disabled in C6: %+v", payload.Metadata)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/example/remote-access-platform/agents/rap-node-agent/internal/client"
|
||||
"github.com/example/remote-access-platform/agents/rap-node-agent/internal/state"
|
||||
)
|
||||
|
||||
func TelemetryPayload(identity state.Identity, startedAt time.Time) client.TelemetryRequest {
|
||||
var mem runtime.MemStats
|
||||
runtime.ReadMemStats(&mem)
|
||||
used := int64(mem.Alloc)
|
||||
total := int64(mem.Sys)
|
||||
processCount := runtime.NumGoroutine()
|
||||
return client.TelemetryRequest{
|
||||
MemoryUsedBytes: &used,
|
||||
MemoryTotalBytes: &total,
|
||||
ProcessCount: &processCount,
|
||||
Payload: map[string]any{
|
||||
"agent": "rap-node-agent",
|
||||
"agent_version": Version,
|
||||
"node_name": identity.NodeName,
|
||||
"os": runtime.GOOS,
|
||||
"arch": runtime.GOARCH,
|
||||
"goroutines": runtime.NumGoroutine(),
|
||||
"uptime_seconds": int64(time.Since(startedAt).Seconds()),
|
||||
"telemetry_source": "testing_flag",
|
||||
},
|
||||
ObservedAt: time.Now().UTC(),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user