webhook

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2021 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BadRequestCode        = "WH400"
	InternalServerErrCode = "WH500"
	OtherErrCode          = "WH600"
)

Variables

View Source
var (

	// ErrNoEventField event 消息中没有 'event' 字段
	ErrNoEventField = errors.New("not found 'event' field")
	// ErrInvalidEvent 'event' 字段内容不是 string 类型
	ErrInvalidEvent = errors.New("invalid 'event' type")
	// ErrNoFormat 在 fmtMap 没有对应的格式
	ErrNoFormat = errors.New("not found related format")
)

EXAMPLE pipeline event json

{
    "action": "B_CREATE",
    "applicationID": "178",
    "content": {
        "kind": "B_CREATE",
        "operator": "10672",
        "pipeline": {
            "applicationID": 178,
            "applicationName": "dice",
            "basePipelineID": 4847,
            "branch": "develop",
            "clusterName": "terminus-y",
            "commit": "bc6410f8e3282e6e5d667551013efac0ded79491",
            "commitDetail": {
                "author": "郑嘉涛",
                "comment": "Merge branch 'feature/org-switch' into 'develop'\n\nfeature: org switch\n\nSee merge request !1645",
                "email": "ef@terminus.io",
                "repo": "http://gittar.app.terminus.io/dcos-terminus/dice",
                "repoAbbr": "dcos-terminus/dice",
                "time": "2019-03-13T10:41:01+08:00"
            },
            "costTimeSec": -1,
            "cronID": null,
            "extra": {
                "callbackURLs": null,
                "configManageNamespaceOfSecrets": "pipeline-secrets-app-178-develop",
                "configManageNamespaceOfSecretsDefault": "pipeline-secrets-app-178-default",
                "cronTriggerTime": "0001-01-01T00:00:00Z",
                "diceWorkspace": "TEST",
                "isAutoRun": true,
                "submitUser": {
                    "avatar": "",
                    "id": 10672,
                    "name": "姜政冬"
                }
            },
            "id": 6461,
            "orgID": 2,
            "orgName": "terminus",
            "pipelineYml": "...",
            "pipelineYmlName": "pipeline.yml",
            "pipelineYmlSource": "content",
            "projectID": 70,
            "projectName": "dice",
            "snapshot": {},
            "source": "qa",
            "status": "Analyzed",
            "timeBegin": "0001-01-01T00:00:00Z",
            "timeCreated": "2019-03-13T10:43:47.945103124+08:00",
            "timeEnd": "0001-01-01T00:00:00Z",
            "timeUpdated": "2019-03-13T10:43:48.035938235+08:00",
            "triggerMode": "manual",
            "type": "normal"
        }
    },
    "env": "",
    "event": "pipeline",
    "orgID": "2",
    "projectID": "70",
    "timestamp": "2019-03-13 10:43:49"
}
View Source
var BadRequestErr = errors.New("bad request input")
View Source
var InternalServerErr = errors.New("internal server error")

Functions

func Format

func Format(eventContent interface{}) (string, error)

Format 格式化 'eventContent'

func MakeSureBuiltinHooks

func MakeSureBuiltinHooks(impl *WebHookImpl) error

MakeSureBuiltinHooks 创建默认 webhook (如果不存在)

Types

type CreateHookRequest

type CreateHookRequest = apistructs.CreateHookRequest

type EventLabel

type EventLabel = apistructs.EventHeader

type EventMessage

type EventMessage struct {
	Event         string `json:"event"`
	Action        string `json:"action"`
	OrgID         string `json:"orgID"`
	ProjectID     string `json:"projectID"`
	ApplicationID string `json:"applicationID"`
	Env           string `json:"env"`
	// content 结构跟具体 event 相关
	Content   json.RawMessage `json:"content"`
	TimeStamp string          `json:"timestamp"`
}

message which response to hooked url

func MkEventMessage

func MkEventMessage(label EventLabel, content []byte) EventMessage

func PingEvent

func PingEvent(org, project, application string, h Hook) (*EventMessage, error)

type Hook

type Hook = apistructs.Hook

type HookLocation

type HookLocation = apistructs.HookLocation

type ListHooksResponse

type ListHooksResponse = apistructs.WebhookListResponseData

type WebHookHTTP

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

func NewWebHookHTTP

func NewWebHookHTTP() (*WebHookHTTP, error)

func (*WebHookHTTP) CreateHook

func (w *WebHookHTTP) CreateHook(ctx context.Context, req *http.Request, vars map[string]string) (stypes.Responser, error)

org, project will be provided in request body

func (*WebHookHTTP) DeleteHook

func (w *WebHookHTTP) DeleteHook(ctx context.Context, req *http.Request, vars map[string]string) (stypes.Responser, error)

func (*WebHookHTTP) EditHook

func (w *WebHookHTTP) EditHook(ctx context.Context, req *http.Request, vars map[string]string) (stypes.Responser, error)

func (*WebHookHTTP) GetHTTPEndPoints

func (w *WebHookHTTP) GetHTTPEndPoints() []stypes.Endpoint

func (*WebHookHTTP) InspectHook

func (w *WebHookHTTP) InspectHook(ctx context.Context, req *http.Request, vars map[string]string) (stypes.Responser, error)

not require 'org' in query param, and it should return not found when found-hook's org not match orgID(in header)

func (*WebHookHTTP) ListHookEvents

func (w *WebHookHTTP) ListHookEvents(ctx context.Context, req *http.Request, vars map[string]string) (stypes.Responser, error)

func (*WebHookHTTP) ListHooks

func (w *WebHookHTTP) ListHooks(ctx context.Context, req *http.Request, vars map[string]string) (stypes.Responser, error)

func (*WebHookHTTP) PingHook

func (w *WebHookHTTP) PingHook(ctx context.Context, req *http.Request, vars map[string]string) (stypes.Responser, error)

type WebHookImpl

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

func NewWebHookImpl

func NewWebHookImpl() (*WebHookImpl, error)

func (*WebHookImpl) CreateHook

func (w *WebHookImpl) CreateHook(realOrg string, h CreateHookRequest) (CreateHookResponse, error)

func (*WebHookImpl) DeleteHook

func (w *WebHookImpl) DeleteHook(realOrg, id string) error

func (*WebHookImpl) EditHook

func (w *WebHookImpl) EditHook(realOrg, id string, e EditHookRequest) (EditHookResponse, error)

func (*WebHookImpl) InspectHook

func (w *WebHookImpl) InspectHook(realOrg, id string) (InspectHookResponse, error)

func (*WebHookImpl) ListHooks

func (w *WebHookImpl) ListHooks(location HookLocation) (ListHooksResponse, error)

ListHooks 列出符合 location 的 hook 列表。

func (*WebHookImpl) PingHook

func (w *WebHookImpl) PingHook(realOrg, id string) error

func (*WebHookImpl) SearchHooks

func (w *WebHookImpl) SearchHooks(location HookLocation, event string) []Hook

search hooks which include 'event' and is 'active'

Jump to

Keyboard shortcuts

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