webhook

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Overview

Package webhook is the base webhook server for a github app's events specific to queued workflow jobs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Environment                   string        `env:"ENVIRONMENT,default=production"`
	GitHubAPIBaseURL              string        `env:"GITHUB_API_BASE_URL,default=https://api.github.com"`
	GitHubAppID                   string        `env:"GITHUB_APP_ID,required"`
	GitHubWebhookKeyMountPath     string        `env:"WEBHOOK_KEY_MOUNT_PATH,required"`
	GitHubWebhookKeyName          string        `env:"WEBHOOK_KEY_NAME,required"`
	KMSAppPrivateKeyID            string        `env:"KMS_APP_PRIVATE_KEY_ID,required"`
	Port                          string        `env:"PORT,default=8080"`
	RunnerExecutionTimeoutSeconds string        `env:"RUNNER_EXECUTION_TIMEOUT_SECONDS,default=3600"`
	RunnerIdleTimeoutSeconds      string        `env:"RUNNER_IDLE_TIMEOUT_SECONDS,default=300"`
	RunnerImageName               string        `env:"RUNNER_IMAGE_NAME,default=default-runner"`
	RunnerImageTag                string        `env:"RUNNER_IMAGE_TAG,default=latest"`
	RunnerLocation                string        `env:"RUNNER_LOCATION,required"`
	RunnerProjectID               string        `env:"RUNNER_PROJECT_ID,required"`
	RunnerRepositoryID            string        `env:"RUNNER_REPOSITORY_ID,required"`
	RunnerServiceAccount          string        `env:"RUNNER_SERVICE_ACCOUNT,required"`
	ExtraRunnerCount              string        `env:"EXTRA_RUNNER_COUNT,default=0"`
	RunnerWorkerPoolID            string        `env:"RUNNER_WORKER_POOL_ID"`
	E2ETestRunID                  string        `env:"E2ETestRunID"`
	RunnerLabel                   string        `env:"RUNNER_LABEL,default=self-hosted"`
	EnableSelfHostedLabel         bool          `env:"ENABLE_SELF_HOSTED_LABEL,default=false"`
	MaxRetryAttempts              int           `env:"MAX_RETRY_ATTEMPTS,default=3"`
	BackoffInitialDelay           time.Duration `env:"BACKOFF_INITIAL_DELAY,default=500ms"`
}

Config defines the set of environment variables required for running the webhook service.

func NewConfig

func NewConfig(ctx context.Context) (*Config, error)

NewConfig creates a new Config from environment variables.

func (*Config) ToFlags

func (cfg *Config) ToFlags(set *cli.FlagSet) *cli.FlagSet

ToFlags binds the config to the cli.FlagSet and returns it.

func (*Config) Validate

func (cfg *Config) Validate() error

Validate validates the webhook config after load.

type FileReader

type FileReader interface {
	ReadFile(filename string) ([]byte, error)
}

FileReader can read a file and return the content.

func NewOSFileReader

func NewOSFileReader() FileReader

Provdes an instance of a FileReader.

type KeyManagement

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

KeyManagement provides a client and dataset identifiers.

func NewKeyManagement

func NewKeyManagement(ctx context.Context, opts ...option.ClientOption) (*KeyManagement, error)

NewKeyManagementClient creates a new instance of a KMS client.

func (*KeyManagement) Close

func (km *KeyManagement) Close() error

Close releases any resources held by the KeyManagement client.

func (*KeyManagement) CreateSigner

func (km *KeyManagement) CreateSigner(ctx context.Context, kmsAppPrivateKeyID string) (*gcpkms.Signer, error)

CreateSigner leverages the gcpkms package to create a signer.

type KeyManagementClient

type KeyManagementClient interface {
	Close() error
	CreateSigner(ctx context.Context, kmsAppPrivateKeyID string) (*gcpkms.Signer, error)
}

KeyManagementClient adheres to the interaction the webhook service has with a subset of Key Management APIs.

type MockFileReader

type MockFileReader struct {
	ReadFileMock *ReadFileResErr
}

func (*MockFileReader) ReadFile

func (m *MockFileReader) ReadFile(filename string) ([]byte, error)

type MockKMSClient

type MockKMSClient struct{}

MockKMSClient is a mock for the KeyManagementClient interface.

func (*MockKMSClient) Close

func (m *MockKMSClient) Close() error

Close implements the KeyManagementClient interface.

func (*MockKMSClient) CreateSigner

func (m *MockKMSClient) CreateSigner(ctx context.Context, kmsAppPrivateKeyID string) (*gcpkms.Signer, error)

CreateSigner implements the KeyManagementClient interface.

type OSFileReader

type OSFileReader struct{}

OSFileReader implements FileReader using the os package.

func (OSFileReader) ReadFile

func (o OSFileReader) ReadFile(filename string) ([]byte, error)

ReadFile reads a file and returns its content.

type ReadFileResErr

type ReadFileResErr struct {
	Res []byte
	Err error
}

type Server

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

Server provides the server implementation.

func NewServer

func NewServer(ctx context.Context, h *renderer.Renderer, cfg *Config, wco *WebhookClientOptions) (*Server, error)

NewServer creates a new HTTP server implementation that will handle receiving webhook payloads.

func (*Server) Close

func (s *Server) Close() error

Close handles the graceful shutdown of the webhook server.

func (*Server) Routes

func (s *Server) Routes(ctx context.Context) http.Handler

Routes creates a ServeMux for all the routes that this Router supports.

type WebhookClientOptions

type WebhookClientOptions struct {
	CloudBuildClientOpts    []option.ClientOption
	KeyManagementClientOpts []option.ClientOption

	OSFileReaderOverride        FileReader
	CloudBuildClientOverride    cloudbuild.Client
	GitHubClientOverride        gh.Client
	KeyManagementClientOverride KeyManagementClient
}

WebhookClientOptions encapsulate client config options as well as dependency implementation overrides.

Jump to

Keyboard shortcuts

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