actuator

package
v0.0.0-...-781ef27 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2017 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// GithubWebhookSecretEnvVariable is the name of the environment variable to use for the secret
	GithubWebhookSecretEnvVariable = "ACTUATOR_WEBHOOK_SECRET"
	// GithubAccessTokenEnvVariable is the name of the environment variable to use for the access token
	GithubAccessTokenEnvVariable = "ACTUATOR_GITHUB_ACCESS_TOKEN"
)
View Source
const (
	// DebugMode sets gin into debug mode
	DebugMode string = gin.DebugMode
	// ReleaseMode disables gin debug features
	ReleaseMode string = gin.ReleaseMode
	// TestMode runs gin in test mode
	TestMode string = gin.TestMode
)
View Source
const ConfigFileName = "actuator.yml"

ConfigFileName defines the name of the configuration file

Variables

View Source
var Config = Configuration{}

Config contains the actual configuration of the app

View Source
var Logger = log.New(os.Stdout, "", log.LstdFlags)

Logger is the central logger for the actuator

SupportedPullRequestActions defines all actions which are currently supported to be handled

Functions

func LoadConfiguration

func LoadConfiguration() error

LoadConfiguration loads the configuration into an internal struct

Types

type Configuration

type Configuration struct {
	GithubWebhookSecret string             `yaml:"github_webhook_secret"` // used to identify incomming webhooks
	GithubAccessToken   string             `yaml:"github_access_token"`   // used to identify against the github api
	Repositories        []RepositoryConfig `yaml:"repositories"`          // repository configurations
}

Configuration contains all configuration options for the app

func (*Configuration) GetRepositoryConfig

func (c *Configuration) GetRepositoryConfig(fullname string) (RepositoryConfig, bool)

GetRepositoryConfig returns the configuration for the repository with the given name

func (*Configuration) LoadConfigFile

func (c *Configuration) LoadConfigFile(fs afero.Fs, config *Configuration) error

LoadConfigFile loads the configuration file into the Config variable It takes an afero.Fs struct to abstract the file system

func (*Configuration) LoadGithubAccessToken

func (c *Configuration) LoadGithubAccessToken()

LoadGithubAccessToken loads the github token from an environment variable

func (*Configuration) LoadGithubWebhookSecret

func (c *Configuration) LoadGithubWebhookSecret()

LoadGithubWebhookSecret loads the github token from an environment variable

type Endpoint

type Endpoint interface {
	Handle(c *gin.Context) (int, interface{})
}

Endpoint defines an interface for all web hook endpoints

type EventDispatcher

type EventDispatcher struct {
	LastEventHandler  EventHandler
	LastEventResponse *EventResponse
}

EventDispatcher is responsible to find the right handler for an incoming Github event. It then forwards the request to the respective handler.

func (*EventDispatcher) FindEventHandler

func (d *EventDispatcher) FindEventHandler(event *github.Event) EventHandler

FindEventHandler finds a handler for the provided event

func (*EventDispatcher) GetEventResponse

func (d *EventDispatcher) GetEventResponse(event *github.Event) *EventResponse

GetEventResponse looks for an appropriate handler to care for this event. It then calls its GetEventResponse method and returns the data.

func (*EventDispatcher) HandleEvent

func (d *EventDispatcher) HandleEvent(event *github.Event)

HandleEvent dispatches the call to the last used event handler

type EventEndpoint

type EventEndpoint struct {
	WebhookParser WebhookParser
	Request       *http.Request
	EventHandler  EventHandler
}

EventEndpoint is an api endpoint to handle Github event webhooks. It needs a parser and an event handler

func NewEventEndpoint

func NewEventEndpoint(request *http.Request) *EventEndpoint

NewEventEndpoint produces a new endpoint to handle github events

func (*EventEndpoint) Handle

func (e *EventEndpoint) Handle() (int, interface{})

Handle parses the request into a github event and handles it

type EventHandler

type EventHandler interface {
	// GetEventResponse gets a response for the sender of the hook. This method doesn't have
	// to do the heavy work as in most cases the caller of the endpoint doesn't care if the work
	// involved succeeded or not. It's just interested if the hook was received correctly and
	// can be handled.
	GetEventResponse(event *github.Event) *EventResponse

	// HandleEvent does the actual work of handling an event. The result of this operation will
	// be logged but not returned to the caller. This makes it possible to do the heavy work
	// in the background and get a fast response for the caller of the hook.
	HandleEvent(event *github.Event)
}

EventHandler is an interface for every event handler in the system

type EventResponse

type EventResponse struct {
	// Message can be returned to the sender of the hook
	Message string

	// HandleEvent tells the receiver if the event should actually be handled
	// if not, the the HandleEvent method should not be called
	HandleEvent bool
}

EventResponse is returned from a handler's GetEventResponse method and contains information to be passed to the sender of the hook

type GenericEventHandler

type GenericEventHandler struct{}

GenericEventHandler is a simple event handler that does nothing

func NewGenericEventHandler

func NewGenericEventHandler() *GenericEventHandler

func (*GenericEventHandler) GetEventResponse

func (h *GenericEventHandler) GetEventResponse(event *github.Event) *EventResponse

GetEventResponse just returns a generic message. The hook was received but doing nothing in this case.

func (*GenericEventHandler) HandleEvent

func (h *GenericEventHandler) HandleEvent(event *github.Event)

HandleEvent does nothing

type PingEventHandler

type PingEventHandler struct{}

PingEventHandler responds to ping events from github https://developer.github.com/webhooks/#ping-event

func NewPingEventHandler

func NewPingEventHandler() *PingEventHandler

NewPingEventHandler creates an empty PingEventHandler

func (*PingEventHandler) GetEventResponse

func (h *PingEventHandler) GetEventResponse(event *github.Event) *EventResponse

GetEventResponse just returns a generic message. The hook was received but doing nothing in this case.

func (*PingEventHandler) HandleEvent

func (h *PingEventHandler) HandleEvent(event *github.Event)

HandleEvent does nothing

type PullRequestEventHandler

type PullRequestEventHandler struct {
	RepositoryConfig RepositoryConfig
	GithubClient     github.Client
	Openshift        openshift.OpenshiftClient
}

PullRequestEventHandler handles pull request events

func NewPullRequestEventHandler

func NewPullRequestEventHandler(event github.Event) *PullRequestEventHandler

NewPullRequestEventHandler creates a new event handler for pull requests

func (*PullRequestEventHandler) BuildCommentForRoute

func (h *PullRequestEventHandler) BuildCommentForRoute(routeName string) string

BuildCommentForRoute tries to get the url for the route and compiles a comment

func (*PullRequestEventHandler) CreateEnvironmentOnOpenshift

func (h *PullRequestEventHandler) CreateEnvironmentOnOpenshift(event *github.Event) (*openshift.NewAppOutput, error)

CreateEnvironmentOnOpenshift does everything necessary to create the environment on openshift

func (*PullRequestEventHandler) DeleteEnvironmentOnOpenshift

func (h *PullRequestEventHandler) DeleteEnvironmentOnOpenshift(labels *openshift.ObjectLabels) error

DeleteEnvironmentOnOpenshift deletes an environment on openshift based on the pull request number

func (*PullRequestEventHandler) GetEventResponse

func (h *PullRequestEventHandler) GetEventResponse(event *github.Event) *EventResponse

GetEventResponse validates the event and checks if it can be handled.

func (*PullRequestEventHandler) HandleActionOpened

func (h *PullRequestEventHandler) HandleActionOpened(event *github.Event) error

HandleActionOpened is called when we receive an opened or reopened event from Github

func (*PullRequestEventHandler) HandleEvent

func (h *PullRequestEventHandler) HandleEvent(event *github.Event)

HandleEvent handles a pull request event from github

func (*PullRequestEventHandler) PostCommentOnGithub

func (h *PullRequestEventHandler) PostCommentOnGithub(event *github.Event, body string) error

PostCommentOnGithub posts a comment on Github, based on data from the event

type RepositoryConfig

type RepositoryConfig struct {
	Enabled  bool   `yaml:"enabled"`  // Run actuator for this repo?
	Fullname string `yaml:"fullname"` // Full name of the repository. ex. ninech/actuator
	Exclude  string `yaml:"exclude"`  // Pattern to exclude branches. ex. ^master$
	Template string `yaml:"template"` // Defines the openshift template to apply
}

RepositoryConfig contains configuration for each repository for which events are being received.

type WebhookEngine

type WebhookEngine struct {
}

WebhookEngine represents the main struct for the webhook application

func NewWebhookEngine

func NewWebhookEngine(mode string) WebhookEngine

NewWebhookEngine builds a new webhook engine It takes a gin mode as argument

func (*WebhookEngine) GetRouter

func (e *WebhookEngine) GetRouter() *gin.Engine

GetRouter constructs the main web engine for the API server

type WebhookParser

type WebhookParser interface {
	ValidateAndParseWebhook(*http.Request) (interface{}, error)
}

WebhookParser defines the interface of a parser of incomming data

Jump to

Keyboard shortcuts

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