mirror of
https://github.com/juanfont/headscale.git
synced 2025-09-29 17:54:59 +02:00
79 lines
1.3 KiB
Go
79 lines
1.3 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 ACL from server: %s", err),
|
|
output,
|
|
)
|
|
|
|
return
|
|
}
|
|
|
|
if response == nil {
|
|
SuccessOutput(
|
|
``,
|
|
`No policy defined.`,
|
|
``,
|
|
)
|
|
|
|
return
|
|
}
|
|
|
|
policy, err := headscale.ACLProtoToStruct(response.Policy)
|
|
if err != nil {
|
|
ErrorOutput(
|
|
err,
|
|
fmt.Sprintf("Error parsing response from server: %s", err),
|
|
output,
|
|
)
|
|
|
|
return
|
|
}
|
|
|
|
SuccessOutput(
|
|
policy,
|
|
``,
|
|
output,
|
|
)
|
|
|
|
return
|
|
},
|
|
}
|