1
0
mirror of https://github.com/juanfont/headscale.git synced 2025-10-05 11:19:03 +02:00
juanfont.headscale/cmd/headscale/cli/acls.go
2022-06-17 18:03:42 +10:00

68 lines
1.1 KiB
Go

package cli
import (
"fmt"
// "github.com/juanfont/headscale".
v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
"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`
}
ctx, client, conn, cancel := getHeadscaleCLIClient()
defer cancel()
defer conn.Close()
request := &v1.ListACLPolicyRequest{}
response, err := client.ListACLPolicy(ctx, request)
if err != nil {
ErrorOutput(
err,
fmt.Sprintf("Error getting headscale app: %s", err),
output,
)
return
}
if response == nil {
SuccessOutput(
``,
`No policy defined.`,
``,
)
return
}
SuccessOutput(
response,
``,
output,
)
return
},
}
}