sdk

package
v0.0.20 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultLogger

type DefaultLogger struct {
	// contains filtered or unexported fields
}

DefaultLogger implementation of Logger using the go log package

func (DefaultLogger) Debug

func (d DefaultLogger) Debug(v ...interface{})

func (DefaultLogger) Debugf

func (d DefaultLogger) Debugf(format string, v ...interface{})

func (DefaultLogger) Error

func (d DefaultLogger) Error(v ...interface{})

func (DefaultLogger) Errorf

func (d DefaultLogger) Errorf(format string, v ...interface{})

func (DefaultLogger) Fatal

func (d DefaultLogger) Fatal(v ...interface{})

func (DefaultLogger) Fatalf

func (d DefaultLogger) Fatalf(format string, v ...interface{})

func (DefaultLogger) Info

func (d DefaultLogger) Info(v ...interface{})

func (DefaultLogger) Infof

func (d DefaultLogger) Infof(format string, v ...interface{})

func (DefaultLogger) Warn

func (d DefaultLogger) Warn(v ...interface{})

func (DefaultLogger) Warnf

func (d DefaultLogger) Warnf(format string, v ...interface{})

type Error

type Error keptnv2.Error

type FailingResourceHandler

type FailingResourceHandler struct {
}

func (FailingResourceHandler) GetResource

func (f FailingResourceHandler) GetResource(scope api.ResourceScope, options ...api.URIOption) (*models.Resource, error)

type FakeKeptn

type FakeKeptn struct {
	TestResourceHandler ResourceHandler
	SentEvents          []models.KeptnContextExtendedCE
	Keptn               *Keptn
}

func NewFakeKeptn

func NewFakeKeptn(source string) *FakeKeptn

func (*FakeKeptn) AddTaskEventHandler

func (f *FakeKeptn) AddTaskEventHandler(eventType string, handler TaskHandler, options TaskHandlerOptions)

func (*FakeKeptn) AddTaskHandler

func (f *FakeKeptn) AddTaskHandler(eventType string, handler TaskHandler, filters ...func(keptnHandle IKeptn, event KeptnEvent) bool)

AddTaskEventHandler registers a TaskHandler Deprecated: use AddTaskEventHandler

func (*FakeKeptn) AddTaskHandlerWithSubscriptionID

func (f *FakeKeptn) AddTaskHandlerWithSubscriptionID(eventType string, handler TaskHandler, subscriptionID string, filters ...func(keptnHandle IKeptn, event KeptnEvent) bool)

func (*FakeKeptn) AssertNumberOfEventSent

func (f *FakeKeptn) AssertNumberOfEventSent(t *testing.T, numOfEvents int)

func (*FakeKeptn) AssertSentEvent

func (f *FakeKeptn) AssertSentEvent(t *testing.T, eventIndex int, assertFn func(ce models.KeptnContextExtendedCE) bool)

func (*FakeKeptn) AssertSentEventResult

func (f *FakeKeptn) AssertSentEventResult(t *testing.T, eventIndex int, result v0_2_0.ResultType)

func (*FakeKeptn) AssertSentEventStatus

func (f *FakeKeptn) AssertSentEventStatus(t *testing.T, eventIndex int, status v0_2_0.StatusType)

func (*FakeKeptn) AssertSentEventType

func (f *FakeKeptn) AssertSentEventType(t *testing.T, eventIndex int, eventType string)

func (*FakeKeptn) GetResourceHandler

func (f *FakeKeptn) GetResourceHandler() ResourceHandler

func (*FakeKeptn) NewEvent

func (f *FakeKeptn) NewEvent(event models.KeptnContextExtendedCE) error

func (*FakeKeptn) SetAPI

func (f *FakeKeptn) SetAPI(api api.KeptnInterface)

func (*FakeKeptn) SetAutomaticResponse

func (f *FakeKeptn) SetAutomaticResponse(autoResponse bool)

func (*FakeKeptn) SetResourceHandler

func (f *FakeKeptn) SetResourceHandler(handler ResourceHandler)

type IKeptn

type IKeptn interface {
	// Start starts the internal event handling logic and needs to be called by the user
	// after creating value of IKeptn
	Start() error
	// GetResourceHandler returns a handler to fetch data from the configuration service
	GetResourceHandler() ResourceHandler
	// SendStartedEvent sends a started event for the given input event to the Keptn API
	// The first parameter is the "parent" event from which common information like e.g.
	// the keptn context, task name, ... are taken and used for constructing the corresponding .started event
	SendStartedEvent(KeptnEvent) error
	// SendFinishedEvent sends a finished event for the given input event to the Keptn API.
	// The first parameter can be seen as the "parent" event from which common information like e.g.
	// the keptn context, task name, ... are taken and used for constructing the corresponding .finished event.
	// The second parameter is the new event data to be set on the newly constructed .finished event
	SendFinishedEvent(KeptnEvent, interface{}) error
	// Logger returns the logger used by the sdk
	// Per default DefaultLogger is used which internally just uses the go logging package
	// Another logger can be configured using the sdk.WithLogger function
	Logger() Logger
	// APIV1 returns API utils for all Keptn APIs
	APIV1() api.KeptnInterface
	// APIV2 returns API utils for all v2 Keptn APIs
	APIV2() apiv2.KeptnInterface
}

type Keptn

type Keptn struct {
	// contains filtered or unexported fields
}

Keptn is the default implementation of IKeptn

func NewKeptn

func NewKeptn(source string, opts ...KeptnOption) *Keptn

NewKeptn creates a new Keptn

func (*Keptn) APIV1

func (k *Keptn) APIV1() api.KeptnInterface

APIV1 retrieves the APIV1 client Deprecated use APIV2 instead

func (*Keptn) APIV2

func (k *Keptn) APIV2() apiv2.KeptnInterface

APIV2 retrieves the APIV2 client

func (*Keptn) GetResourceHandler

func (k *Keptn) GetResourceHandler() ResourceHandler

func (*Keptn) Logger

func (k *Keptn) Logger() Logger

func (*Keptn) OnEvent

func (k *Keptn) OnEvent(ctx context.Context, event models.KeptnContextExtendedCE) error

func (*Keptn) RegistrationData

func (k *Keptn) RegistrationData() controlplane.RegistrationData

func (*Keptn) SendFinishedEvent

func (k *Keptn) SendFinishedEvent(parentEvent KeptnEvent, newEventData interface{}) error

func (*Keptn) SendStartedEvent

func (k *Keptn) SendStartedEvent(parentEvent KeptnEvent) error

func (*Keptn) Start

func (k *Keptn) Start() error

type KeptnOption

type KeptnOption func(*Keptn)

KeptnOption can be used to configure the keptn sdk

func WithAutomaticResponse

func WithAutomaticResponse(autoResponse bool) KeptnOption

WithAutomaticResponse sets the option to instruct the sdk to automatically send a .started and .finished event. Per default this behavior is turned on and can be disabled with this function. Note, that this affects ALL task handlers. If you want to disable automatic event responses for a specific task handler, this can be done with the respective TaskHandlerOptions passed to WithTaskEventHandler

func WithGracefulShutdown

func WithGracefulShutdown(gracefulShutdown bool) KeptnOption

WithGracefulShutdown sets the option to ensure running tasks/handlers will finish in case of interrupt or forced termination Per default this behavior is turned on and can be disabled with this function

func WithLogger

func WithLogger(logger Logger) KeptnOption

WithLogger configures keptn to use another logger

func WithTaskEventHandler

func WithTaskEventHandler(eventType string, handler TaskHandler, options TaskHandlerOptions) KeptnOption

WithTaskEventHandler registers a handler which is responsible for processing a received .triggered event

func WithTaskHandler

func WithTaskHandler(eventType string, handler TaskHandler, filters ...func(keptnHandle IKeptn, event KeptnEvent) bool) KeptnOption

WithTaskHandler registers a handler which is responsible for processing a .triggered event. Note, that if you want to have more control on configuring the behavior of the task handler, you can use WithTaskEventHandler instead

type Logger

type Logger interface {
	Debug(v ...interface{})
	Debugf(format string, v ...interface{})
	Info(v ...interface{})
	Infof(format string, v ...interface{})
	Warn(v ...interface{})
	Warnf(format string, v ...interface{})
	Error(v ...interface{})
	Errorf(format string, v ...interface{})
	Fatal(v ...interface{})
	Fatalf(format string, v ...interface{})
}

Logger interface used by the go sdk

type ResourceHandler

type ResourceHandler interface {
	GetResource(scope api.ResourceScope, options ...api.URIOption) (*models.Resource, error)
}

type StringResourceHandler

type StringResourceHandler struct {
	ResourceContent string
}

func (StringResourceHandler) GetResource

func (s StringResourceHandler) GetResource(scope api.ResourceScope, options ...api.URIOption) (*models.Resource, error)

type TaskHandler

type TaskHandler interface {
	// Execute is called whenever the actual business-logic of the service shall be executed.
	// Thus, the core logic of the service shall be triggered/implemented in this method.
	//
	// Note, that the contract of the method is to return the payload of the .finished event to be sent out as well as a Error Pointer
	// or nil, if there was no error during execution.
	Execute(keptnHandle IKeptn, event KeptnEvent) (interface{}, *Error)
}

type TaskHandlerOptions

type TaskHandlerOptions struct {
	// Filters specifies functions that determine whether the event shall be handled or ignored
	Filters []func(IKeptn, KeptnEvent) bool
	// SkipAutomaticResponse determines whether automatic sending of .started/.finished events should be skipped
	SkipAutomaticResponse bool
}

TaskHandlerOptions are specific options for a task handler

type TestResourceHandler

type TestResourceHandler struct {
	Resource models.Resource
}

func (TestResourceHandler) GetResource

func (t TestResourceHandler) GetResource(scope api.ResourceScope, options ...api.URIOption) (*models.Resource, error)

Jump to

Keyboard shortcuts

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