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,27 @@
|
||||
package domain
|
||||
|
||||
type RegisterAgentData struct {
|
||||
AgentId string
|
||||
AgentName string
|
||||
AgentVersion string
|
||||
Host HostInfo
|
||||
Capabilities []Capability
|
||||
}
|
||||
|
||||
type HostInfo struct {
|
||||
System string
|
||||
Hostname string
|
||||
Arch string
|
||||
}
|
||||
|
||||
type Capability struct {
|
||||
Available bool
|
||||
Version string
|
||||
Name string
|
||||
Reason string
|
||||
}
|
||||
|
||||
type RegisterAgentDataResponse struct {
|
||||
Heartbeat int
|
||||
AgentID string
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
package rpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
pb "github.com/lorsanstand/HomeOps-Hub/api/gen/homeops"
|
||||
"github.com/lorsanstand/HomeOps-Hub/internal/agent/domain"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
@@ -30,3 +32,8 @@ func (c *Connection) Close() error {
|
||||
func (c *Connection) Hub() pb.HubClient {
|
||||
return c.hub
|
||||
}
|
||||
|
||||
func (c *Connection) RegisterAgent(ctx context.Context, RegisterData domain.RegisterAgentData) (domain.RegisterAgentDataResponse, error) {
|
||||
ResponseData, err := c.Hub().RegisterAgent(ctx, new(toAgentRegisterRequest(RegisterData)))
|
||||
return toAgentRegisterDataResponse(ResponseData), err
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package hub_service
|
||||
|
||||
import (
|
||||
"github.com/lorsanstand/HomeOps-Hub/internal/agent/rpc"
|
||||
"github.com/lorsanstand/HomeOps-Hub/internal/agent/service/docker_service"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
type HubService struct {
|
||||
docker *docker_service.DockerService
|
||||
log zerolog.Logger
|
||||
hubConn *rpc.Connection
|
||||
}
|
||||
|
||||
func NewHubService(docker *docker_service.DockerService, log zerolog.Logger) *HubService {
|
||||
return &HubService{docker: docker, log: log}
|
||||
}
|
||||
|
||||
func (h *HubService) GatherInfoSystem() {
|
||||
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package hub_service
|
||||
|
||||
type AgentRegistrationData struct {
|
||||
AgentID string
|
||||
AgentName string
|
||||
Config AgentConfig
|
||||
}
|
||||
|
||||
type AgentConfig struct {
|
||||
System string
|
||||
Docker bool
|
||||
Hostname string
|
||||
Version string
|
||||
Arch string
|
||||
}
|
||||
Reference in New Issue
Block a user