core

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: MIT Imports: 21 Imported by: 1

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 PrepareForToGetLabels added in v0.0.11

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

PrepareForToGetLabels 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 AgentLabel added in v0.0.11

type AgentLabel struct {
	CloudsCount                    int      `json:"cloudsCount"`
	Description                    string   `json:"description"`
	HasMoreThanOneJob              bool     `json:"hasMoreThanOneJob"`
	JobsCount                      int      `json:"jobsCount"`
	JobsWithLabelDefaultValue      []string `json:"jobsWithLabelDefaultValue"`
	JobsWithLabelDefaultValueCount int      `json:"jobsWithLabelDefaultValueCount"`
	Label                          string   `json:"label"`
	LabelURL                       string   `json:"labelURL"`
	NodesCount                     int      `json:"nodesCount"`
	PluginActiveForLabel           bool     `json:"pluginActiveForLabel"`
	TriggeredJobs                  []string `json:"triggeredJobs"`
	TriggeredJobsCount             int      `json:"triggeredJobsCount"`
}

AgentLabel represents a label object of the Jenkins agent

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) GetLabels added in v0.0.11

func (q *Client) GetLabels() (labelsRes *LabelsResponse, err error)

GetLabels returns the labels of all the Jenkins agents Read details from https://github.com/jenkinsci/label-linked-jobs-plugin

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() []interface{}
	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 []interface{}          `json:"errors"`
}

JSONResult represents the JSON result

func (JSONResult) GetErrors added in v0.0.10

func (r JSONResult) GetErrors() []interface{}

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      []interface{} `json:"errors"`
}

JenkinsfileResult represents the Jenkinsfile result

func (JenkinsfileResult) GetErrors added in v0.0.10

func (r JenkinsfileResult) GetErrors() []interface{}

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 LabelsResponse added in v0.0.11

type LabelsResponse struct {
	Status string       `json:"status"`
	Data   []AgentLabel `json:"data"`
}

LabelsResponse represents the response from the labels request

func (*LabelsResponse) GetLabels added in v0.0.11

func (l *LabelsResponse) GetLabels() (labels []string)

GetLabels returns the labels with string array format

type RequestBuilder added in v0.0.14

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

RequestBuilder is a helper for the HTTP request

func NewRequest added in v0.0.14

func NewRequest(api string, j *JenkinsCore) *RequestBuilder

NewRequest creates a HTTP request builder instance

func (*RequestBuilder) AcceptStatusCode added in v0.0.14

func (r *RequestBuilder) AcceptStatusCode(code int) *RequestBuilder

AcceptStatusCode accept status code

func (*RequestBuilder) AddHeader added in v0.0.14

func (r *RequestBuilder) AddHeader(key, val string) *RequestBuilder

AddHeader adds a header

func (*RequestBuilder) AsFormRequest added in v0.0.14

func (r *RequestBuilder) AsFormRequest() *RequestBuilder

AsFormRequest makes this request as a form request

func (*RequestBuilder) AsPostFormRequest added in v0.0.14

func (r *RequestBuilder) AsPostFormRequest() *RequestBuilder

AsPostFormRequest make this request as a POST form request

func (*RequestBuilder) Do added in v0.0.14

func (r *RequestBuilder) Do() (err error)

Do runs the HTTP request

func (*RequestBuilder) GetData added in v0.0.14

func (r *RequestBuilder) GetData() []byte

GetData returns the response data

func (*RequestBuilder) GetObject added in v0.0.14

func (r *RequestBuilder) GetObject(obj interface{}) error

GetObject parses the data to an interface

func (*RequestBuilder) RejectStatusCode added in v0.0.14

func (r *RequestBuilder) RejectStatusCode(code int) *RequestBuilder

RejectStatusCode reject specific status code

func (*RequestBuilder) WithMethod added in v0.0.14

func (r *RequestBuilder) WithMethod(method string) *RequestBuilder

WithMethod sets the HTTP request method

func (*RequestBuilder) WithPayload added in v0.0.14

func (r *RequestBuilder) WithPayload(payload io.Reader) *RequestBuilder

WithPayload sets the payload for the request

func (*RequestBuilder) WithPostMethod added in v0.0.14

func (r *RequestBuilder) WithPostMethod() *RequestBuilder

WithPostMethod sets the request method be POSt

func (*RequestBuilder) WithValues added in v0.0.14

func (r *RequestBuilder) WithValues(values url.Values) *RequestBuilder

WithValues sets the payload with values format

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