mirror of
https://github.com/juanfont/headscale.git
synced 2025-09-20 17:53:11 +02:00
linting
This commit is contained in:
parent
c308e21c70
commit
85e4dd684d
11
acls.go
11
acls.go
@ -129,20 +129,19 @@ func (h *Headscale) ListACLPolicy() (*ACLPolicy, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ACLProtoToStruct(v *v1.ACLPolicy) (*ACLPolicy, error) {
|
func ACLProtoToStruct(v *v1.ACLPolicy) (*ACLPolicy, error) {
|
||||||
|
|
||||||
// v := req.GetPolicy()
|
// v := req.GetPolicy()
|
||||||
|
|
||||||
// groups parsing
|
// groups parsing
|
||||||
vgroups := v.GetGroups()
|
vgroups := v.GetGroups()
|
||||||
groups := make(map[string][]string, len(vgroups))
|
groups := make(map[string][]string, len(vgroups))
|
||||||
for n,i := range vgroups {
|
for n, i := range vgroups {
|
||||||
groups[n] = i.GetGroup()
|
groups[n] = i.GetGroup()
|
||||||
}
|
}
|
||||||
|
|
||||||
// hosts parsing
|
// hosts parsing
|
||||||
vhosts := v.GetHosts()
|
vhosts := v.GetHosts()
|
||||||
hosts := make(map[string]netaddr.IPPrefix, len(vhosts))
|
hosts := make(map[string]netaddr.IPPrefix, len(vhosts))
|
||||||
for n,i := range vhosts {
|
for n, i := range vhosts {
|
||||||
addr, err := netaddr.ParseIPPrefix(i)
|
addr, err := netaddr.ParseIPPrefix(i)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -153,14 +152,14 @@ func ACLProtoToStruct(v *v1.ACLPolicy) (*ACLPolicy, error) {
|
|||||||
// tag owners parsing
|
// tag owners parsing
|
||||||
vtagowners := v.GetTagOwners()
|
vtagowners := v.GetTagOwners()
|
||||||
tagowners := make(map[string][]string, len(vtagowners))
|
tagowners := make(map[string][]string, len(vtagowners))
|
||||||
for n,i := range vtagowners {
|
for n, i := range vtagowners {
|
||||||
tagowners[n] = i.GetTagOwners()
|
tagowners[n] = i.GetTagOwners()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ACLs parsing
|
// ACLs parsing
|
||||||
vacls := (*v).GetAcls()
|
vacls := (*v).GetAcls()
|
||||||
acls := make([]ACL, len(vacls))
|
acls := make([]ACL, len(vacls))
|
||||||
for n,i := range vacls {
|
for n, i := range vacls {
|
||||||
acls[n] = ACL{
|
acls[n] = ACL{
|
||||||
Action: i.GetAction(),
|
Action: i.GetAction(),
|
||||||
Protocol: i.GetProtocol(),
|
Protocol: i.GetProtocol(),
|
||||||
@ -172,7 +171,7 @@ func ACLProtoToStruct(v *v1.ACLPolicy) (*ACLPolicy, error) {
|
|||||||
// ACL Tests parsing
|
// ACL Tests parsing
|
||||||
vtests := v.GetAclTest()
|
vtests := v.GetAclTest()
|
||||||
tests := make([]ACLTest, len(vtests))
|
tests := make([]ACLTest, len(vtests))
|
||||||
for n,i := range vtests {
|
for n, i := range vtests {
|
||||||
tests[n] = ACLTest{
|
tests[n] = ACLTest{
|
||||||
Source: i.GetSource(),
|
Source: i.GetSource(),
|
||||||
Accept: i.GetAccept(),
|
Accept: i.GetAccept(),
|
||||||
|
36
acls_test.go
36
acls_test.go
@ -62,7 +62,11 @@ func (s *Suite) TestBasicRule(c *check.C) {
|
|||||||
func (s *Suite) TestInvalidAction(c *check.C) {
|
func (s *Suite) TestInvalidAction(c *check.C) {
|
||||||
app.aclPolicy = &ACLPolicy{
|
app.aclPolicy = &ACLPolicy{
|
||||||
ACLs: []ACL{
|
ACLs: []ACL{
|
||||||
{Action: "invalidAction", Sources: []string{"*"}, Destinations: []string{"*:*"}},
|
{
|
||||||
|
Action: "invalidAction",
|
||||||
|
Sources: []string{"*"},
|
||||||
|
Destinations: []string{"*:*"},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
err := app.UpdateACLRules()
|
err := app.UpdateACLRules()
|
||||||
@ -77,7 +81,11 @@ func (s *Suite) TestInvalidGroupInGroup(c *check.C) {
|
|||||||
"group:error": []string{"foo", "group:test"},
|
"group:error": []string{"foo", "group:test"},
|
||||||
},
|
},
|
||||||
ACLs: []ACL{
|
ACLs: []ACL{
|
||||||
{Action: "accept", Sources: []string{"group:error"}, Destinations: []string{"*:*"}},
|
{
|
||||||
|
Action: "accept",
|
||||||
|
Sources: []string{"group:error"},
|
||||||
|
Destinations: []string{"*:*"},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
err := app.UpdateACLRules()
|
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
|
// this ACL is wrong because no tagOwners own the requested tag for the server
|
||||||
app.aclPolicy = &ACLPolicy{
|
app.aclPolicy = &ACLPolicy{
|
||||||
ACLs: []ACL{
|
ACLs: []ACL{
|
||||||
{Action: "accept", Sources: []string{"tag:foo"}, Destinations: []string{"*:*"}},
|
{
|
||||||
|
Action: "accept",
|
||||||
|
Sources: []string{"tag:foo"},
|
||||||
|
Destinations: []string{"*:*"},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
err := app.UpdateACLRules()
|
err := app.UpdateACLRules()
|
||||||
@ -131,7 +143,11 @@ func (s *Suite) TestValidExpandTagOwnersInSources(c *check.C) {
|
|||||||
Groups: Groups{"group:test": []string{"user1", "user2"}},
|
Groups: Groups{"group:test": []string{"user1", "user2"}},
|
||||||
TagOwners: TagOwners{"tag:test": []string{"user3", "group:test"}},
|
TagOwners: TagOwners{"tag:test": []string{"user3", "group:test"}},
|
||||||
ACLs: []ACL{
|
ACLs: []ACL{
|
||||||
{Action: "accept", Sources: []string{"tag:test"}, Destinations: []string{"*:*"}},
|
{
|
||||||
|
Action: "accept",
|
||||||
|
Sources: []string{"tag:test"},
|
||||||
|
Destinations: []string{"*:*"},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
err = app.UpdateACLRules()
|
err = app.UpdateACLRules()
|
||||||
@ -177,7 +193,11 @@ func (s *Suite) TestValidExpandTagOwnersInDestinations(c *check.C) {
|
|||||||
Groups: Groups{"group:test": []string{"user1", "user2"}},
|
Groups: Groups{"group:test": []string{"user1", "user2"}},
|
||||||
TagOwners: TagOwners{"tag:test": []string{"user3", "group:test"}},
|
TagOwners: TagOwners{"tag:test": []string{"user3", "group:test"}},
|
||||||
ACLs: []ACL{
|
ACLs: []ACL{
|
||||||
{Action: "accept", Sources: []string{"*"}, Destinations: []string{"tag:test:*"}},
|
{
|
||||||
|
Action: "accept",
|
||||||
|
Sources: []string{"*"},
|
||||||
|
Destinations: []string{"tag:test:*"},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
err = app.UpdateACLRules()
|
err = app.UpdateACLRules()
|
||||||
@ -222,7 +242,11 @@ func (s *Suite) TestInvalidTagValidNamespace(c *check.C) {
|
|||||||
app.aclPolicy = &ACLPolicy{
|
app.aclPolicy = &ACLPolicy{
|
||||||
TagOwners: TagOwners{"tag:test": []string{"user1"}},
|
TagOwners: TagOwners{"tag:test": []string{"user1"}},
|
||||||
ACLs: []ACL{
|
ACLs: []ACL{
|
||||||
{Action: "accept", Sources: []string{"user1"}, Destinations: []string{"*:*"}},
|
{
|
||||||
|
Action: "accept",
|
||||||
|
Sources: []string{"user1"},
|
||||||
|
Destinations: []string{"*:*"},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
err = app.UpdateACLRules()
|
err = app.UpdateACLRules()
|
||||||
|
5
app.go
5
app.go
@ -766,7 +766,10 @@ func (h *Headscale) setLastStateChangeToNow(namespaces ...string) {
|
|||||||
if len(namespaces) == 0 {
|
if len(namespaces) == 0 {
|
||||||
namespaces, err = h.ListNamespacesStr()
|
namespaces, err = h.ListNamespacesStr()
|
||||||
if err != nil {
|
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.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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))
|
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)
|
request.Expiration = timestamppb.New(expiration)
|
||||||
|
|
||||||
|
@ -164,7 +164,9 @@ var createPreAuthKeyCmd = &cobra.Command{
|
|||||||
|
|
||||||
expiration := time.Now().UTC().Add(time.Duration(duration))
|
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)
|
request.Expiration = timestamppb.New(expiration)
|
||||||
|
|
||||||
|
@ -24,7 +24,10 @@ const (
|
|||||||
func getHeadscaleApp() (*headscale.Headscale, error) {
|
func getHeadscaleApp() (*headscale.Headscale, error) {
|
||||||
cfg, err := headscale.GetHeadscaleConfig()
|
cfg, err := headscale.GetHeadscaleConfig()
|
||||||
if err != nil {
|
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)
|
app, err := headscale.NewHeadscale(cfg)
|
||||||
|
1
db.go
1
db.go
@ -111,7 +111,6 @@ func (h *Headscale) initDB() error {
|
|||||||
Err(err).
|
Err(err).
|
||||||
Msg("Failed to save normalized machine name in DB migration")
|
Msg("Failed to save normalized machine name in DB migration")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -219,7 +219,6 @@ func getIPs(
|
|||||||
func getDNSNames(
|
func getDNSNames(
|
||||||
headscale *dockertest.Resource,
|
headscale *dockertest.Resource,
|
||||||
) ([]string, error) {
|
) ([]string, error) {
|
||||||
|
|
||||||
listAllResult, err := ExecuteCommand(
|
listAllResult, err := ExecuteCommand(
|
||||||
headscale,
|
headscale,
|
||||||
[]string{
|
[]string{
|
||||||
@ -253,7 +252,6 @@ func getDNSNames(
|
|||||||
func getMagicFQDN(
|
func getMagicFQDN(
|
||||||
headscale *dockertest.Resource,
|
headscale *dockertest.Resource,
|
||||||
) ([]string, error) {
|
) ([]string, error) {
|
||||||
|
|
||||||
listAllResult, err := ExecuteCommand(
|
listAllResult, err := ExecuteCommand(
|
||||||
headscale,
|
headscale,
|
||||||
[]string{
|
[]string{
|
||||||
@ -278,7 +276,11 @@ func getMagicFQDN(
|
|||||||
hostnames := make([]string, len(listAll))
|
hostnames := make([]string, len(listAll))
|
||||||
|
|
||||||
for index := range 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
|
return hostnames, nil
|
||||||
|
@ -188,8 +188,16 @@ func (s *Suite) TestGetACLFilteredPeers(c *check.C) {
|
|||||||
Hosts: map[string]netaddr.IPPrefix{},
|
Hosts: map[string]netaddr.IPPrefix{},
|
||||||
TagOwners: map[string][]string{},
|
TagOwners: map[string][]string{},
|
||||||
ACLs: []ACL{
|
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{},
|
Tests: []ACLTest{},
|
||||||
}
|
}
|
||||||
|
6
poll.go
6
poll.go
@ -278,7 +278,11 @@ func (h *Headscale) PollNetMapStream(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.WithValue(ctx.Request.Context(), machineNameContextKey, machine.Hostname)
|
ctx := context.WithValue(
|
||||||
|
ctx.Request.Context(),
|
||||||
|
machineNameContextKey,
|
||||||
|
machine.Hostname,
|
||||||
|
)
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
@ -3,9 +3,9 @@ package headscale.v1;
|
|||||||
option go_package = "github.com/juanfont/headscale/gen/go/v1";
|
option go_package = "github.com/juanfont/headscale/gen/go/v1";
|
||||||
|
|
||||||
message ACLPolicy {
|
message ACLPolicy {
|
||||||
map<string,Group> groups = 1;
|
map<string, Group> groups = 1;
|
||||||
map<string,string> hosts = 2;
|
map<string, string> hosts = 2;
|
||||||
map<string,TagOwners> tag_owners = 3;
|
map<string, TagOwners> tag_owners = 3;
|
||||||
repeated ACL acls = 4;
|
repeated ACL acls = 4;
|
||||||
repeated ACLTest acl_test = 5;
|
repeated ACLTest acl_test = 5;
|
||||||
}
|
}
|
||||||
|
4
utils.go
4
utils.go
@ -332,7 +332,9 @@ func GenerateRandomStringDNSSafe(n int) (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
str = strings.ToLower(strings.ReplaceAll(strings.ReplaceAll(str, "_", ""), "-", ""))
|
str = strings.ToLower(
|
||||||
|
strings.ReplaceAll(strings.ReplaceAll(str, "_", ""), "-", ""),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return str[:n], nil
|
return str[:n], nil
|
||||||
|
Loading…
Reference in New Issue
Block a user