github

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 23, 2026 License: Apache-2.0 Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildInstallURL

func BuildInstallURL(appSlug string, state string, redirectURI string) (string, error)

BuildInstallURL returns the GitHub App installation URL with an opaque state.

func NormalizeAppSlug

func NormalizeAppSlug(value string) (string, error)

NormalizeAppSlug validates the GitHub App slug used in install URLs.

func NormalizeBaseURL

func NormalizeBaseURL(value string) (string, error)

NormalizeBaseURL validates and canonicalizes the GitHub Enterprise base URL.

func ParsePrivateKey

func ParsePrivateKey(privateKeyPEM string) (*rsa.PrivateKey, error)

ParsePrivateKey parses a PEM-encoded RSA private key in PKCS#1 or PKCS#8 form.

func SignAppJWT

func SignAppJWT(creds AppCredentials, now time.Time) (string, error)

SignAppJWT signs a short-lived RS256 JWT accepted by GitHub App APIs.

func ValidatePATShape

func ValidatePATShape(token string) error

ValidatePATShape checks whether a token looks like a GitHub classic PAT.

func VerifyWebhookSignature

func VerifyWebhookSignature(secret string, payload []byte, signature string) bool

VerifyWebhookSignature verifies GitHub's X-Hub-Signature-256 value.

Types

type AppCredentials

type AppCredentials struct {
	AppID         int64
	AppSlug       string
	PrivateKeyPEM string
}

AppCredentials contains the non-tenant GitHub App credentials used by the hosted SaaS connector flow.

type CodeScanningAlert

type CodeScanningAlert struct {
	Number             int                       `json:"number"`
	State              string                    `json:"state"`
	Rule               CodeScanningRule          `json:"rule"`
	Tool               CodeScanningTool          `json:"tool"`
	MostRecentInstance CodeScanningAlertInstance `json:"most_recent_instance"`
	HTMLURL            string                    `json:"html_url"`
}

CodeScanningAlert is the GitHub API shape needed for repository finding ingestion.

type CodeScanningAlertInstance

type CodeScanningAlertInstance struct {
	Ref         string               `json:"ref"`
	AnalysisKey string               `json:"analysis_key"`
	Category    string               `json:"category"`
	State       string               `json:"state"`
	CommitSHA   string               `json:"commit_sha"`
	Message     CodeScanningMessage  `json:"message"`
	Location    CodeScanningLocation `json:"location"`
}

type CodeScanningLocation

type CodeScanningLocation struct {
	Path        string `json:"path"`
	StartLine   int    `json:"start_line"`
	EndLine     int    `json:"end_line"`
	StartColumn int    `json:"start_column"`
	EndColumn   int    `json:"end_column"`
}

type CodeScanningMessage

type CodeScanningMessage struct {
	Text string `json:"text"`
}

type CodeScanningRule

type CodeScanningRule struct {
	ID                    string   `json:"id"`
	Name                  string   `json:"name"`
	Severity              string   `json:"severity"`
	Description           string   `json:"description"`
	SecuritySeverityLevel string   `json:"security_severity_level"`
	Tags                  []string `json:"tags"`
}

type CodeScanningTool

type CodeScanningTool struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

type GitHubRateLimitState

type GitHubRateLimitState struct {
	Limit     int        `json:"limit,omitempty"`
	Remaining int        `json:"remaining,omitempty"`
	ResetAt   *time.Time `json:"reset_at,omitempty"`
}

GitHubRateLimitState captures the latest observed GitHub REST rate-limit headers for posture calls.

type InstallationEvent

type InstallationEvent struct {
	Action         string
	InstallationID int64
	AccountLogin   string
}

InstallationEvent is the subset of GitHub installation webhooks Identrail needs to bind and clean up GitHub App connectors.

func ParseInstallationEvent

func ParseInstallationEvent(payload []byte) (InstallationEvent, error)

ParseInstallationEvent extracts the action, installation id, and account.

type InstallationRepositoriesEvent

type InstallationRepositoriesEvent struct {
	Action              string
	InstallationID      int64
	AddedRepositories   []string
	RemovedRepositories []string
}

InstallationRepositoriesEvent is the subset of GitHub repository-selection webhooks needed to keep connector repository allowlists current.

func ParseInstallationRepositoriesEvent

func ParseInstallationRepositoriesEvent(payload []byte) (InstallationRepositoriesEvent, error)

ParseInstallationRepositoriesEvent extracts added and removed repositories from an installation_repositories webhook.

type InstallationToken

type InstallationToken struct {
	Token     string
	ExpiresAt time.Time
}

InstallationToken represents one GitHub App installation token response.

type InstallationTokenClient

type InstallationTokenClient struct {
	Credentials AppCredentials
	HTTPClient  *http.Client
	APIBaseURL  string
	Now         func() time.Time
	// contains filtered or unexported fields
}

InstallationTokenClient mints and caches installation tokens.

func (*InstallationTokenClient) Mint

func (c *InstallationTokenClient) Mint(ctx context.Context, installationID int64) (InstallationToken, error)

Mint returns a cached token unless it is close to expiry.

type InstallationTokenMinter

type InstallationTokenMinter interface {
	Mint(ctx context.Context, installationID int64) (InstallationToken, error)
}

InstallationTokenMinter mints GitHub App installation access tokens.

type PATValidationResult

type PATValidationResult struct {
	Login  string
	Scopes []string
}

PATValidationResult captures the minimum identity and scope proof for a PAT.

type PATValidator

type PATValidator struct {
	HTTPClient      *http.Client
	AllowedBaseURLs []string
}

PATValidator validates classic GitHub PATs against GitHub.com or GHES.

func (PATValidator) Validate

func (v PATValidator) Validate(ctx context.Context, baseURL string, token string) (PATValidationResult, error)

Validate confirms the token is accepted and has read-oriented repository scope.

func (PATValidator) ValidateGitHubPAT

func (v PATValidator) ValidateGitHubPAT(ctx context.Context, baseURL string, token string) (PATValidationResult, error)

ValidateGitHubPAT adapts PATValidator to the API service dependency.

type Repository

type Repository struct {
	FullName string `json:"full_name"`
	Private  bool   `json:"private"`
}

Repository describes the GitHub repository metadata Identrail needs for selection and scan target storage.

type RepositoryClient

type RepositoryClient struct {
	TokenClient InstallationTokenMinter
	HTTPClient  *http.Client
	APIBaseURL  string
	Now         func() time.Time
}

RepositoryClient lists repositories visible to one GitHub App installation.

func (RepositoryClient) CollectRepositoryPosture

func (c RepositoryClient) CollectRepositoryPosture(ctx context.Context, installationID int64, repository string) (RepositoryPosture, error)

CollectRepositoryPosture collects normalized security posture from GitHub API endpoints that require an installation token. Each endpoint contributes a check even when the setting is unavailable or permission-limited.

func (RepositoryClient) ListCodeScanningAlerts

func (c RepositoryClient) ListCodeScanningAlerts(ctx context.Context, installationID int64, repository string) ([]CodeScanningAlert, error)

ListCodeScanningAlerts returns all open GitHub code-scanning alerts for a repository.

func (RepositoryClient) ListInstallationRepositories

func (c RepositoryClient) ListInstallationRepositories(ctx context.Context, installationID int64) ([]Repository, error)

ListInstallationRepositories returns all repositories available to the installation, following GitHub pagination.

type RepositoryPosture

type RepositoryPosture struct {
	Repository     string                   `json:"repository"`
	InstallationID int64                    `json:"installation_id,omitempty"`
	CollectedAt    time.Time                `json:"collected_at"`
	Checks         []RepositoryPostureCheck `json:"checks"`
	RateLimit      *GitHubRateLimitState    `json:"rate_limit,omitempty"`
}

RepositoryPosture describes GitHub-hosted repository security settings that are not visible from git content alone.

type RepositoryPostureCheck

type RepositoryPostureCheck struct {
	ID       string                 `json:"id"`
	Category string                 `json:"category"`
	State    RepositoryPostureState `json:"state"`
	Reason   string                 `json:"reason,omitempty"`
	Summary  string                 `json:"summary"`
	Evidence map[string]any         `json:"evidence,omitempty"`
}

RepositoryPostureCheck is one normalized GitHub repository posture signal.

type RepositoryPostureState

type RepositoryPostureState string

RepositoryPostureState is a normalized posture state for one GitHub control.

const (
	RepositoryPostureStateSecure            RepositoryPostureState = "secure"
	RepositoryPostureStateInsecure          RepositoryPostureState = "insecure"
	RepositoryPostureStateUnavailable       RepositoryPostureState = "unavailable"
	RepositoryPostureStatePermissionLimited RepositoryPostureState = "permission_limited"
)

Jump to

Keyboard shortcuts

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