mirror of
https://github.com/juanfont/headscale.git
synced 2026-03-19 20:53:57 +09:00
hscontrol: allow CreatePreAuthKey without user when tags provided
Handle case where user is 0 in gRPC layer to support tags-only auth keys.
This commit is contained in:
committed by
Kristoffer Dalby
parent
4dd1b49a35
commit
c8c3c9d4a0
@@ -160,7 +160,7 @@ func (hsdb *HSDatabase) ListPreAuthKeys() ([]types.PreAuthKey, error) {
|
||||
})
|
||||
}
|
||||
|
||||
// ListPreAuthKeys returns the list of PreAuthKeys for a user.
|
||||
// ListPreAuthKeys returns all PreAuthKeys in the database.
|
||||
func ListPreAuthKeys(tx *gorm.DB) ([]types.PreAuthKey, error) {
|
||||
var keys []types.PreAuthKey
|
||||
|
||||
|
||||
@@ -161,13 +161,17 @@ func (api headscaleV1APIServer) CreatePreAuthKey(
|
||||
}
|
||||
}
|
||||
|
||||
user, err := api.h.state.GetUserByID(types.UserID(request.GetUser()))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
var userID *types.UserID
|
||||
if request.GetUser() != 0 {
|
||||
user, err := api.h.state.GetUserByID(types.UserID(request.GetUser()))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
userID = user.TypedID()
|
||||
}
|
||||
|
||||
preAuthKey, err := api.h.state.CreatePreAuthKey(
|
||||
user.TypedID(),
|
||||
userID,
|
||||
request.GetReusable(),
|
||||
request.GetEphemeral(),
|
||||
&expiration,
|
||||
|
||||
Reference in New Issue
Block a user