core

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2022 License: MIT Imports: 21 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

AsFormRequest is the fixed header for the form request purpose

View Source
var Logger *zap.Logger

Functions

func PrepareCancelQueue

func PrepareCancelQueue(roundTripper *mhttp.MockRoundTripper, rootURL, user, passwd string)

PrepareCancelQueue only for test

func PrepareCommonPost

func PrepareCommonPost(request *http.Request, responseBody string, roundTripper *mhttp.MockRoundTripper, user, passwd, rootURL string) (
	response *http.Response)

PrepareCommonPost only for test

func PrepareCommonPostWithResponseCode added in v0.0.8

func PrepareCommonPostWithResponseCode(request *http.Request, responseBody string, responseCode int, roundTripper *mhttp.MockRoundTripper, user, passwd, rootURL string) (
	response *http.Response)

PrepareCommonPostWithResponseCode only for test

func PrepareFor500InstalledPluginList

func PrepareFor500InstalledPluginList(roundTripper *mhttp.MockRoundTripper, rootURL string, depth int) (
	request *http.Request, response *http.Response)

PrepareFor500InstalledPluginList only for test

func PrepareForCancelShutdown

func PrepareForCancelShutdown(roundTripper *mhttp.MockRoundTripper, rootURL, user, password string, cancel bool)

PrepareForCancelShutdown only for test

func PrepareForEmptyAvaiablePluginList

func PrepareForEmptyAvaiablePluginList(roundTripper *mhttp.MockRoundTripper, rootURL string) (
	request *http.Request, response *http.Response)

PrepareForEmptyAvaiablePluginList only for test

func PrepareForEmptyInstalledPluginList

func PrepareForEmptyInstalledPluginList(roundTripper *mhttp.MockRoundTripper, rootURL string, depth int) (
	request *http.Request, response *http.Response)

PrepareForEmptyInstalledPluginList only for test

func PrepareForGetIdentity

func PrepareForGetIdentity(roundTripper *mhttp.MockRoundTripper, rootURL, user, password string)

PrepareForGetIdentity only for test

func PrepareForGetIssuer

func PrepareForGetIssuer(roundTripper *mhttp.MockRoundTripper, rootURL, user, password string) (
	request *http.Request, response *http.Response)

PrepareForGetIssuer only for test

func PrepareForGetIssuerWith500

func PrepareForGetIssuerWith500(roundTripper *mhttp.MockRoundTripper, rootURL, user, password string)

PrepareForGetIssuerWith500 only for test

func PrepareForInstallPlugin

func PrepareForInstallPlugin(roundTripper *mhttp.MockRoundTripper, rootURL, pluginName, user, passwd string)

PrepareForInstallPlugin only for test

func PrepareForInstallPluginWithCode

func PrepareForInstallPluginWithCode(roundTripper *mhttp.MockRoundTripper,
	statusCode int, rootURL, pluginName, user, passwd string) (response *http.Response)

PrepareForInstallPluginWithCode only for test

func PrepareForInstallPluginWithVersion

func PrepareForInstallPluginWithVersion(roundTripper *mhttp.MockRoundTripper, rootURL, pluginName, version, user, passwd string)

PrepareForInstallPluginWithVersion only for test

func PrepareForManyAvaiablePlugin

func PrepareForManyAvaiablePlugin(roundTripper *mhttp.MockRoundTripper, rootURL string) (
	request *http.Request, response *http.Response)

PrepareForManyAvaiablePlugin only for test

func PrepareForManyInstalledPlugins

func PrepareForManyInstalledPlugins(roundTripper *mhttp.MockRoundTripper, rootURL string, depth int) (
	request *http.Request, response *http.Response)

PrepareForManyInstalledPlugins only for test

func PrepareForNoAvailablePlugins

func PrepareForNoAvailablePlugins(roundTripper *mhttp.MockRoundTripper, rootURL string) (
	requestCenter *http.Request, responseCenter *http.Response)

PrepareForNoAvailablePlugins only for the test case

func PrepareForOneAvaiablePlugin

func PrepareForOneAvaiablePlugin(roundTripper *mhttp.MockRoundTripper, rootURL string) (
	request *http.Request, response *http.Response)

PrepareForOneAvaiablePlugin only for test

func PrepareForPipelineJob

func PrepareForPipelineJob(roundTripper *mhttp.MockRoundTripper, rootURL, user, passwd string) (
	request *http.Request, response *http.Response)

PrepareForPipelineJob only for test

func PrepareForRequest500UpdateCenter

func PrepareForRequest500UpdateCenter(roundTripper *mhttp.MockRoundTripper, rootURL string) (
	requestCenter *http.Request, responseCenter *http.Response)

PrepareForRequest500UpdateCenter only for the test case

func PrepareForRequestUpdateCenter

func PrepareForRequestUpdateCenter(roundTripper *mhttp.MockRoundTripper, rootURL string) (
	requestCenter *http.Request, responseCenter *http.Response)

PrepareForRequestUpdateCenter only for the test case

func PrepareForShutdown

func PrepareForShutdown(roundTripper *mhttp.MockRoundTripper, rootURL, user, password string, safe bool)

PrepareForShutdown only for test

func PrepareForToJSON added in v0.0.10

func PrepareForToJSON(roundTripper *mhttp.MockRoundTripper, rootURL, user, password string)

PrepareForToJSON only for test

func PrepareForToJenkinsfile added in v0.0.10

func PrepareForToJenkinsfile(roundTripper *mhttp.MockRoundTripper, rootURL, user, password string)

PrepareForToJenkinsfile only for test

func PrepareForUninstallPlugin

func PrepareForUninstallPlugin(roundTripper *mhttp.MockRoundTripper, rootURL, pluginName string) (
	request *http.Request, response *http.Response, requestCrumb *http.Request, responseCrumb *http.Response)

PrepareForUninstallPlugin only for test

func PrepareForUninstallPluginWith500

func PrepareForUninstallPluginWith500(roundTripper *mhttp.MockRoundTripper, rootURL, pluginName string) (
	request *http.Request, response *http.Response, requestCrumb *http.Request, responseCrumb *http.Response)

PrepareForUninstallPluginWith500 only for test

func PrepareForUpdatePipelineJob

func PrepareForUpdatePipelineJob(roundTripper *mhttp.MockRoundTripper, rootURL, script, user, password string)

PrepareForUpdatePipelineJob only for test

func PrepareForUploadPlugin

func PrepareForUploadPlugin(roundTripper *mhttp.MockRoundTripper, rootURL string) (
	request *http.Request, response *http.Response, requestCrumb *http.Request, responseCrumb *http.Response)

PrepareForUploadPlugin only for test

func PrepareGetQueue

func PrepareGetQueue(roundTripper *mhttp.MockRoundTripper, rootURL, user, passwd string)

PrepareGetQueue only for test

func PrepareRestart

func PrepareRestart(roundTripper *mhttp.MockRoundTripper, rootURL, user, password string, statusCode int)

PrepareRestart only for test

func PrepareRestartDirectly

func PrepareRestartDirectly(roundTripper *mhttp.MockRoundTripper, rootURL, user, password string, statusCode int)

PrepareRestartDirectly only for test

func SetLanguage

func SetLanguage(lan string)

SetLanguage set the language

func SetLogger

func SetLogger(zapLogger *zap.Logger)

SetLogger set a global Logger

Types

type Client

type Client struct {
	JenkinsCore
}

Client hold the client of Jenkins core

func (*Client) GetIdentity

func (q *Client) GetIdentity() (identity JenkinsIdentity, err error)

GetIdentity returns the identity of a Jenkins

func (*Client) PrepareShutdown

func (q *Client) PrepareShutdown(cancel bool) (err error)

PrepareShutdown Put Jenkins in a Quiet mode, in preparation for a restart. In that mode Jenkins don’t start any build

func (*Client) Restart

func (q *Client) Restart() (err error)

Restart will send the restart request

func (*Client) RestartDirectly

func (q *Client) RestartDirectly() (err error)

RestartDirectly restart Jenkins directly

func (*Client) Shutdown

func (q *Client) Shutdown(safe bool) (err error)

Shutdown puts Jenkins into the quiet mode, wait for existing builds to be completed, and then shut down Jenkins

func (*Client) ToJSON added in v0.0.10

func (q *Client) ToJSON(jenkinsfile string) (result GenericResult, err error)

ToJSON turns a Jenkinsfile to JSON format Read details from https://github.com/jenkinsci/pipeline-model-definition-plugin/blob/master/EXTENDING.md

func (*Client) ToJenkinsfile added in v0.0.10

func (q *Client) ToJenkinsfile(data string) (result GenericResult, err error)

ToJenkinsfile converts a JSON format data to Jenkinsfile Read details from https://github.com/jenkinsci/pipeline-model-definition-plugin/blob/master/EXTENDING.md

type GenericResult added in v0.0.10

type GenericResult interface {
	GetResult() string
	GetErrors() []string
	GetStatus() string
}

GenericResult represents a generic result interface

type JSONResult added in v0.0.10

type JSONResult struct {
	Result string                 `json:"result"`
	JSON   map[string]interface{} `json:"json"`
	Errors []string               `json:"errors"`
}

JSONResult represents the JSON result

func (JSONResult) GetErrors added in v0.0.10

func (r JSONResult) GetErrors() []string

GetErrors returns the errors

func (JSONResult) GetResult added in v0.0.10

func (r JSONResult) GetResult() string

GetResult returns the result of this object

func (JSONResult) GetStatus added in v0.0.10

func (r JSONResult) GetStatus() string

GetStatus returns the status

type JenkinsCore

type JenkinsCore struct {
	JenkinsCrumb
	Timeout            time.Duration
	URL                string
	InsecureSkipVerify bool
	UserName           string
	Token              string
	Proxy              string
	ProxyAuth          string

	Debug        bool
	Output       io.Writer
	RoundTripper http.RoundTripper
}

JenkinsCore core information of Jenkins

func (*JenkinsCore) AuthHandle

func (j *JenkinsCore) AuthHandle(request *http.Request) (err error)

AuthHandle takes care of the auth

func (*JenkinsCore) CrumbHandle

func (j *JenkinsCore) CrumbHandle(request *http.Request) error

CrumbHandle handle crum with http request

func (*JenkinsCore) ErrorHandle

func (j *JenkinsCore) ErrorHandle(statusCode int, data []byte) (err error)

ErrorHandle handles the error cases

func (*JenkinsCore) GetClient

func (j *JenkinsCore) GetClient() (client *http.Client)

GetClient get the default http Jenkins client

func (*JenkinsCore) GetCrumb

func (j *JenkinsCore) GetCrumb() (crumbIssuer *JenkinsCrumb, err error)

GetCrumb get the crumb from Jenkins

func (*JenkinsCore) PermissionError

func (j *JenkinsCore) PermissionError(statusCode int) (err error)

PermissionError handles the no permission

func (*JenkinsCore) ProxyHandle

func (j *JenkinsCore) ProxyHandle(request *http.Request)

ProxyHandle takes care of the proxy setting

func (*JenkinsCore) Request

func (j *JenkinsCore) Request(method, api string, headers map[string]string, payload io.Reader) (
	statusCode int, data []byte, err error)

Request make a common request

func (*JenkinsCore) RequestWithData

func (j *JenkinsCore) RequestWithData(method, api string, headers map[string]string,
	payload io.Reader, successCode int, obj interface{}) (err error)

RequestWithData requests the api and parse the data into an interface

func (*JenkinsCore) RequestWithResponse

func (j *JenkinsCore) RequestWithResponse(method, api string, headers map[string]string, payload io.Reader) (
	response *http.Response, err error)

RequestWithResponse make a common request

func (*JenkinsCore) RequestWithResponseHeader

func (j *JenkinsCore) RequestWithResponseHeader(method, api string, headers map[string]string, payload io.Reader, obj interface{}) (
	response *http.Response, err error)

RequestWithResponseHeader make a common request

func (*JenkinsCore) RequestWithoutData

func (j *JenkinsCore) RequestWithoutData(method, api string, headers map[string]string,
	payload io.Reader, successCode int) (statusCode int, err error)

RequestWithoutData requests the api without handling data

type JenkinsCrumb

type JenkinsCrumb struct {
	CrumbRequestField string
	Crumb             string
}

JenkinsCrumb crumb for Jenkins

type JenkinsIdentity

type JenkinsIdentity struct {
	Fingerprint   string
	PublicKey     string
	SystemMessage string
}

JenkinsIdentity belongs to a Jenkins

type JenkinsfileResult added in v0.0.10

type JenkinsfileResult struct {
	Result      string   `json:"result"`
	Jenkinsfile string   `json:"jenkinsfile"`
	Errors      []string `json:"errors"`
}

JenkinsfileResult represents the Jenkinsfile result

func (JenkinsfileResult) GetErrors added in v0.0.10

func (r JenkinsfileResult) GetErrors() []string

GetErrors returns the errors

func (JenkinsfileResult) GetResult added in v0.0.10

func (r JenkinsfileResult) GetResult() string

GetResult returns the result

func (JenkinsfileResult) GetStatus added in v0.0.10

func (r JenkinsfileResult) GetStatus() string

GetStatus returns the status

type RequestMatcher

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

RequestMatcher to match the http request

func NewRequestMatcher

func NewRequestMatcher(request *http.Request) *RequestMatcher

NewRequestMatcher create a request matcher will match request method and request path

func NewVerboseRequestMatcher

func NewVerboseRequestMatcher(request *http.Request) *RequestMatcher

NewVerboseRequestMatcher create a verbose request matcher will match request method and request path

func (*RequestMatcher) Matches

func (matcher *RequestMatcher) Matches(x interface{}) bool

Matches returns a matcher with given function

func (*RequestMatcher) String

func (matcher *RequestMatcher) String() string

String returns the text of current object

func (*RequestMatcher) WithBody

func (matcher *RequestMatcher) WithBody() *RequestMatcher

WithBody returns a matcher with body

func (*RequestMatcher) WithQuery

func (matcher *RequestMatcher) WithQuery() *RequestMatcher

WithQuery returns a matcher with query

type Result added in v0.0.10

type Result struct {
	Status string        `json:"status"`
	Data   GenericResult `json:"data"`
}

Result represents a generic result

Jump to

Keyboard shortcuts

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