mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-23 18:15:26 +00:00
31 lines
505 B
Go
31 lines
505 B
Go
|
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
|
||
|
}
|