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) {
|
||||
|
||||
// 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()
|
||||
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
|
||||
@ -153,14 +152,14 @@ func ACLProtoToStruct(v *v1.ACLPolicy) (*ACLPolicy, error) {
|
||||
// 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
|
||||
vacls := (*v).GetAcls()
|
||||
acls := make([]ACL, len(vacls))
|
||||
for n,i := range vacls {
|
||||
for n, i := range vacls {
|
||||
acls[n] = ACL{
|
||||
Action: i.GetAction(),
|
||||
Protocol: i.GetProtocol(),
|
||||
@ -172,7 +171,7 @@ func ACLProtoToStruct(v *v1.ACLPolicy) (*ACLPolicy, error) {
|
||||
// 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(),
|
||||
|
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) {
|
||||
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()
|
||||
|
5
app.go
5
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.")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
1
db.go
1
db.go
@ -111,7 +111,6 @@ func (h *Headscale) initDB() error {
|
||||
Err(err).
|
||||
Msg("Failed to save normalized machine name in DB migration")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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{},
|
||||
}
|
||||
|
6
poll.go
6
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()
|
||||
|
@ -3,9 +3,9 @@ package headscale.v1;
|
||||
option go_package = "github.com/juanfont/headscale/gen/go/v1";
|
||||
|
||||
message ACLPolicy {
|
||||
map<string,Group> groups = 1;
|
||||
map<string,string> hosts = 2;
|
||||
map<string,TagOwners> tag_owners = 3;
|
||||
map<string, Group> groups = 1;
|
||||
map<string, string> hosts = 2;
|
||||
map<string, TagOwners> tag_owners = 3;
|
||||
repeated ACL acls = 4;
|
||||
repeated ACLTest acl_test = 5;
|
||||
}
|
||||
|
4
utils.go
4
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
|
||||
|
Loading…
Reference in New Issue
Block a user