1
0
mirror of https://github.com/juanfont/headscale.git synced 2025-09-20 17:53:11 +02:00

added cli options to output ACLs

This commit is contained in:
Samuel Lock 2022-05-12 20:18:52 +10:00
parent 41cd0d30eb
commit c054e2766e
3 changed files with 69 additions and 5 deletions

View File

@ -11,11 +11,11 @@ import (
// ACLPolicy represents a Tailscale ACL Policy.
type ACLPolicy struct {
Groups Groups `json:"Groups" yaml:"Groups"`
Hosts Hosts `json:"Hosts" yaml:"Hosts"`
TagOwners TagOwners `json:"TagOwners" yaml:"TagOwners"`
ACLs []ACL `json:"ACLs" yaml:"ACLs"`
Tests []ACLTest `json:"Tests" yaml:"Tests"`
Groups Groups `json:"Groups,omitempty" yaml:"Groups,omitempty"`
Hosts Hosts `json:"Hosts,omitempty" yaml:"Hosts,omitempty"`
TagOwners TagOwners `json:"TagOwners,omitempty" yaml:"TagOwners,omitempty"`
ACLs []ACL `json:"ACLs,omitempty" yaml:"ACLs,omitempty"`
Tests []ACLTest `json:"Tests,omitempty" yaml:"Tests,omitempty"`
}
// ACL is a basic rule for the ACL Policy.

4
app.go
View File

@ -874,3 +874,7 @@ func readOrCreatePrivateKey(path string) (*key.MachinePrivate, error) {
return &machineKey, nil
}
func (h *Headscale) GetACLPolicy() (*ACLPolicy) {
return h.aclPolicy
}

60
cmd/headscale/cli/acls.go Normal file
View File

@ -0,0 +1,60 @@
package cli
import (
"fmt"
"github.com/spf13/cobra"
)
func init() {
rootCmd.AddCommand(aclsCmd)
aclsCmd.AddCommand(listAclsCmd)
}
var aclsCmd = &cobra.Command{
Use: "acls",
Short: "Manage Access Control Lists (ACLs)",
Aliases: []string{"access-lists","acl"},
}
var listAclsCmd = &cobra.Command{
Use: "list",
Short: "List ACLs",
Aliases: []string{"ls","show"},
Run: func(cmd *cobra.Command, args []string) {
output, _ := cmd.Flags().GetString("output")
if output == `` {
output = `json`
}
h, err := getHeadscaleApp()
if err != nil {
ErrorOutput(
err,
fmt.Sprintf("Error getting headscale app: %s", err),
output,
)
return
}
policy := h.GetACLPolicy()
if policy == nil {
SuccessOutput(
``,
`No policy defined.`,
``,
)
return
}
SuccessOutput(
policy,
``,
output,
)
return
},
}