webhook

package
v0.104.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DeployItemWebhookLogic webhooklib.WebhookLogic = func(ctx context.Context, req admission.Request, dec runtime.Decoder) admission.Response {
	logger, _ := logging.FromContextOrNew(ctx, []interface{}{lc.KeyMethod, "DeployItemWebhookLogic"})

	di := &lscore.DeployItem{}
	if _, _, err := dec.Decode(req.Object.Raw, nil, di); err != nil {
		logger.Debug("Decoding failed: " + err.Error())
		return admission.Errored(http.StatusBadRequest, err)
	}

	if errs := validation.ValidateDeployItem(di); len(errs) > 0 {
		aggErr := errs.ToAggregate().Error()
		logger.Debug("Validation failed: " + aggErr)
		return admission.Denied(aggErr)
	}

	if req.Operation == admissionv1.Update {
		oldDi := &lscore.DeployItem{}
		if _, _, err := dec.Decode(req.OldObject.Raw, nil, oldDi); err != nil {
			logger.Debug("Decoding old failed: " + err.Error())
			return admission.Errored(http.StatusBadRequest, err)
		}
		if oldDi.Spec.Type != di.Spec.Type {
			logger.Debug(fmt.Sprintf("deployitem type is immutable, got %q but expected %q", di.Spec.Type, oldDi.Spec.Type))
			return admission.Errored(http.StatusForbidden, field.Forbidden(field.NewPath(".spec.type"), "type is immutable"))
		}
	}

	return admission.Allowed("DeployItem is valid")
}
View Source
var ExecutionWebhookLogic webhooklib.WebhookLogic = func(ctx context.Context, req admission.Request, dec runtime.Decoder) admission.Response {
	logger, _ := logging.FromContextOrNew(ctx, []interface{}{lc.KeyMethod, "ExecutionWebhookLogic"})

	exec := &lscore.Execution{}
	if _, _, err := dec.Decode(req.Object.Raw, nil, exec); err != nil {
		logger.Debug("Decoding failed: " + err.Error())
		return admission.Errored(http.StatusBadRequest, err)
	}

	if errs := validation.ValidateExecution(exec); len(errs) > 0 {
		aggErr := errs.ToAggregate().Error()
		logger.Debug("Validation failed: " + aggErr)
		return admission.Denied(aggErr)
	}

	return admission.Allowed("Execution is valid")
}
View Source
var InstallationWebhookLogic webhooklib.WebhookLogic = func(ctx context.Context, req admission.Request, dec runtime.Decoder) admission.Response {
	logger, _ := logging.FromContextOrNew(ctx, []interface{}{lc.KeyMethod, "InstallationWebhookLogic"})
	inst := &lscore.Installation{}
	if _, _, err := dec.Decode(req.Object.Raw, nil, inst); err != nil {
		logger.Debug("Decoding failed: " + err.Error())
		return admission.Errored(http.StatusBadRequest, err)
	}

	if errs := validation.ValidateInstallation(inst); len(errs) > 0 {
		aggErr := errs.ToAggregate().Error()
		logger.Debug("Validation failed: " + aggErr)
		return admission.Denied(aggErr)
	}

	return admission.Allowed("Installation is valid")
}
View Source
var TargetWebhookLogic webhooklib.WebhookLogic = func(ctx context.Context, req admission.Request, dec runtime.Decoder) admission.Response {
	logger, _ := logging.FromContextOrNew(ctx, []interface{}{lc.KeyMethod, "ExecutionWebhookLogic"})

	t := &lscore.Target{}
	if _, _, err := dec.Decode(req.Object.Raw, nil, t); err != nil {
		logger.Debug("Decoding failed: " + err.Error())
		return admission.Errored(http.StatusBadRequest, err)
	}

	if errs := validation.ValidateTarget(t); len(errs) > 0 {
		aggErr := errs.ToAggregate().Error()
		logger.Debug("Validation failed: " + aggErr)
		return admission.Denied(aggErr)
	}

	return admission.Allowed("Target is valid")
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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