mirror of
https://github.com/juanfont/headscale.git
synced 2026-04-18 06:50:16 +02:00
all: apply golangci-lint 2.9.0 fixes
Fix issues found by the upgraded golangci-lint: - wsl_v5: add required whitespace in CLI files - staticcheck SA4006: replace new(var.Field) with &localVar pattern since staticcheck does not recognize Go 1.26 new(value) as a use of the variable - staticcheck SA5011: use t.Fatal instead of t.Error for nil guard checks so execution stops - unused: remove dead ptrTo helper function
This commit is contained in:
@@ -71,6 +71,7 @@ var listAPIKeys = &cobra.Command{
|
|||||||
tableData := pterm.TableData{
|
tableData := pterm.TableData{
|
||||||
{"ID", "Prefix", "Expiration", "Created"},
|
{"ID", "Prefix", "Expiration", "Created"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, key := range response.GetApiKeys() {
|
for _, key := range response.GetApiKeys() {
|
||||||
expiration := "-"
|
expiration := "-"
|
||||||
|
|
||||||
@@ -84,8 +85,8 @@ var listAPIKeys = &cobra.Command{
|
|||||||
expiration,
|
expiration,
|
||||||
key.GetCreatedAt().AsTime().Format(HeadscaleDateTimeFormat),
|
key.GetCreatedAt().AsTime().Format(HeadscaleDateTimeFormat),
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render()
|
err = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ErrorOutput(
|
ErrorOutput(
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ var healthCmd = &cobra.Command{
|
|||||||
Long: "Check the health of the Headscale server. This command will return an exit code of 0 if the server is healthy, or 1 if it is not.",
|
Long: "Check the health of the Headscale server. This command will return an exit code of 0 if the server is healthy, or 1 if it is not.",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
output, _ := cmd.Flags().GetString("output")
|
output, _ := cmd.Flags().GetString("output")
|
||||||
|
|
||||||
ctx, client, conn, cancel := newHeadscaleCLIWithConfig()
|
ctx, client, conn, cancel := newHeadscaleCLIWithConfig()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ var registerNodeCmd = &cobra.Command{
|
|||||||
Short: "Registers a node to your network",
|
Short: "Registers a node to your network",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
output, _ := cmd.Flags().GetString("output")
|
output, _ := cmd.Flags().GetString("output")
|
||||||
|
|
||||||
user, err := cmd.Flags().GetString("user")
|
user, err := cmd.Flags().GetString("user")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ErrorOutput(err, fmt.Sprintf("Error getting user: %s", err), output)
|
ErrorOutput(err, fmt.Sprintf("Error getting user: %s", err), output)
|
||||||
@@ -152,6 +153,7 @@ var listNodesCmd = &cobra.Command{
|
|||||||
Aliases: []string{"ls", "show"},
|
Aliases: []string{"ls", "show"},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
output, _ := cmd.Flags().GetString("output")
|
output, _ := cmd.Flags().GetString("output")
|
||||||
|
|
||||||
user, err := cmd.Flags().GetString("user")
|
user, err := cmd.Flags().GetString("user")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ErrorOutput(err, fmt.Sprintf("Error getting user: %s", err), output)
|
ErrorOutput(err, fmt.Sprintf("Error getting user: %s", err), output)
|
||||||
@@ -200,6 +202,7 @@ var listNodeRoutesCmd = &cobra.Command{
|
|||||||
Aliases: []string{"lsr", "routes"},
|
Aliases: []string{"lsr", "routes"},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
output, _ := cmd.Flags().GetString("output")
|
output, _ := cmd.Flags().GetString("output")
|
||||||
|
|
||||||
identifier, err := cmd.Flags().GetUint64("identifier")
|
identifier, err := cmd.Flags().GetUint64("identifier")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ErrorOutput(
|
ErrorOutput(
|
||||||
@@ -283,7 +286,9 @@ var expireNodeCmd = &cobra.Command{
|
|||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
expiryTime := now
|
expiryTime := now
|
||||||
if expiry != "" {
|
if expiry != "" {
|
||||||
expiryTime, err = time.Parse(time.RFC3339, expiry)
|
expiryTime, err = time.Parse(time.RFC3339, expiry)
|
||||||
@@ -350,6 +355,7 @@ var renameNodeCmd = &cobra.Command{
|
|||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
newName = args[0]
|
newName = args[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
request := &v1.RenameNodeRequest{
|
request := &v1.RenameNodeRequest{
|
||||||
NodeId: identifier,
|
NodeId: identifier,
|
||||||
NewName: newName,
|
NewName: newName,
|
||||||
@@ -409,6 +415,7 @@ var deleteNodeCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
confirm := false
|
confirm := false
|
||||||
|
|
||||||
force, _ := cmd.Flags().GetBool("force")
|
force, _ := cmd.Flags().GetBool("force")
|
||||||
if !force {
|
if !force {
|
||||||
confirm = util.YesNo(fmt.Sprintf(
|
confirm = util.YesNo(fmt.Sprintf(
|
||||||
@@ -424,6 +431,7 @@ var deleteNodeCmd = &cobra.Command{
|
|||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ErrorOutput(
|
ErrorOutput(
|
||||||
err,
|
err,
|
||||||
@@ -431,6 +439,7 @@ var deleteNodeCmd = &cobra.Command{
|
|||||||
output,
|
output,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
SuccessOutput(
|
SuccessOutput(
|
||||||
map[string]string{"Result": "Node deleted"},
|
map[string]string{"Result": "Node deleted"},
|
||||||
"Node deleted",
|
"Node deleted",
|
||||||
@@ -659,6 +668,7 @@ var tagCmd = &cobra.Command{
|
|||||||
Aliases: []string{"tags", "t"},
|
Aliases: []string{"tags", "t"},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
output, _ := cmd.Flags().GetString("output")
|
output, _ := cmd.Flags().GetString("output")
|
||||||
|
|
||||||
ctx, client, conn, cancel := newHeadscaleCLIWithConfig()
|
ctx, client, conn, cancel := newHeadscaleCLIWithConfig()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
@@ -672,6 +682,7 @@ var tagCmd = &cobra.Command{
|
|||||||
output,
|
output,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
tagsToSet, err := cmd.Flags().GetStringSlice("tags")
|
tagsToSet, err := cmd.Flags().GetStringSlice("tags")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ErrorOutput(
|
ErrorOutput(
|
||||||
@@ -686,6 +697,7 @@ var tagCmd = &cobra.Command{
|
|||||||
NodeId: identifier,
|
NodeId: identifier,
|
||||||
Tags: tagsToSet,
|
Tags: tagsToSet,
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := client.SetTags(ctx, request)
|
resp, err := client.SetTags(ctx, request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ErrorOutput(
|
ErrorOutput(
|
||||||
@@ -710,6 +722,7 @@ var approveRoutesCmd = &cobra.Command{
|
|||||||
Short: "Manage the approved routes of a node",
|
Short: "Manage the approved routes of a node",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
output, _ := cmd.Flags().GetString("output")
|
output, _ := cmd.Flags().GetString("output")
|
||||||
|
|
||||||
ctx, client, conn, cancel := newHeadscaleCLIWithConfig()
|
ctx, client, conn, cancel := newHeadscaleCLIWithConfig()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
@@ -723,6 +736,7 @@ var approveRoutesCmd = &cobra.Command{
|
|||||||
output,
|
output,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
routes, err := cmd.Flags().GetStringSlice("routes")
|
routes, err := cmd.Flags().GetStringSlice("routes")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ErrorOutput(
|
ErrorOutput(
|
||||||
@@ -737,6 +751,7 @@ var approveRoutesCmd = &cobra.Command{
|
|||||||
NodeId: identifier,
|
NodeId: identifier,
|
||||||
Routes: routes,
|
Routes: routes,
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := client.SetApprovedRoutes(ctx, request)
|
resp, err := client.SetApprovedRoutes(ctx, request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ErrorOutput(
|
ErrorOutput(
|
||||||
|
|||||||
@@ -56,9 +56,12 @@ var getPolicy = &cobra.Command{
|
|||||||
Aliases: []string{"show", "view", "fetch"},
|
Aliases: []string{"show", "view", "fetch"},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
output, _ := cmd.Flags().GetString("output")
|
output, _ := cmd.Flags().GetString("output")
|
||||||
|
|
||||||
var policy string
|
var policy string
|
||||||
|
|
||||||
if bypass, _ := cmd.Flags().GetBool(bypassFlag); bypass {
|
if bypass, _ := cmd.Flags().GetBool(bypassFlag); bypass {
|
||||||
confirm := false
|
confirm := false
|
||||||
|
|
||||||
force, _ := cmd.Flags().GetBool("force")
|
force, _ := cmd.Flags().GetBool("force")
|
||||||
if !force {
|
if !force {
|
||||||
confirm = util.YesNo("DO NOT run this command if an instance of headscale is running, are you sure headscale is not running?")
|
confirm = util.YesNo("DO NOT run this command if an instance of headscale is running, are you sure headscale is not running?")
|
||||||
@@ -134,6 +137,7 @@ var setPolicy = &cobra.Command{
|
|||||||
|
|
||||||
if bypass, _ := cmd.Flags().GetBool(bypassFlag); bypass {
|
if bypass, _ := cmd.Flags().GetBool(bypassFlag); bypass {
|
||||||
confirm := false
|
confirm := false
|
||||||
|
|
||||||
force, _ := cmd.Flags().GetBool("force")
|
force, _ := cmd.Flags().GetBool("force")
|
||||||
if !force {
|
if !force {
|
||||||
confirm = util.YesNo("DO NOT run this command if an instance of headscale is running, are you sure headscale is not running?")
|
confirm = util.YesNo("DO NOT run this command if an instance of headscale is running, are you sure headscale is not running?")
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ var listPreAuthKeys = &cobra.Command{
|
|||||||
"Owner",
|
"Owner",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, key := range response.GetPreAuthKeys() {
|
for _, key := range response.GetPreAuthKeys() {
|
||||||
expiration := "-"
|
expiration := "-"
|
||||||
if key.GetExpiration() != nil {
|
if key.GetExpiration() != nil {
|
||||||
@@ -105,8 +106,8 @@ var listPreAuthKeys = &cobra.Command{
|
|||||||
key.GetCreatedAt().AsTime().Format("2006-01-02 15:04:05"),
|
key.GetCreatedAt().AsTime().Format("2006-01-02 15:04:05"),
|
||||||
owner,
|
owner,
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render()
|
err = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ErrorOutput(
|
ErrorOutput(
|
||||||
|
|||||||
@@ -112,10 +112,12 @@ var createUserCmd = &cobra.Command{
|
|||||||
output,
|
output,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
request.PictureUrl = pictureURL
|
request.PictureUrl = pictureURL
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Trace().Interface(zf.Request, request).Msg("sending CreateUser request")
|
log.Trace().Interface(zf.Request, request).Msg("sending CreateUser request")
|
||||||
|
|
||||||
response, err := client.CreateUser(ctx, request)
|
response, err := client.CreateUser(ctx, request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ErrorOutput(
|
ErrorOutput(
|
||||||
@@ -167,6 +169,7 @@ var destroyUserCmd = &cobra.Command{
|
|||||||
user := users.GetUsers()[0]
|
user := users.GetUsers()[0]
|
||||||
|
|
||||||
confirm := false
|
confirm := false
|
||||||
|
|
||||||
force, _ := cmd.Flags().GetBool("force")
|
force, _ := cmd.Flags().GetBool("force")
|
||||||
if !force {
|
if !force {
|
||||||
confirm = util.YesNo(fmt.Sprintf(
|
confirm = util.YesNo(fmt.Sprintf(
|
||||||
@@ -186,6 +189,7 @@ var destroyUserCmd = &cobra.Command{
|
|||||||
output,
|
output,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
SuccessOutput(response, "User destroyed", output)
|
SuccessOutput(response, "User destroyed", output)
|
||||||
} else {
|
} else {
|
||||||
SuccessOutput(map[string]string{"Result": "User not destroyed"}, "User not destroyed", output)
|
SuccessOutput(map[string]string{"Result": "User not destroyed"}, "User not destroyed", output)
|
||||||
@@ -246,6 +250,7 @@ var listUsersCmd = &cobra.Command{
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render()
|
err = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ErrorOutput(
|
ErrorOutput(
|
||||||
|
|||||||
@@ -682,6 +682,7 @@ func (hsdb *HSDatabase) CreateNodeForTest(user *types.User, hostname ...string)
|
|||||||
panic(fmt.Sprintf("failed to create preauth key for test node: %v", err))
|
panic(fmt.Sprintf("failed to create preauth key for test node: %v", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pakID := pak.ID
|
||||||
nodeKey := key.NewNode()
|
nodeKey := key.NewNode()
|
||||||
machineKey := key.NewMachine()
|
machineKey := key.NewMachine()
|
||||||
discoKey := key.NewDisco()
|
discoKey := key.NewDisco()
|
||||||
@@ -693,7 +694,7 @@ func (hsdb *HSDatabase) CreateNodeForTest(user *types.User, hostname ...string)
|
|||||||
Hostname: nodeName,
|
Hostname: nodeName,
|
||||||
UserID: &user.ID,
|
UserID: &user.ID,
|
||||||
RegisterMethod: util.RegisterMethodAuthKey,
|
RegisterMethod: util.RegisterMethodAuthKey,
|
||||||
AuthKeyID: new(pak.ID),
|
AuthKeyID: &pakID,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = hsdb.DB.Save(node).Error
|
err = hsdb.DB.Save(node).Error
|
||||||
|
|||||||
@@ -101,6 +101,8 @@ func TestExpireNode(t *testing.T) {
|
|||||||
pak, err := db.CreatePreAuthKey(user.TypedID(), false, false, nil, nil)
|
pak, err := db.CreatePreAuthKey(user.TypedID(), false, false, nil, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
pakID := pak.ID
|
||||||
|
|
||||||
_, err = db.getNode(types.UserID(user.ID), "testnode")
|
_, err = db.getNode(types.UserID(user.ID), "testnode")
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
@@ -114,7 +116,7 @@ func TestExpireNode(t *testing.T) {
|
|||||||
Hostname: "testnode",
|
Hostname: "testnode",
|
||||||
UserID: &user.ID,
|
UserID: &user.ID,
|
||||||
RegisterMethod: util.RegisterMethodAuthKey,
|
RegisterMethod: util.RegisterMethodAuthKey,
|
||||||
AuthKeyID: new(pak.ID),
|
AuthKeyID: &pakID,
|
||||||
Expiry: &time.Time{},
|
Expiry: &time.Time{},
|
||||||
}
|
}
|
||||||
db.DB.Save(node)
|
db.DB.Save(node)
|
||||||
@@ -145,6 +147,8 @@ func TestSetTags(t *testing.T) {
|
|||||||
pak, err := db.CreatePreAuthKey(user.TypedID(), false, false, nil, nil)
|
pak, err := db.CreatePreAuthKey(user.TypedID(), false, false, nil, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
pakID := pak.ID
|
||||||
|
|
||||||
_, err = db.getNode(types.UserID(user.ID), "testnode")
|
_, err = db.getNode(types.UserID(user.ID), "testnode")
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
@@ -158,7 +162,7 @@ func TestSetTags(t *testing.T) {
|
|||||||
Hostname: "testnode",
|
Hostname: "testnode",
|
||||||
UserID: &user.ID,
|
UserID: &user.ID,
|
||||||
RegisterMethod: util.RegisterMethodAuthKey,
|
RegisterMethod: util.RegisterMethodAuthKey,
|
||||||
AuthKeyID: new(pak.ID),
|
AuthKeyID: &pakID,
|
||||||
}
|
}
|
||||||
|
|
||||||
trx := db.DB.Save(node)
|
trx := db.DB.Save(node)
|
||||||
@@ -652,6 +656,9 @@ func TestListEphemeralNodes(t *testing.T) {
|
|||||||
pakEph, err := db.CreatePreAuthKey(user.TypedID(), false, true, nil, nil)
|
pakEph, err := db.CreatePreAuthKey(user.TypedID(), false, true, nil, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
pakID := pak.ID
|
||||||
|
pakEphID := pakEph.ID
|
||||||
|
|
||||||
node := types.Node{
|
node := types.Node{
|
||||||
ID: 0,
|
ID: 0,
|
||||||
MachineKey: key.NewMachine().Public(),
|
MachineKey: key.NewMachine().Public(),
|
||||||
@@ -659,7 +666,7 @@ func TestListEphemeralNodes(t *testing.T) {
|
|||||||
Hostname: "test",
|
Hostname: "test",
|
||||||
UserID: &user.ID,
|
UserID: &user.ID,
|
||||||
RegisterMethod: util.RegisterMethodAuthKey,
|
RegisterMethod: util.RegisterMethodAuthKey,
|
||||||
AuthKeyID: new(pak.ID),
|
AuthKeyID: &pakID,
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeEph := types.Node{
|
nodeEph := types.Node{
|
||||||
@@ -669,7 +676,7 @@ func TestListEphemeralNodes(t *testing.T) {
|
|||||||
Hostname: "ephemeral",
|
Hostname: "ephemeral",
|
||||||
UserID: &user.ID,
|
UserID: &user.ID,
|
||||||
RegisterMethod: util.RegisterMethodAuthKey,
|
RegisterMethod: util.RegisterMethodAuthKey,
|
||||||
AuthKeyID: new(pakEph.ID),
|
AuthKeyID: &pakEphID,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = db.DB.Save(&node).Error
|
err = db.DB.Save(&node).Error
|
||||||
|
|||||||
@@ -73,12 +73,14 @@ func TestDestroyUserErrors(t *testing.T) {
|
|||||||
pak, err := db.CreatePreAuthKey(user.TypedID(), false, false, nil, nil)
|
pak, err := db.CreatePreAuthKey(user.TypedID(), false, false, nil, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
pakID := pak.ID
|
||||||
|
|
||||||
node := types.Node{
|
node := types.Node{
|
||||||
ID: 0,
|
ID: 0,
|
||||||
Hostname: "testnode",
|
Hostname: "testnode",
|
||||||
UserID: &user.ID,
|
UserID: &user.ID,
|
||||||
RegisterMethod: util.RegisterMethodAuthKey,
|
RegisterMethod: util.RegisterMethodAuthKey,
|
||||||
AuthKeyID: new(pak.ID),
|
AuthKeyID: &pakID,
|
||||||
}
|
}
|
||||||
trx := db.DB.Save(&node)
|
trx := db.DB.Save(&node)
|
||||||
require.NoError(t, trx.Error)
|
require.NoError(t, trx.Error)
|
||||||
|
|||||||
@@ -330,6 +330,8 @@ func TestApproveRoutesWithPolicy_NilPolicyManagerCase(t *testing.T) {
|
|||||||
Name: "test",
|
Name: "test",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
userID := user.ID
|
||||||
|
|
||||||
currentApproved := []netip.Prefix{
|
currentApproved := []netip.Prefix{
|
||||||
netip.MustParsePrefix("10.0.0.0/24"),
|
netip.MustParsePrefix("10.0.0.0/24"),
|
||||||
}
|
}
|
||||||
@@ -342,8 +344,8 @@ func TestApproveRoutesWithPolicy_NilPolicyManagerCase(t *testing.T) {
|
|||||||
MachineKey: key.NewMachine().Public(),
|
MachineKey: key.NewMachine().Public(),
|
||||||
NodeKey: key.NewNode().Public(),
|
NodeKey: key.NewNode().Public(),
|
||||||
Hostname: "testnode",
|
Hostname: "testnode",
|
||||||
UserID: new(user.ID),
|
UserID: &userID,
|
||||||
User: new(user),
|
User: &user,
|
||||||
RegisterMethod: util.RegisterMethodAuthKey,
|
RegisterMethod: util.RegisterMethodAuthKey,
|
||||||
Hostinfo: &tailcfg.Hostinfo{
|
Hostinfo: &tailcfg.Hostinfo{
|
||||||
RoutableIPs: announcedRoutes,
|
RoutableIPs: announcedRoutes,
|
||||||
|
|||||||
@@ -502,10 +502,9 @@ func (s *State) Connect(id types.NodeID) []change.Change {
|
|||||||
|
|
||||||
// Disconnect marks a node as disconnected and updates its primary routes in the state.
|
// Disconnect marks a node as disconnected and updates its primary routes in the state.
|
||||||
func (s *State) Disconnect(id types.NodeID) ([]change.Change, error) {
|
func (s *State) Disconnect(id types.NodeID) ([]change.Change, error) {
|
||||||
now := time.Now()
|
|
||||||
|
|
||||||
node, ok := s.nodeStore.UpdateNode(id, func(n *types.Node) {
|
node, ok := s.nodeStore.UpdateNode(id, func(n *types.Node) {
|
||||||
n.LastSeen = new(now)
|
now := time.Now()
|
||||||
|
n.LastSeen = &now
|
||||||
// NodeStore is the source of truth for all node state including online status.
|
// NodeStore is the source of truth for all node state including online status.
|
||||||
n.IsOnline = new(false)
|
n.IsOnline = new(false)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -365,11 +365,6 @@ func KeyExpiry(nodeID types.NodeID, expiry *time.Time) Change {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ptrTo returns a pointer to the given value.
|
|
||||||
func ptrTo[T any](v T) *T {
|
|
||||||
return new(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
// High-level change constructors
|
// High-level change constructors
|
||||||
|
|
||||||
// NodeAdded returns a Change for when a node is added or updated.
|
// NodeAdded returns a Change for when a node is added or updated.
|
||||||
|
|||||||
@@ -1207,10 +1207,10 @@ func TestEnsureHostnameWithHostinfo(t *testing.T) {
|
|||||||
wantHostname: "test",
|
wantHostname: "test",
|
||||||
checkHostinfo: func(t *testing.T, hi *tailcfg.Hostinfo) { //nolint:thelper
|
checkHostinfo: func(t *testing.T, hi *tailcfg.Hostinfo) { //nolint:thelper
|
||||||
if hi == nil {
|
if hi == nil {
|
||||||
t.Error("hostinfo should not be nil")
|
t.Fatal("hostinfo should not be nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if hi.Hostname != "test" { //nolint:staticcheck // SA5011: nil check is above
|
if hi.Hostname != "test" {
|
||||||
t.Errorf("hostname = %v, want test", hi.Hostname)
|
t.Errorf("hostname = %v, want test", hi.Hostname)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1241,10 +1241,10 @@ func TestEnsureHostnameWithHostinfo(t *testing.T) {
|
|||||||
wantHostname: "123456789012345678901234567890123456789012345678901234567890123",
|
wantHostname: "123456789012345678901234567890123456789012345678901234567890123",
|
||||||
checkHostinfo: func(t *testing.T, hi *tailcfg.Hostinfo) { //nolint:thelper
|
checkHostinfo: func(t *testing.T, hi *tailcfg.Hostinfo) { //nolint:thelper
|
||||||
if hi == nil {
|
if hi == nil {
|
||||||
t.Error("hostinfo should not be nil")
|
t.Fatal("hostinfo should not be nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(hi.Hostname) != 63 { //nolint:staticcheck // SA5011: nil check is above
|
if len(hi.Hostname) != 63 {
|
||||||
t.Errorf("hostname length = %v, want 63", len(hi.Hostname))
|
t.Errorf("hostname length = %v, want 63", len(hi.Hostname))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -929,8 +929,8 @@ func tagp(name string) policyv2.Alias {
|
|||||||
// prefixp returns a pointer to a Prefix from a CIDR string for policy v2 configurations.
|
// prefixp returns a pointer to a Prefix from a CIDR string for policy v2 configurations.
|
||||||
// Converts CIDR notation to policy prefix format for network range specifications.
|
// Converts CIDR notation to policy prefix format for network range specifications.
|
||||||
func prefixp(cidr string) policyv2.Alias {
|
func prefixp(cidr string) policyv2.Alias {
|
||||||
prefix := netip.MustParsePrefix(cidr)
|
p := policyv2.Prefix(netip.MustParsePrefix(cidr))
|
||||||
return new(policyv2.Prefix(prefix))
|
return &p
|
||||||
}
|
}
|
||||||
|
|
||||||
// aliasWithPorts creates an AliasWithPorts structure from an alias and port ranges.
|
// aliasWithPorts creates an AliasWithPorts structure from an alias and port ranges.
|
||||||
|
|||||||
@@ -1485,6 +1485,7 @@ func (s *Scenario) runMockOIDC(accessTTL time.Duration, users []mockoidc.MockUse
|
|||||||
httpClient := &http.Client{}
|
httpClient := &http.Client{}
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
req, _ := http.NewRequestWithContext(ctx, http.MethodGet, oidcConfigURL, nil)
|
req, _ := http.NewRequestWithContext(ctx, http.MethodGet, oidcConfigURL, nil)
|
||||||
|
|
||||||
resp, err := httpClient.Do(req)
|
resp, err := httpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("headscale mock OIDC tests is not ready: %s\n", err)
|
log.Printf("headscale mock OIDC tests is not ready: %s\n", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user