Implement new machine register parameter

This commit is contained in:
Kristoffer Dalby 2022-02-28 16:34:50 +00:00
parent 402a76070f
commit 54cc3c067f
3 changed files with 18 additions and 14 deletions

21
api.go
View File

@ -154,6 +154,7 @@ func (h *Headscale) RegistrationHandler(ctx *gin.Context) {
)
h.handleMachineRegistrationNew(ctx, machineKey, req)
return
}
@ -573,15 +574,19 @@ func (h *Headscale) handleAuthKey(
nodeKey := NodePublicKeyStripPrefix(registerRequest.NodeKey)
now := time.Now().UTC()
machineToRegister := Machine{
Name: registerRequest.Hostinfo.Hostname,
NamespaceID: pak.Namespace.ID,
MachineKey: machineKeyStr,
RegisterMethod: RegisterMethodAuthKey,
Expiry: &registerRequest.Expiry,
NodeKey: nodeKey,
LastSeen: &now,
AuthKeyID: uint(pak.ID),
}
machine, err := h.RegisterMachine(
registerRequest.Hostinfo.Hostname,
machineKeyStr,
pak.Namespace.Name,
RegisterMethodAuthKey,
&registerRequest.Expiry,
pak,
&nodeKey,
&now,
machineToRegister,
)
if err != nil {
log.Error().

View File

@ -415,11 +415,11 @@ func (api headscaleV1APIServer) DebugCreateMachine(
HostInfo: datatypes.JSON(hostinfoJson),
}
// log.Trace().Caller().Interface("machine", newMachine).Msg("")
if err := api.h.db.Create(&newMachine).Error; err != nil {
return nil, err
}
api.h.registrationCache.Set(
request.GetKey(),
newMachine,
requestedExpiryCacheExpiration,
)
return &v1.DebugCreateMachineResponse{Machine: newMachine.toProto()}, nil
}

View File

@ -344,7 +344,6 @@ func (h *Headscale) OIDCCallback(ctx *gin.Context) {
return
}
}
var content bytes.Buffer