cli

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Copyright © 2022 NAME HERE <EMAIL ADDRESS>

Copyright © 2022 NAME HERE <EMAIL ADDRESS>

Index

Constants

This section is empty.

Variables

View Source
var OPACmd = &cobra.Command{
	Use:   "opa {-r <policy file> -k <Kube manifest file> | -b <directory of policies and manifests>} [flags]",
	Short: "Validate the syntax and output of a V2 Insights OPA policy",
	Long:  `opa runs V2 format Insights OPA policies with a Kubernetes manifest as input, validating rego syntax and proper Insights action item output.`,
	Example: `
	To validate a single policy: insights-cli validate opa -r policy.rego -k input-manifest.yaml

	To validate a directory of policies and Kubernetes manifests, with a policy and its corresponding Kubernetes manifest sharing the same base filename: insights-cli validate opa -b ./all_policies`,
	Run: func(cmd *cobra.Command, args []string) {
		if !checkValidateOPAFlags() {
			err := cmd.Help()
			if err != nil {
				logrus.Error(err)
			}
			os.Exit(1)
		}
		if regoFileName != "" {
			_, err := opavalidation.Run(regoFileName, objectFileName, expectActionItem, fwrego.InsightsInfo{InsightsContext: insightsInfoContext, Cluster: insightsInfoCluster}, objectNamespaceOverride)
			if err != nil {
				fmt.Printf("OPA policy failed validation: %v\n", err)
				os.Exit(1)
			}
			fmt.Println("OPA policy validated successfully.")
		}

		if batchDir != "" {
			_, failedPolicies, err := opavalidation.RunBatch(batchDir, expectActionItem, fwrego.InsightsInfo{InsightsContext: insightsInfoContext, Cluster: insightsInfoCluster}, objectNamespaceOverride)
			fmt.Println()
			if err != nil {
				fmt.Printf("OPA policies failed validation: %v\n", err)
				fmt.Printf("Please check the above output for details about the %s\n", opavalidation.HumanizeStringsOutput(failedPolicies, "failure"))
				os.Exit(1)
			}
			fmt.Println("OPA policies validated successfully.")
		}
	},
}

OPACmd represents the validate opa command

Functions

func IsEmpty added in v1.2.0

func IsEmpty(path string) (bool, error)

func Run

func Run() (exitValue int)

RUn executes the cobra root command, and returns an exit value depending on whether an error occured.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL