testutils

package
v0.0.0-...-d20acdf Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanCanNot

func CanCanNot(b bool) string

CanCanNot helper to make English a bit nicer

func CreateFakeRequestJSON

func CreateFakeRequestJSON(uid string,
	gvk metav1.GroupVersionKind, gvr metav1.GroupVersionResource,
	operation admissionv1.Operation,
	username string, userGroups []string,
	obj, oldObject *runtime.RawExtension) ([]byte, error)

CreateFakeRequestJSON will render the []byte slice needed for the (fake) HTTP request. Inputs into this are the request UID, which GVK and GVR are being gated by this webhook, User information (username and groups), what kind of operation is being gated by this webhook and finally the runtime.RawExtension representation of the request's Object or OldObject The Object/OldObject is automatically inferred by the operation; delete operations will force OldObject To create the RawExtension:

obj := runtime.RawExtension{
	Raw: []byte(rawObjString),
}

where rawObjString is a literal JSON blob, eg:

{
 "metadata": {
   "name": "namespace-name",
   "uid": "request-userid",
   "creationTimestamp": "2020-05-10T07:51:00Z"
 },
 "users": null
}

func CreateHTTPRequest

func CreateHTTPRequest(uri, uid string,
	gvk metav1.GroupVersionKind, gvr metav1.GroupVersionResource,
	operation admissionv1.Operation,
	username string, userGroups []string,
	obj, oldObject *runtime.RawExtension) (*http.Request, error)

CreateHTTPRequest takes all the information needed for an AdmissionReview. See also CreateFakeRequestJSON for more.

func SendHTTPRequest

func SendHTTPRequest(req *http.Request, s Webhook) (*admissionv1.AdmissionResponse, error)

SendHTTPRequest will send the fake request to be handled by the Webhook

Types

type Webhook

type Webhook interface {
	// Authorized will determine if the request is allowed
	Authorized(request admissionctl.Request) admissionctl.Response
}

Webhook interface

Jump to

Keyboard shortcuts

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