mirror of
https://github.com/vee1e/kubearmor-client.git
synced 2026-09-01 18:28:04 +00:00
74 lines
2.1 KiB
Go
74 lines
2.1 KiB
Go
// SPDX-License-Identifier: Apache-2.0
|
|
// Copyright 2021 Authors of KubeArmor
|
|
//go:build darwin || (linux && !windows)
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/kubearmor/kubearmor-client/vm"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var policyOptions vm.PolicyOptions
|
|
|
|
// vmPolicyCmd represents the vm command for policy enforcement
|
|
var vmPolicyCmd = &cobra.Command{
|
|
Use: "policy",
|
|
Short: "policy handling for non kubernetes/bare metal KubeArmor",
|
|
Long: `policy handling for non kubernetes/bare metal KubeArmor`,
|
|
}
|
|
|
|
// vmPolicyAddCmd represents the vm add policy command for policy enforcement
|
|
var vmPolicyAddCmd = &cobra.Command{
|
|
Use: "add",
|
|
Short: "add policy for non kubernetes/bare metal KubeArmor",
|
|
Long: `add policy for non kubernetes/bare metal KubeArmor`,
|
|
Args: func(cmd *cobra.Command, args []string) error {
|
|
if len(args) < 1 {
|
|
return errors.New("requires a path to valid policy YAML as argument")
|
|
}
|
|
return nil
|
|
},
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
if err := vm.PolicyHandling("ADDED", args[0], policyOptions); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
},
|
|
}
|
|
|
|
// vmPolicyDeleteCmd represents the vm delete policy command for policy enforcement
|
|
var vmPolicyDeleteCmd = &cobra.Command{
|
|
Use: "delete",
|
|
Short: "delete policy for non kubernetes/bare metal KubeArmor",
|
|
Long: `delete policy for non kubernetes/bare metal KubeArmor`,
|
|
Args: func(cmd *cobra.Command, args []string) error {
|
|
if len(args) < 1 {
|
|
return errors.New("requires a path to valid policy YAML as argument")
|
|
}
|
|
return nil
|
|
},
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
if err := vm.PolicyHandling("DELETED", args[0], policyOptions); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
},
|
|
}
|
|
|
|
// ========== //
|
|
// == Init == //
|
|
// ========== //
|
|
|
|
func init() {
|
|
vmCmd.AddCommand(vmPolicyCmd)
|
|
|
|
// Subcommand for policy command
|
|
vmPolicyCmd.AddCommand(vmPolicyAddCmd)
|
|
vmPolicyCmd.AddCommand(vmPolicyDeleteCmd)
|
|
|
|
// gRPC endpoint flag to communicate with KubeArmor. Available across subcommands.
|
|
vmPolicyCmd.PersistentFlags().StringVar(&policyOptions.GRPC, "gRPC", "", "gRPC server information")
|
|
}
|