Skip to content

Commit

Permalink
make generateFilterRule a pol struct func
Browse files Browse the repository at this point in the history
Signed-off-by: Kristoffer Dalby <[email protected]>
  • Loading branch information
kradalby authored and juanfont committed May 3, 2023
1 parent 5bbbe43 commit 200e3b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
5 changes: 2 additions & 3 deletions acls.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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{}
Expand Down
14 changes: 7 additions & 7 deletions acls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 200e3b8

Please sign in to comment.