feat: add forcedTags field and update proto
This commit is contained in:
parent
bc63c577a9
commit
02f68ebac8
9 changed files with 688 additions and 253 deletions
35
grpcv1.go
35
grpcv1.go
|
@ -3,9 +3,11 @@ package headscale
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/juanfont/headscale/gen/go/headscale/v1"
|
||||
v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
|
||||
"github.com/rs/zerolog/log"
|
||||
"tailscale.com/tailcfg"
|
||||
)
|
||||
|
@ -182,6 +184,37 @@ func (api headscaleV1APIServer) GetMachine(
|
|||
return &v1.GetMachineResponse{Machine: machine.toProto()}, nil
|
||||
}
|
||||
|
||||
func (api headscaleV1APIServer) UpdateMachine(
|
||||
ctx context.Context,
|
||||
request *v1.UpdateMachineRequest,
|
||||
) (*v1.UpdateMachineResponse, error) {
|
||||
rMachine := request.GetMachine()
|
||||
machine, err := api.h.GetMachineByID(rMachine.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
machine.ForcedTags = rMachine.ForcedTags
|
||||
machine.Name = rMachine.Name
|
||||
id, err := strconv.Atoi(rMachine.Namespace.Id)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to convert namespace id to integer: %w", err)
|
||||
}
|
||||
machine.NamespaceID = uint(id)
|
||||
|
||||
err = api.h.UpdateDBMachine(*machine)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
machine, err = api.h.GetMachineByID(rMachine.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &v1.UpdateMachineResponse{Machine: machine.toProto()}, nil
|
||||
}
|
||||
|
||||
func (api headscaleV1APIServer) DeleteMachine(
|
||||
ctx context.Context,
|
||||
request *v1.DeleteMachineRequest,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue