common

package
v1.10.2 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2023 License: Apache-2.0 Imports: 38 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(c ApplyPolicyConfig) ([]engineapi.EngineResponse, 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 GetGitBranchOrPolicyPaths added in v1.9.0

func GetGitBranchOrPolicyPaths(gitBranch, repoURL string, policyPaths []string) (string, string)

func GetKindsFromPolicy

func GetKindsFromPolicy(policy kyvernov1.PolicyInterface, subresources []Subresource, dClient dclient.Interface) map[string]struct{}

func GetKindsFromRule

GetKindsFromRule will return the kinds from policy match block

func GetPatchedAndGeneratedResource added in v1.8.0

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

GetPatchedAndGeneratedResource 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, error)

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

func HasVariables

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

HasVariables - check for variables in the policy

func IsGitSourcePath added in v1.9.0

func IsGitSourcePath(policyPaths []string) bool

func IsInputFromPipe

func IsInputFromPipe() bool

IsInputFromPipe - check if input is passed using pipe

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 engineapi.EngineResponse, resPath string, rc *ResultCounts, policyReport bool, auditWarn bool)

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 ApplyPolicyConfig added in v1.9.0

type ApplyPolicyConfig struct {
	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
	Client                    dclient.Interface
	AuditWarn                 bool
	Subresources              []Subresource
}

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 Subresource added in v1.9.0

type Subresource struct {
	APIResource    metav1.APIResource `json:"subresource"`
	ParentResource metav1.APIResource `json:"parentResource"`
}

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, []Subresource, error)

type Values

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

Jump to

Keyboard shortcuts

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