Documentation ¶
Index ¶
Constants ¶
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 ¶
var ( ErrInvalidSignature = errors.New("invalid signature") ErrMandatoryArgsMissing = errors.New("mandatory args missing") ErrAppNotFound = fmt.Errorf("app not found") )
var (
GithubURLAccessTokenFmt = "/app/installations/%s/access_tokens"
)
Functions ¶
This section is empty.
Types ¶
type APIRequest ¶
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 ¶
InstallationURL returns the URL to install the GitHub App.
func (*App) JWT ¶
Generate a JWT token for the GitHub App. (https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-a-json-web-token-jwt-for-a-github-app)
func (*App) VerifyWebhookSignature ¶
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 (*Handler) HandleInstallation ¶
HandleInstallation redirects the user to the installation page on Github.
func (*Handler) HandleWebhook ¶
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 ¶
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.