proxy

package
v0.0.0-...-9ac85d6 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2018 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// GHHeader is how we determine whether we are dealing with a GitHub webhook
	GHHeader = "User-Agent"
	// GHAgent is the prefix of the GHHeader
	GHAgent = "GitHub-Hookshot"
)
View Source
const (

	// ServiceName is name of service that we are trying to idle or unidle
	ServiceName = "jenkins"
)

Variables

Recorder to capture events

Functions

This section is empty.

Types

type CacheItem

type CacheItem struct {
	ClusterURL string
	NS         string
	Route      string
	Scheme     string
}

CacheItem represents a cache item consisting of cluster URL, namespace, route, scheme(HTTP, HTTPS etc).

func NewCacheItem

func NewCacheItem(ns string, scheme string, route string, clusterURL string) CacheItem

NewCacheItem creates an instance of cache item.

type Codebase

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

Codebase is an implementation of the codebase interface

func NewCodebase

func NewCodebase(wit wit.Service, tenant tenant.Service, repositoryCloneURL string, logger *log.Entry) *Codebase

NewCodebase gets an instance of

func (*Codebase) Namespace

func (c *Codebase) Namespace() (tenant.Namespace, error)

Namespace gives us details of user who owns given repository

type CodebaseService

type CodebaseService interface {
	Namespace(repositoryCloneURL string) (tenant.Namespace, error)
}

CodebaseService contains methods that deals with code repository and code hosting services

type GHHookStruct

type GHHookStruct struct {
	Repository struct {
		Name     string `json:"name"`
		FullName string `json:"full_name"`
		GitURL   string `json:"git_url"`
		CloneURL string `json:"clone_url"`
	} `json:"repository"`
}

GHHookStruct a simplified structure to get info from a webhook request

type Jenkins

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

Jenkins implements Jenkins interface

func GetJenkins

func GetJenkins(clusters map[string]string,
	pci *CacheItem,
	idler idler.Service,
	tenantClient tenant.Service,
	tokenData string,
	logger *log.Entry) (j *Jenkins, osioToken string, err error)

GetJenkins returns an intance of Jenkins struct

func (*Jenkins) Login

func (j *Jenkins) Login(osoToken string) (status int, cookie []*http.Cookie, err error)

Login to Jenkins with OSO token to get cookies

func (*Jenkins) Start

func (j *Jenkins) Start() (state idler.PodState, code int, err error)

Start unidles Jenkins only if it is idled and returns the state of the pod, the http status of calling unidle, and error if any

func (*Jenkins) State

func (j *Jenkins) State() (idler.PodState, error)

State returns state of Jenkins associated with given namespace

type JenkinsService

type JenkinsService interface {
	Login(osoToken string) (status int, cookie []*http.Cookie, err error)
	State() (idler.PodState, error)
	Start() (state idler.PodState, code int, err error)
}

JenkinsService talks to wit service, auth service, tenant service and various jenkins instances in order to perform task such as starting a jenkins, logging into one, get information for a jenkins instance such as its url, which namespace it belongs to, which cluster it belongs to etc

type Proxy

type Proxy struct {
	//TenantCache is used as a temporary cache to optimize number of requests
	//going to tenant and wit services
	TenantCache *cache.Cache

	//ProxyCache is used as a cache for session ids passed by Jenkins in cookies
	ProxyCache *cache.Cache
	// contains filtered or unexported fields
}

Proxy handles requests, verifies authentication and proxies to Jenkins. If the request comes from Github, it buffers it and replays if Jenkins is not available.

func New

func New(
	idler idler.Service,
	tenant tenant.Service,
	wit wit.Service,
	storageService storage.Store,
	config configuration.Configuration,
	clusters map[string]string) (Proxy, error)

New creates an instance of Proxy client

func NewMock

func NewMock(jenkinsState idler.PodState, ownedBy string) *Proxy

NewMock returns an instance of proxy object that uses mocked dependency services

func (*Proxy) Handle

func (p *Proxy) Handle(w http.ResponseWriter, r *http.Request)

Handle handles requests coming to the proxy and performs action based on the type of request and state of Jenkins.

func (*Proxy) HandleError

func (p *Proxy) HandleError(w http.ResponseWriter, err error, requestLogEntry *log.Entry)

HandleError creates a JSON response with a given error and writes it to ResponseWriter

func (*Proxy) OnErrorUIRequest

func (p *Proxy) OnErrorUIRequest(rw http.ResponseWriter, req *http.Request, code int) error

OnErrorUIRequest handles when there is an error while reverse proxy

func (*Proxy) ProcessBuffer

func (p *Proxy) ProcessBuffer()

ProcessBuffer is a loop running through buffered webhook requests trying to replay them

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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