mirror of
https://github.com/juanfont/headscale.git
synced 2025-10-28 10:51:44 +01:00
added cli options to output ACLs
This commit is contained in:
parent
41cd0d30eb
commit
c054e2766e
@ -11,11 +11,11 @@ import (
|
|||||||
|
|
||||||
// ACLPolicy represents a Tailscale ACL Policy.
|
// ACLPolicy represents a Tailscale ACL Policy.
|
||||||
type ACLPolicy struct {
|
type ACLPolicy struct {
|
||||||
Groups Groups `json:"Groups" yaml:"Groups"`
|
Groups Groups `json:"Groups,omitempty" yaml:"Groups,omitempty"`
|
||||||
Hosts Hosts `json:"Hosts" yaml:"Hosts"`
|
Hosts Hosts `json:"Hosts,omitempty" yaml:"Hosts,omitempty"`
|
||||||
TagOwners TagOwners `json:"TagOwners" yaml:"TagOwners"`
|
TagOwners TagOwners `json:"TagOwners,omitempty" yaml:"TagOwners,omitempty"`
|
||||||
ACLs []ACL `json:"ACLs" yaml:"ACLs"`
|
ACLs []ACL `json:"ACLs,omitempty" yaml:"ACLs,omitempty"`
|
||||||
Tests []ACLTest `json:"Tests" yaml:"Tests"`
|
Tests []ACLTest `json:"Tests,omitempty" yaml:"Tests,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ACL is a basic rule for the ACL Policy.
|
// ACL is a basic rule for the ACL Policy.
|
||||||
|
|||||||
4
app.go
4
app.go
@ -874,3 +874,7 @@ func readOrCreatePrivateKey(path string) (*key.MachinePrivate, error) {
|
|||||||
|
|
||||||
return &machineKey, nil
|
return &machineKey, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *Headscale) GetACLPolicy() (*ACLPolicy) {
|
||||||
|
return h.aclPolicy
|
||||||
|
}
|
||||||
60
cmd/headscale/cli/acls.go
Normal file
60
cmd/headscale/cli/acls.go
Normal 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
|
||||||
|
},
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user