github

package
v1.0.0-beta.5 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderGithubSignature = "x-hub-signature-256"
	HeaderRunnerSignature = "x-deepsource-signature-256"
	HeaderRunnerID        = "x-deepsource-runner-id"
	HeaderAppID           = "x-deepsource-app-id"
	HeaderInstallationID  = "X-Installation-Id"

	HeaderContentType    = "Content-Type"
	HeaderAuthorization  = "Authorization"
	HeaderAccept         = "Accept"
	HeaderAcceptEncoding = "Accept-Encoding"

	HeaderValueGithubAccept = "application/vnd.github+json"
)

Variables

View Source
var (
	ErrInvalidSignature     = errors.New("invalid signature")
	ErrMandatoryArgsMissing = errors.New("mandatory args missing")
	ErrAppNotFound          = fmt.Errorf("app not found")
)
View Source
var (
	GithubURLAccessTokenFmt = "/app/installations/%s/access_tokens"
)

Functions

This section is empty.

Types

type APIRequest

type APIRequest struct {
	AppID          string
	InstallationID string
	HTTPRequest    *http.Request
}

func NewAPIRequest

func NewAPIRequest(c echo.Context) (*APIRequest, error)

func (*APIRequest) Validate

func (r *APIRequest) Validate() error

type APIService

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

func NewAPIService

func NewAPIService(appFactory *AppFactory, client *http.Client) *APIService

func (*APIService) Process

func (s *APIService) Process(req *APIRequest) (*http.Response, error)

type AccessTokenResponse

type AccessTokenResponse struct {
	Token string `json:"token"`
}

type App

type App struct {
	ID string

	// Github App configuration.
	AppID         string
	AppSlug       string
	WebhookSecret string
	BaseHost      url.URL
	APIHost       url.URL
	PrivateKey    *rsa.PrivateKey
}

func (*App) InstallationURL

func (a *App) InstallationURL() string

InstallationURL returns the URL to install the GitHub App.

func (*App) VerifyWebhookSignature

func (a *App) VerifyWebhookSignature(payload []byte, signature string) error

VerifyWebhookSignature verifies the signature of the webhook payload. (https://docs.github.com/en/developers/webhooks-and-events/securing-your-webhooks#validating-payloads-from-github)

type AppFactory

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

func NewAppFactory

func NewAppFactory(apps map[string]*App) *AppFactory

func (*AppFactory) GetApp

func (f *AppFactory) GetApp(appID string) *App

type Handler

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

func NewHandler

func NewHandler(
	webhookService *WebhookService,
	apiService *APIService,
	appFactory *AppFactory,
	_ *model.Runner,
	_ *model.DeepSource,
	httpClient *http.Client) (*Handler, error)

func (*Handler) AuthenticatedRemoteURL

func (h *Handler) AuthenticatedRemoteURL(appID, installationID string, srcURL string) (string, error)

func (*Handler) HandleAPI

func (h *Handler) HandleAPI(c echo.Context) error

func (*Handler) HandleInstallation

func (h *Handler) HandleInstallation(c echo.Context) error

HandleInstallation redirects the user to the installation page on Github.

func (*Handler) HandleWebhook

func (h *Handler) HandleWebhook(c echo.Context) error

HandleWebhook handles the webhook request from Github to DeepSource Cloud.

type InstallationClient

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

func NewInstallationClient

func NewInstallationClient(app *App, installationID string, client *http.Client) *InstallationClient

func (*InstallationClient) AccessToken

func (c *InstallationClient) AccessToken() (string, error)

AccessToken returns the Installation Access Token for the given installation ID and app. This token is used to authenticate requests to the GitHub API on behalf of an installation. (https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-an-installation-access-token-for-a-github-app)

func (*InstallationClient) ProxyURL

func (c *InstallationClient) ProxyURL(path string) *url.URL

ProxyURL returns the URL to proxy the request. When DeepSource Cloud sends a request to GitHub via the Runner, it is prefixed with "/apps/:app_id/api". This method strips this prefix and generates the actual GitHub API URL.

type InstallationRequest

type InstallationRequest struct {
	AppID string `param:"app_id"`
}

type WebhookRequest

type WebhookRequest struct {
	AppID       string
	Signature   string
	HTTPRequest *http.Request
}

func NewWebhookRequest

func NewWebhookRequest(c echo.Context) (*WebhookRequest, error)

func (*WebhookRequest) Validate

func (r *WebhookRequest) Validate() error

type WebhookService

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

func NewWebhookService

func NewWebhookService(appFactory *AppFactory, runner *model.Runner, deepsource *model.DeepSource, client *http.Client) *WebhookService

func (*WebhookService) Process

func (s *WebhookService) Process(req *WebhookRequest) (*http.Response, error)

Process processes the webhook request. It verifies the signature, adds a signature for the cloud server, and then proxies the request to the cloud.

Jump to

Keyboard shortcuts

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