mirror of
https://github.com/lorsanstand/HomeOps-Hub.git
synced 2026-06-19 17:45:17 +03:00
feat: add Register agent in agent
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package rpc
|
||||
|
||||
import (
|
||||
pb "github.com/lorsanstand/HomeOps-Hub/api/gen/homeops"
|
||||
"github.com/lorsanstand/HomeOps-Hub/internal/agent/domain"
|
||||
)
|
||||
|
||||
func toAgentRegisterRequest(request domain.RegisterAgentData) pb.RegisterAgentRequest {
|
||||
return pb.RegisterAgentRequest{
|
||||
AgentId: request.AgentId,
|
||||
AgentName: request.AgentName,
|
||||
Host: &pb.HostInfo{
|
||||
Hostname: request.Host.Hostname,
|
||||
Arch: request.Host.Arch,
|
||||
System: request.Host.System,
|
||||
},
|
||||
Version: request.AgentVersion,
|
||||
Capability: toGRPCCapability(request.Capabilities),
|
||||
}
|
||||
}
|
||||
|
||||
func toGRPCCapability(caps []domain.Capability) []*pb.Capability {
|
||||
capability := make([]*pb.Capability, len(caps))
|
||||
for _, capi := range caps {
|
||||
capability = append(capability, &pb.Capability{
|
||||
Name: capi.Name,
|
||||
Available: capi.Available,
|
||||
Version: capi.Version,
|
||||
Reason: capi.Reason,
|
||||
})
|
||||
}
|
||||
return capability
|
||||
}
|
||||
|
||||
func toAgentRegisterDataResponse(response *pb.RegisterAgentResponse) domain.RegisterAgentDataResponse {
|
||||
return domain.RegisterAgentDataResponse{
|
||||
AgentID: response.AgentId,
|
||||
Heartbeat: int(response.HeartbeatIntervalSecond),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user