types

package
v0.0.0-...-e28bd7b Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DefaultNatsClientID is a default NATS Client ID
	DefaultNatsClientID = "template-webhook-service"

	// DefaultMongoDBURL is a default MongoDB URL
	DefaultMongoDBURL = "mongodb://localhost:27017"
	// DefaultMongoDBName is a default MongoDB Name
	DefaultMongoDBName = "cacao_template_webhook"
	// DefaultWebhookMongoDBCollectionName is a default MongoDB Collection Name
	DefaultWebhookMongoDBCollectionName = "template_webhook"

	// TemplateWebhookIDPrefix is the prefix for XID for Template Webhook ID
	TemplateWebhookIDPrefix = "templatewebhook"
)

Variables

This section is empty.

Functions

func GenerateGithubWebhookSecretKey

func GenerateGithubWebhookSecretKey() (key string, keyBytes []byte)

GenerateGithubWebhookSecretKey generates secrey key for GitHub webhook

func GenerateGitlabWebhookToken

func GenerateGitlabWebhookToken() (token string, hash, salt []byte)

GenerateGitlabWebhookToken generates token.

func GithubWebhookSignatureVerify

func GithubWebhookSignatureVerify(key []byte, signatureHex string, requestBody []byte) bool

GithubWebhookSignatureVerify verify HMAC signature in GitHub webhook

func GitlabWebhookTokenCompare

func GitlabWebhookTokenCompare(tokenHex string, hash, salt []byte) (ok bool)

GitlabWebhookTokenCompare ...

func NewWebhookID

func NewWebhookID() common.ID

NewWebhookID ...

Types

type Config

type Config struct {
	// NATS
	NatsStanConfig messaging2.NatsStanMsgConfig

	// MongoDB
	MongoDBConfig                cacao_common_db.MongoDBConfig
	WebhookMongoDBCollectionName string

	LogLevel       string `envconfig:"LOG_LEVEL" default:"debug"`
	HTTPListenPort uint16 `envconfig:"HTTP_LISTEN_PORT" default:"8080"`
	// minimal interval between executing the same webhook, this is to prevent DoS from flooding of webhook request.
	MinTriggerIntervalSec uint16 `envconfig:"MIN_TRIGGER_INTERVAL" default:"60"`
}

Config is the configuration settings, which can be used by the Domain object or Adapters

func (*Config) Override

func (c *Config) Override()

Override overrides certain config

func (*Config) ProcessDefaults

func (c *Config) ProcessDefaults()

ProcessDefaults will take a Config object and process the config object further, including populating any null values

type GithubWebhookHeader

type GithubWebhookHeader struct {
	GitHubHookID                     string // X-GitHub-Hook-ID: The unique identifier of the webhook.
	GitHubEvent                      string // X-GitHub-Event: The name of the event that triggered the delivery.
	GitHubDelivery                   string // X-GitHub-Delivery: A globally unique identifier (GUID) to identify the delivery.
	HubSignature                     string //X-Hub-Signature: This header is sent if the webhook is configured with a secret. This is the HMAC hex digest of the request body, and is generated using the SHA-1 hash function and the secret as the HMAC key. X-Hub-Signature is provided for compatibility with existing integrations. We recommend that you use the more secure X-Hub-Signature-256 instead.
	HubSignature256                  string //X-Hub-Signature-256: This header is sent if the webhook is configured with a secret. This is the HMAC hex digest of the request body, and is generated using the SHA-256 hash function and the secret as the HMAC key. For more information, see "Validating webhook deliveries."
	UserAgent                        string //User-Agent: This header will always have the prefix GitHub-Hookshot/.
	GitHubHookInstallationTargetType string //X-GitHub-Hook-Installation-Target-Type: The type of resource where the webhook was created.
	GitHubHookInstallationTargetID   string //X-GitHub-Hook-Installation-Target-ID: The unique identifier of the resource where the webhook was created.
}

GithubWebhookHeader contains useful headers from GitHub webhook request

type GithubWebhookRequest

type GithubWebhookRequest struct {
	Action string `json:"action"`
	Issue  struct {
		URL    string `json:"url"`
		Number int    `json:"number"`
	} `json:"issue"`
	Repository struct {
		ID       int    `json:"id"`
		FullName string `json:"full_name"`
		Owner    struct {
			Login string `json:"login"`
			ID    int    `json:"id"`
		} `json:"owner"`
	} `json:"repository"`
	Sender struct {
		Login string `json:"login"`
		ID    int    `json:"id"`
	} `json:"sender"`
}

GithubWebhookRequest ... https://docs.github.com/en/webhooks/webhook-events-and-payloads#example-webhook-delivery

type GitlabWebhookHeader

type GitlabWebhookHeader struct {
	GitlabToken       string // X-Gitlab-Token
	GitlabInstance    string // X-Gitlab-Instance, e.g. "https://gitlab.com"
	GitlabEvent       string // X-Gitlab-Event: Push Hook
	GitlabWebhookUUID string // X-Gitlab-Webhook-UUID
	GitlabEventUUID   string // X-Gitlab-Event-UUID
}

GitlabWebhookHeader contains useful headers of the Gitlab webhook request https://docs.gitlab.com/ee/user/project/integrations/webhooks.html#delivery-headers

type GitlabWebhookRequest

type GitlabWebhookRequest struct {
	ObjectKind   string `json:"object_kind"`
	EventName    string `json:"event_name"`
	Before       string `json:"before"`
	After        string `json:"after"`
	Ref          string `json:"ref"`
	RefProtected bool   `json:"ref_protected"`
	CheckoutSha  string `json:"checkout_sha"`
	UserID       int    `json:"user_id"`
	UserName     string `json:"user_name"`
	UserUsername string `json:"user_username"`
	UserEmail    string `json:"user_email"`
	UserAvatar   string `json:"user_avatar"`
	ProjectID    int    `json:"project_id"`
	Project      struct {
		ID                int         `json:"id"`
		Name              string      `json:"name"`
		Description       string      `json:"description"`
		WebURL            string      `json:"web_url"`
		AvatarURL         interface{} `json:"avatar_url"`
		GitSSHURL         string      `json:"git_ssh_url"`
		GitHTTPURL        string      `json:"git_http_url"`
		Namespace         string      `json:"namespace"`
		VisibilityLevel   int         `json:"visibility_level"`
		PathWithNamespace string      `json:"path_with_namespace"`
		DefaultBranch     string      `json:"default_branch"`
		Homepage          string      `json:"homepage"`
		URL               string      `json:"url"`
		SSHURL            string      `json:"ssh_url"`
		HTTPURL           string      `json:"http_url"`
	} `json:"project"`
	Repository struct {
		Name            string `json:"name"`
		URL             string `json:"url"`
		Description     string `json:"description"`
		Homepage        string `json:"homepage"`
		GitHTTPURL      string `json:"git_http_url"`
		GitSSHURL       string `json:"git_ssh_url"`
		VisibilityLevel int    `json:"visibility_level"`
	} `json:"repository"`
	Commits []struct {
		ID        string    `json:"id"`
		Message   string    `json:"message"`
		Title     string    `json:"title"`
		Timestamp time.Time `json:"timestamp"`
		URL       string    `json:"url"`
		Author    struct {
			Name  string `json:"name"`
			Email string `json:"email"`
		} `json:"author"`
		Added    []string      `json:"added"`
		Modified []string      `json:"modified"`
		Removed  []interface{} `json:"removed"`
	} `json:"commits"`
	TotalCommitsCount int `json:"total_commits_count"`

	GitlabToken string `json:"-"` // X-Gitlab-Token header
}

GitlabWebhookRequest ... https://docs.gitlab.com/ee/user/project/integrations/webhook_events.html#push-events

type TemplateWebhook

type TemplateWebhook struct {
	WebhookID  common.ID                           `bson:"_id"`
	TemplateID common.ID                           `bson:"template_id"`
	Owner      string                              `bson:"owner"`
	Platform   service.TemplateWebhookPlatformType `bson:"platform"`
	Gitlab     TemplateWebhookGitlabConfig         `bson:"gitlab"`
	Github     TemplateWebhookGithubConfig         `bson:"github"`
	CreatedAt  time.Time                           `bson:"created_at"`
	// The last time the webhook is fully executed
	LastExecutedAt time.Time `bson:"last_executed_at"`
}

TemplateWebhook is the storage schema of template webhook

type TemplateWebhookGithubConfig

type TemplateWebhookGithubConfig struct {
	Key []byte `bson:"key"`
}

TemplateWebhookGithubConfig ...

type TemplateWebhookGitlabConfig

type TemplateWebhookGitlabConfig struct {
	SecretTokenHash []byte `bson:"secret_token_hash"`
	SecretTokenSalt []byte `bson:"secret_token_salt"`
}

TemplateWebhookGitlabConfig ...

Jump to

Keyboard shortcuts

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