diff --git a/acls.go b/acls.go index 014d1bd9..169f08b3 100644 --- a/acls.go +++ b/acls.go @@ -129,63 +129,62 @@ func (h *Headscale) ListACLPolicy() (*ACLPolicy, error) { } func ACLProtoToStruct(v *v1.ACLPolicy) (*ACLPolicy, error) { - // v := req.GetPolicy() // groups parsing vgroups := v.GetGroups() groups := make(map[string][]string, len(vgroups)) - for n,i := range vgroups { + for n, i := range vgroups { groups[n] = i.GetGroup() } // hosts parsing - vhosts := v.GetHosts() + vhosts := v.GetHosts() hosts := make(map[string]netaddr.IPPrefix, len(vhosts)) - for n,i := range vhosts { + for n, i := range vhosts { addr, err := netaddr.ParseIPPrefix(i) if err != nil { - return nil, err + return nil, err } - hosts[n] = addr + hosts[n] = addr } // tag owners parsing vtagowners := v.GetTagOwners() tagowners := make(map[string][]string, len(vtagowners)) - for n,i := range vtagowners { + for n, i := range vtagowners { tagowners[n] = i.GetTagOwners() } - // ACLs parsing + // ACLs parsing vacls := (*v).GetAcls() - acls := make([]ACL, len(vacls)) - for n,i := range vacls { + acls := make([]ACL, len(vacls)) + for n, i := range vacls { acls[n] = ACL{ - Action: i.GetAction(), - Protocol: i.GetProtocol(), - Sources: i.GetSources(), + Action: i.GetAction(), + Protocol: i.GetProtocol(), + Sources: i.GetSources(), Destinations: i.GetDestinations(), } } - // ACL Tests parsing + // ACL Tests parsing vtests := v.GetAclTest() tests := make([]ACLTest, len(vtests)) - for n,i := range vtests { + for n, i := range vtests { tests[n] = ACLTest{ Source: i.GetSource(), Accept: i.GetAccept(), - Deny: i.GetDeny(), + Deny: i.GetDeny(), } } - + return &ACLPolicy{ - Groups: groups, - Hosts: hosts, - TagOwners: tagowners, - ACLs: acls, - Tests: tests, + Groups: groups, + Hosts: hosts, + TagOwners: tagowners, + ACLs: acls, + Tests: tests, }, nil } @@ -240,7 +239,7 @@ func (g *Groups) toProto() map[string]*v1.Group { } protoGroups[k] = protoGroupSingle } - + return protoGroups } diff --git a/acls_test.go b/acls_test.go index 9e24f99f..e608b1e9 100644 --- a/acls_test.go +++ b/acls_test.go @@ -62,7 +62,11 @@ func (s *Suite) TestBasicRule(c *check.C) { func (s *Suite) TestInvalidAction(c *check.C) { app.aclPolicy = &ACLPolicy{ ACLs: []ACL{ - {Action: "invalidAction", Sources: []string{"*"}, Destinations: []string{"*:*"}}, + { + Action: "invalidAction", + Sources: []string{"*"}, + Destinations: []string{"*:*"}, + }, }, } err := app.UpdateACLRules() @@ -77,7 +81,11 @@ func (s *Suite) TestInvalidGroupInGroup(c *check.C) { "group:error": []string{"foo", "group:test"}, }, ACLs: []ACL{ - {Action: "accept", Sources: []string{"group:error"}, Destinations: []string{"*:*"}}, + { + Action: "accept", + Sources: []string{"group:error"}, + Destinations: []string{"*:*"}, + }, }, } err := app.UpdateACLRules() @@ -88,7 +96,11 @@ func (s *Suite) TestInvalidTagOwners(c *check.C) { // this ACL is wrong because no tagOwners own the requested tag for the server app.aclPolicy = &ACLPolicy{ ACLs: []ACL{ - {Action: "accept", Sources: []string{"tag:foo"}, Destinations: []string{"*:*"}}, + { + Action: "accept", + Sources: []string{"tag:foo"}, + Destinations: []string{"*:*"}, + }, }, } err := app.UpdateACLRules() @@ -131,7 +143,11 @@ func (s *Suite) TestValidExpandTagOwnersInSources(c *check.C) { Groups: Groups{"group:test": []string{"user1", "user2"}}, TagOwners: TagOwners{"tag:test": []string{"user3", "group:test"}}, ACLs: []ACL{ - {Action: "accept", Sources: []string{"tag:test"}, Destinations: []string{"*:*"}}, + { + Action: "accept", + Sources: []string{"tag:test"}, + Destinations: []string{"*:*"}, + }, }, } err = app.UpdateACLRules() @@ -177,7 +193,11 @@ func (s *Suite) TestValidExpandTagOwnersInDestinations(c *check.C) { Groups: Groups{"group:test": []string{"user1", "user2"}}, TagOwners: TagOwners{"tag:test": []string{"user3", "group:test"}}, ACLs: []ACL{ - {Action: "accept", Sources: []string{"*"}, Destinations: []string{"tag:test:*"}}, + { + Action: "accept", + Sources: []string{"*"}, + Destinations: []string{"tag:test:*"}, + }, }, } err = app.UpdateACLRules() @@ -222,7 +242,11 @@ func (s *Suite) TestInvalidTagValidNamespace(c *check.C) { app.aclPolicy = &ACLPolicy{ TagOwners: TagOwners{"tag:test": []string{"user1"}}, ACLs: []ACL{ - {Action: "accept", Sources: []string{"user1"}, Destinations: []string{"*:*"}}, + { + Action: "accept", + Sources: []string{"user1"}, + Destinations: []string{"*:*"}, + }, }, } err = app.UpdateACLRules() diff --git a/acls_types.go b/acls_types.go index 86649174..dffd8679 100644 --- a/acls_types.go +++ b/acls_types.go @@ -20,10 +20,10 @@ type ACLPolicy struct { // ACL is a basic rule for the ACL Policy. type ACL struct { - Action string `json:"action,omitempty" yaml:"action,omitempty"` - Protocol string `json:"proto,omitempty" yaml:"proto,omitempty"` - Sources []string `json:"src,omitempty" yaml:"src,omitempty"` - Destinations []string `json:"dst,omitempty" yaml:"dst,omitempty"` + Action string `json:"action,omitempty" yaml:"action,omitempty"` + Protocol string `json:"proto,omitempty" yaml:"proto,omitempty"` + Sources []string `json:"src,omitempty" yaml:"src,omitempty"` + Destinations []string `json:"dst,omitempty" yaml:"dst,omitempty"` } // Groups references a series of alias in the ACL rules. @@ -37,9 +37,9 @@ type TagOwners map[string][]string // ACLTest is not implemented, but should be use to check if a certain rule is allowed. type ACLTest struct { - Source string `json:"src,omitempty" yaml:"src,omitempty"` - Accept []string `json:"accept,omitempty" yaml:"accept,omitempty"` - Deny []string `json:"deny,omitempty" yaml:"deny,omitempty"` + Source string `json:"src,omitempty" yaml:"src,omitempty"` + Accept []string `json:"accept,omitempty" yaml:"accept,omitempty"` + Deny []string `json:"deny,omitempty" yaml:"deny,omitempty"` } // UnmarshalJSON allows to parse the Hosts directly into netaddr objects. diff --git a/app.go b/app.go index 953ce665..9f415024 100644 --- a/app.go +++ b/app.go @@ -766,7 +766,10 @@ func (h *Headscale) setLastStateChangeToNow(namespaces ...string) { if len(namespaces) == 0 { namespaces, err = h.ListNamespacesStr() if err != nil { - log.Error().Caller().Err(err).Msg("failed to fetch all namespaces, failing to update last changed state.") + log.Error(). + Caller(). + Err(err). + Msg("failed to fetch all namespaces, failing to update last changed state.") } } @@ -864,4 +867,4 @@ func readOrCreatePrivateKey(path string) (*key.MachinePrivate, error) { } return &machineKey, nil -} \ No newline at end of file +} diff --git a/cmd/headscale/cli/acls.go b/cmd/headscale/cli/acls.go index b7ed6c56..578761b3 100644 --- a/cmd/headscale/cli/acls.go +++ b/cmd/headscale/cli/acls.go @@ -64,7 +64,7 @@ var listAclsCmd = &cobra.Command{ output, ) - return + return } SuccessOutput( diff --git a/cmd/headscale/cli/api_key.go b/cmd/headscale/cli/api_key.go index d97cefa9..5756db48 100644 --- a/cmd/headscale/cli/api_key.go +++ b/cmd/headscale/cli/api_key.go @@ -134,7 +134,9 @@ If you loose a key, create a new one and revoke (expire) the old one.`, expiration := time.Now().UTC().Add(time.Duration(duration)) - log.Trace().Dur("expiration", time.Duration(duration)).Msg("expiration has been set") + log.Trace(). + Dur("expiration", time.Duration(duration)). + Msg("expiration has been set") request.Expiration = timestamppb.New(expiration) diff --git a/cmd/headscale/cli/preauthkeys.go b/cmd/headscale/cli/preauthkeys.go index ffa1a81d..8d8e2093 100644 --- a/cmd/headscale/cli/preauthkeys.go +++ b/cmd/headscale/cli/preauthkeys.go @@ -164,7 +164,9 @@ var createPreAuthKeyCmd = &cobra.Command{ expiration := time.Now().UTC().Add(time.Duration(duration)) - log.Trace().Dur("expiration", time.Duration(duration)).Msg("expiration has been set") + log.Trace(). + Dur("expiration", time.Duration(duration)). + Msg("expiration has been set") request.Expiration = timestamppb.New(expiration) diff --git a/cmd/headscale/cli/utils.go b/cmd/headscale/cli/utils.go index 327c8c14..747f94a0 100644 --- a/cmd/headscale/cli/utils.go +++ b/cmd/headscale/cli/utils.go @@ -24,7 +24,10 @@ const ( func getHeadscaleApp() (*headscale.Headscale, error) { cfg, err := headscale.GetHeadscaleConfig() if err != nil { - return nil, fmt.Errorf("failed to load configuration while creating headscale instance: %w", err) + return nil, fmt.Errorf( + "failed to load configuration while creating headscale instance: %w", + err, + ) } app, err := headscale.NewHeadscale(cfg) diff --git a/db.go b/db.go index 17d83237..b3222d0e 100644 --- a/db.go +++ b/db.go @@ -111,7 +111,6 @@ func (h *Headscale) initDB() error { Err(err). Msg("Failed to save normalized machine name in DB migration") } - } } } diff --git a/integration_common_test.go b/integration_common_test.go index f1c4e868..b1fdf18a 100644 --- a/integration_common_test.go +++ b/integration_common_test.go @@ -219,7 +219,6 @@ func getIPs( func getDNSNames( headscale *dockertest.Resource, ) ([]string, error) { - listAllResult, err := ExecuteCommand( headscale, []string{ @@ -253,7 +252,6 @@ func getDNSNames( func getMagicFQDN( headscale *dockertest.Resource, ) ([]string, error) { - listAllResult, err := ExecuteCommand( headscale, []string{ @@ -278,7 +276,11 @@ func getMagicFQDN( hostnames := make([]string, len(listAll)) for index := range listAll { - hostnames[index] = fmt.Sprintf("%s.%s.headscale.net", listAll[index].GetGivenName(), listAll[index].GetNamespace().GetName()) + hostnames[index] = fmt.Sprintf( + "%s.%s.headscale.net", + listAll[index].GetGivenName(), + listAll[index].GetNamespace().GetName(), + ) } return hostnames, nil diff --git a/machine_test.go b/machine_test.go index 48ccb153..530d551c 100644 --- a/machine_test.go +++ b/machine_test.go @@ -188,8 +188,16 @@ func (s *Suite) TestGetACLFilteredPeers(c *check.C) { Hosts: map[string]netaddr.IPPrefix{}, TagOwners: map[string][]string{}, ACLs: []ACL{ - {Action: "accept", Sources: []string{"admin"}, Destinations: []string{"*:*"}}, - {Action: "accept", Sources: []string{"test"}, Destinations: []string{"test:*"}}, + { + Action: "accept", + Sources: []string{"admin"}, + Destinations: []string{"*:*"}, + }, + { + Action: "accept", + Sources: []string{"test"}, + Destinations: []string{"test:*"}, + }, }, Tests: []ACLTest{}, } diff --git a/poll.go b/poll.go index 239f260b..495ef211 100644 --- a/poll.go +++ b/poll.go @@ -278,7 +278,11 @@ func (h *Headscale) PollNetMapStream( return } - ctx := context.WithValue(ctx.Request.Context(), machineNameContextKey, machine.Hostname) + ctx := context.WithValue( + ctx.Request.Context(), + machineNameContextKey, + machine.Hostname, + ) ctx, cancel := context.WithCancel(ctx) defer cancel() diff --git a/proto/headscale/v1/acls.proto b/proto/headscale/v1/acls.proto index eb075e83..c1eb7286 100644 --- a/proto/headscale/v1/acls.proto +++ b/proto/headscale/v1/acls.proto @@ -3,11 +3,11 @@ package headscale.v1; option go_package = "github.com/juanfont/headscale/gen/go/v1"; message ACLPolicy { - map groups = 1; - map hosts = 2; - map tag_owners = 3; - repeated ACL acls = 4; - repeated ACLTest acl_test = 5; + map groups = 1; + map hosts = 2; + map tag_owners = 3; + repeated ACL acls = 4; + repeated ACLTest acl_test = 5; } message Group { @@ -19,16 +19,16 @@ message TagOwners { } message ACL { - string action = 1; - string protocol = 2; - repeated string sources = 3; + string action = 1; + string protocol = 2; + repeated string sources = 3; repeated string destinations = 4; } message ACLTest { - string source = 1; + string source = 1; repeated string accept = 2; - repeated string deny = 3; + repeated string deny = 3; } message ListACLPolicyRequest { diff --git a/routes_test.go b/routes_test.go index 0108d888..89b712b5 100644 --- a/routes_test.go +++ b/routes_test.go @@ -28,7 +28,7 @@ func (s *Suite) TestGetRoutes(c *check.C) { MachineKey: "foo", NodeKey: "bar", DiscoKey: "faa", - Hostname: "test_get_route_machine", + Hostname: "test_get_route_machine", NamespaceID: namespace.ID, RegisterMethod: RegisterMethodAuthKey, AuthKeyID: uint(pak.ID), @@ -79,7 +79,7 @@ func (s *Suite) TestGetEnableRoutes(c *check.C) { MachineKey: "foo", NodeKey: "bar", DiscoKey: "faa", - Hostname: "test_enable_route_machine", + Hostname: "test_enable_route_machine", NamespaceID: namespace.ID, RegisterMethod: RegisterMethodAuthKey, AuthKeyID: uint(pak.ID), diff --git a/utils.go b/utils.go index fd4cda86..b79d86f5 100644 --- a/utils.go +++ b/utils.go @@ -332,7 +332,9 @@ func GenerateRandomStringDNSSafe(n int) (string, error) { if err != nil { return "", err } - str = strings.ToLower(strings.ReplaceAll(strings.ReplaceAll(str, "_", ""), "-", "")) + str = strings.ToLower( + strings.ReplaceAll(strings.ReplaceAll(str, "_", ""), "-", ""), + ) } return str[:n], nil