From 200e3b88cc2360fb92b7d2fe53fbc9c664ccf01d Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Wed, 26 Apr 2023 11:24:44 +0200 Subject: [PATCH] make generateFilterRule a pol struct func Signed-off-by: Kristoffer Dalby --- acls.go | 5 ++--- acls_test.go | 14 +++++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/acls.go b/acls.go index 3f7ce06c..ad5ff3fa 100644 --- a/acls.go +++ b/acls.go @@ -128,7 +128,7 @@ func (h *Headscale) UpdateACLRules() error { return errEmptyPolicy } - rules, err := generateFilterRules(machines, *h.aclPolicy, h.cfg.OIDC.StripEmaildomain) + rules, err := h.aclPolicy.generateFilterRules(machines, h.cfg.OIDC.StripEmaildomain) if err != nil { return err } @@ -226,9 +226,8 @@ func expandACLPeerAddr(srcIP string) []string { // generateFilterRules takes a set of machines and an ACLPolicy and generates a // set of Tailscale compatible FilterRules used to allow traffic on clients. -func generateFilterRules( +func (pol *ACLPolicy) generateFilterRules( machines []Machine, - pol ACLPolicy, stripEmaildomain bool, ) ([]tailcfg.FilterRule, error) { rules := []tailcfg.FilterRule{} diff --git a/acls_test.go b/acls_test.go index cd801fba..4264f07d 100644 --- a/acls_test.go +++ b/acls_test.go @@ -54,7 +54,7 @@ func (s *Suite) TestBasicRule(c *check.C) { err := app.LoadACLPolicy("./tests/acls/acl_policy_basic_1.hujson") c.Assert(err, check.IsNil) - rules, err := generateFilterRules([]Machine{}, *app.aclPolicy, false) + rules, err := app.aclPolicy.generateFilterRules([]Machine{}, false) c.Assert(err, check.IsNil) c.Assert(rules, check.NotNil) } @@ -411,7 +411,7 @@ func (s *Suite) TestPortRange(c *check.C) { err := app.LoadACLPolicy("./tests/acls/acl_policy_basic_range.hujson") c.Assert(err, check.IsNil) - rules, err := generateFilterRules([]Machine{}, *app.aclPolicy, false) + rules, err := app.aclPolicy.generateFilterRules([]Machine{}, false) c.Assert(err, check.IsNil) c.Assert(rules, check.NotNil) @@ -425,7 +425,7 @@ func (s *Suite) TestProtocolParsing(c *check.C) { err := app.LoadACLPolicy("./tests/acls/acl_policy_basic_protocols.hujson") c.Assert(err, check.IsNil) - rules, err := generateFilterRules([]Machine{}, *app.aclPolicy, false) + rules, err := app.aclPolicy.generateFilterRules([]Machine{}, false) c.Assert(err, check.IsNil) c.Assert(rules, check.NotNil) @@ -439,7 +439,7 @@ func (s *Suite) TestPortWildcard(c *check.C) { err := app.LoadACLPolicy("./tests/acls/acl_policy_basic_wildcards.hujson") c.Assert(err, check.IsNil) - rules, err := generateFilterRules([]Machine{}, *app.aclPolicy, false) + rules, err := app.aclPolicy.generateFilterRules([]Machine{}, false) c.Assert(err, check.IsNil) c.Assert(rules, check.NotNil) @@ -455,7 +455,7 @@ func (s *Suite) TestPortWildcardYAML(c *check.C) { err := app.LoadACLPolicy("./tests/acls/acl_policy_basic_wildcards.yaml") c.Assert(err, check.IsNil) - rules, err := generateFilterRules([]Machine{}, *app.aclPolicy, false) + rules, err := app.aclPolicy.generateFilterRules([]Machine{}, false) c.Assert(err, check.IsNil) c.Assert(rules, check.NotNil) @@ -498,7 +498,7 @@ func (s *Suite) TestPortUser(c *check.C) { machines, err := app.ListMachines() c.Assert(err, check.IsNil) - rules, err := generateFilterRules(machines, *app.aclPolicy, false) + rules, err := app.aclPolicy.generateFilterRules(machines, false) c.Assert(err, check.IsNil) c.Assert(rules, check.NotNil) @@ -541,7 +541,7 @@ func (s *Suite) TestPortGroup(c *check.C) { machines, err := app.ListMachines() c.Assert(err, check.IsNil) - rules, err := generateFilterRules(machines, *app.aclPolicy, false) + rules, err := app.aclPolicy.generateFilterRules(machines, false) c.Assert(err, check.IsNil) c.Assert(rules, check.NotNil)