common

package
v1.8.2-rc.2 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2022 License: Apache-2.0 Imports: 41 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var IsHTTPRegex = regexp.MustCompile("^(http|https)://")

IsHTTPRegex represents regex for starts with http:// or https://

View Source
var RegexVariables = regexp.MustCompile(`\{\{[^{}]*\}\}`)

RegexVariables represents regex for '{{}}'

Functions

func ApplyPolicyOnResource

func ApplyPolicyOnResource(policy kyvernov1.PolicyInterface, resource *unstructured.Unstructured,
	mutateLogPath string, mutateLogPathIsDir bool, variables map[string]interface{}, userInfo kyvernov1beta1.RequestInfo, policyReport bool,
	namespaceSelectorMap map[string]map[string]string, stdin bool, rc *ResultCounts,
	printPatchResource bool, ruleToCloneSourceResource map[string]string,
) ([]*response.EngineResponse, policyreport.Info, error)

ApplyPolicyOnResource - function to apply policy on resource

func CheckVariableForPolicy

func CheckVariableForPolicy(valuesMap map[string]map[string]Resource, globalValMap map[string]string, policyName string, resourceName string, resourceKind string, variables map[string]string, kindOnwhichPolicyIsApplied map[string]struct{}, variable string) (map[string]interface{}, error)

func GetKindsFromPolicy

func GetKindsFromPolicy(policy kyvernov1.PolicyInterface) map[string]struct{}

func GetKindsFromRule

func GetKindsFromRule(rule kyvernov1.Rule) map[string]bool

GetKindsFromRule will return the kinds from policy match block

func GetPatchedAndGeneratedResource added in v1.8.0

func GetPatchedAndGeneratedResource(resourceBytes []byte) (unstructured.Unstructured, error)

GetPatchedResource converts raw bytes to unstructured object

func GetPolicies

func GetPolicies(paths []string) (policies []kyvernov1.PolicyInterface, errors []error)

GetPolicies - Extracting the policies from multiple YAML

func GetPoliciesFromPaths

func GetPoliciesFromPaths(fs billy.Filesystem, dirPath []string, isGit bool, policyResourcePath string) (policies []kyvernov1.PolicyInterface, err error)

GetPoliciesFromPaths - get policies according to the resource path

func GetResource

func GetResource(resourceBytes []byte) ([]*unstructured.Unstructured, error)

GetResource converts raw bytes to unstructured object

func GetResourceAccordingToResourcePath

func GetResourceAccordingToResourcePath(fs billy.Filesystem, resourcePaths []string,
	cluster bool, policies []kyvernov1.PolicyInterface, dClient dclient.Interface, namespace string, policyReport bool, isGit bool, policyResourcePath string,
) (resources []*unstructured.Unstructured, err error)

GetResourceAccordingToResourcePath - get resources according to the resource path

func GetResourceFromPath added in v1.8.0

func GetResourceFromPath(fs billy.Filesystem, path string, isGit bool, policyResourcePath string, resourceType string) (unstructured.Unstructured, error)

GetResourceFromPath - get patchedResource and generatedResource from given path

func GetResources

func GetResources(policies []kyvernov1.PolicyInterface, resourcePaths []string, dClient dclient.Interface, cluster bool, namespace string, policyReport bool) ([]*unstructured.Unstructured, error)

GetResources gets matched resources by the given policies the resources are fetched from - local paths to resources, if given - the k8s cluster, if given

func GetResourcesWithTest

func GetResourcesWithTest(fs billy.Filesystem, policies []kyvernov1.PolicyInterface, resourcePaths []string, isGit bool, policyResourcePath string) ([]*unstructured.Unstructured, error)

GetResourcesWithTest with gets matched resources by the given policies

func GetUserInfoFromPath

func GetUserInfoFromPath(fs billy.Filesystem, path string, isGit bool, policyResourcePath string) (kyvernov1beta1.RequestInfo, store.Subject, error)

GetUserInfoFromPath - get the request info as user info from a given path

func GetVariable

func GetVariable(variablesString, valuesFile string, fs billy.Filesystem, isGit bool, policyResourcePath string) (map[string]string, map[string]string, map[string]map[string]Resource, map[string]map[string]string, error)

func HasVariables

func HasVariables(policy kyvernov1.PolicyInterface) [][]string

HasVariables - check for variables in the policy

func IsInputFromPipe

func IsInputFromPipe() bool

IsInputFromPipe - check if input is passed using pipe

func MutatePolicies

func MutatePolicies(policies []kyvernov1.PolicyInterface) ([]kyvernov1.PolicyInterface, error)

MutatePolicies - function to apply mutation on policies

func MutatePolicy

func MutatePolicy(policy kyvernov1.PolicyInterface, logger logr.Logger) (kyvernov1.PolicyInterface, error)

MutatePolicy - applies mutation to a policy

func PrintMutatedOutput

func PrintMutatedOutput(mutateLogPath string, mutateLogPathIsDir bool, yaml string, fileName string) error

PrintMutatedOutput - function to print output in provided file or directory

func PrintMutatedPolicy

func PrintMutatedPolicy(mutatedPolicies []kyvernov1.PolicyInterface) error

func ProcessValidateEngineResponse

func ProcessValidateEngineResponse(policy kyvernov1.PolicyInterface, validateResponse *response.EngineResponse, resPath string, rc *ResultCounts, policyReport bool) policyreport.Info

func RemoveDuplicateAndObjectVariables

func RemoveDuplicateAndObjectVariables(matches [][]string) string

RemoveDuplicateAndObjectVariables - remove duplicate variables

func SetInStoreContext

func SetInStoreContext(mutatedPolicies []kyvernov1.PolicyInterface, variables map[string]string) map[string]string

Types

type NamespaceSelector

type NamespaceSelector struct {
	Name   string            `json:"name"`
	Labels map[string]string `json:"labels"`
}

type Policy

type Policy struct {
	Name      string     `json:"name"`
	Resources []Resource `json:"resources"`
	Rules     []Rule     `json:"rules"`
}

type Resource

type Resource struct {
	Name   string                 `json:"name"`
	Values map[string]interface{} `json:"values"`
}

type ResultCounts

type ResultCounts struct {
	Pass  int
	Fail  int
	Warn  int
	Error int
	Skip  int
}

type Rule

type Rule struct {
	Name          string                   `json:"name"`
	Values        map[string]interface{}   `json:"values"`
	ForeachValues map[string][]interface{} `json:"foreachValues"`
}

type Values

type Values struct {
	Policies           []Policy            `json:"policies"`
	GlobalValues       map[string]string   `json:"globalValues"`
	NamespaceSelectors []NamespaceSelector `json:"namespaceSelector"`
}

Jump to

Keyboard shortcuts

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