Initial work on ACLs
This commit is contained in:
parent
95fee5aa6f
commit
b161a92e58
6 changed files with 252 additions and 0 deletions
30
acls.go
Normal file
30
acls.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package headscale
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/tailscale/hujson"
|
||||
)
|
||||
|
||||
const errorInvalidPolicy = Error("invalid policy")
|
||||
|
||||
func (h *Headscale) ParsePolicy(path string) (*ACLPolicy, error) {
|
||||
policyFile, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer policyFile.Close()
|
||||
|
||||
var policy ACLPolicy
|
||||
b, err := io.ReadAll(policyFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = hujson.Unmarshal(b, &policy)
|
||||
if policy.IsZero() {
|
||||
return nil, errorInvalidPolicy
|
||||
}
|
||||
|
||||
return &policy, err
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue