githubauth

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT, MIT Imports: 26 Imported by: 0

Documentation

Overview

Package githubauth owns every GitHub credential used by gh-broker. Credentials are opaque outside this package and have no readback API.

Index

Constants

View Source
const APIVersion = "2026-03-10"

Variables

View Source
var (
	ErrWebhookInvalid   = errors.New("GitHub webhook is invalid")
	ErrWebhookSignature = errors.New("GitHub webhook signature is invalid")
)

Functions

func IsNotFound

func IsNotFound(err error) bool

func OpenUserCredentialStore

func OpenUserCredentialStore(stateDir string) (*credentialstore.Store, error)

OpenUserCredentialStore opens the broker-owned namespace reserved for internal GitHub App user credentials.

func StatusCode

func StatusCode(err error) (int, bool)

func UserCredentialStorePath

func UserCredentialStorePath(stateDir string) (string, error)

UserCredentialStorePath returns the state subtree whose ownership the local setup command must preserve for the broker service account.

Types

type API

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

func (*API) BranchProtected

func (a *API) BranchProtected(ctx context.Context, owner, repo, branch string) (bool, error)

func (*API) DefaultBranch

func (a *API) DefaultBranch(ctx context.Context, owner, repo string) (string, error)

type APIError

type APIError struct {
	Code       string
	StatusCode int
	RateReset  time.Time
}

func (APIError) Error

func (e APIError) Error() string

type Config

type Config struct {
	AppID                string
	AppPrivateKey        []byte
	AppClientID          string
	AppClientSecret      []byte
	DevelopmentToken     []byte
	DevelopmentTokenFile string
	APIBaseURL           *url.URL
	WebBaseURL           *url.URL
	HTTPClient           *http.Client
	StreamTimeout        time.Duration
	Store                *credentialstore.Store
	Now                  func() time.Time
	RefreshBefore        time.Duration
}

type Credential

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

Credential can authorize an upstream request without exposing its value.

func (*Credential) AuthorizeAPI

func (c *Credential) AuthorizeAPI(request *http.Request) error

func (*Credential) AuthorizeGit

func (c *Credential) AuthorizeGit(request *http.Request) error

func (*Credential) Metadata

func (c *Credential) Metadata() Metadata

type ExecutionResult

type ExecutionResult struct {
	StatusCode int
	Body       json.RawMessage
}

type Kind

type Kind string
const (
	KindAppJWT           Kind = "app-jwt"
	KindInstallation     Kind = "installation"
	KindUser             Kind = "user"
	KindDevelopmentToken Kind = "development-token" // #nosec G101 -- credential kind, not a credential.
)

type Manager

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

func New

func New(cfg Config) (*Manager, error)

func (*Manager) API

func (m *Manager) API(credential *Credential) (*API, error)

func (*Manager) CheckApp

func (m *Manager) CheckApp(ctx context.Context) error

func (*Manager) CredentialKind

func (m *Manager) CredentialKind() Kind

func (*Manager) EnableInstallation

func (m *Manager) EnableInstallation(installationID int64)

func (*Manager) EnrollUser

func (m *Manager) EnrollUser(ctx context.Context, enrollment UserEnrollment) error

func (*Manager) ExecuteGraphQL

func (m *Manager) ExecuteGraphQL(ctx context.Context, selector Metadata, document graphqlmanifest.Document, variables map[string]any) (ExecutionResult, error)

func (*Manager) ExecuteREST

func (m *Manager) ExecuteREST(ctx context.Context, selector Metadata, binding opbinding.Binding, target, arguments map[string]any) (ExecutionResult, error)

func (*Manager) ExecuteRESTDownload

func (m *Manager) ExecuteRESTDownload(ctx context.Context, selector Metadata, binding opbinding.Binding, target, arguments map[string]any) (*http.Response, error)

func (*Manager) ExecuteRESTRaw

func (m *Manager) ExecuteRESTRaw(ctx context.Context, selector Metadata, binding opbinding.Binding, target, arguments map[string]any) (ExecutionResult, error)

ExecuteRESTRaw returns one bounded upstream JSON result before projection. It is reserved for adapters that immediately move a credential field into an encrypted broker-owned slot.

func (*Manager) ExecuteRESTUpload

func (m *Manager) ExecuteRESTUpload(ctx context.Context, selector Metadata, binding opbinding.Binding, target, arguments map[string]any,
	source io.Reader, size int64, mediaType string) (ExecutionResult, error)

func (*Manager) InstallationCredential

func (m *Manager) InstallationCredential(ctx context.Context, installationID int64, repositoryIDs []int64, permissions map[string]string) (*Credential, error)

func (*Manager) InstallationForAccount

func (m *Manager) InstallationForAccount(ctx context.Context, account string) (Metadata, error)

func (*Manager) Installations

func (m *Manager) Installations(ctx context.Context) ([]int64, error)

func (*Manager) InvalidateInstallation

func (m *Manager) InvalidateInstallation(installationID int64, disabled bool)

func (*Manager) InvalidateUser

func (m *Manager) InvalidateUser(userID int64) error

func (*Manager) RepositoryCredential

func (m *Manager) RepositoryCredential(ctx context.Context, operation, owner, repo string) (*Credential, error)

func (*Manager) ResolveRepository

func (m *Manager) ResolveRepository(ctx context.Context, operation, owner, repo string) (Metadata, error)

func (*Manager) RevokeUser

func (m *Manager) RevokeUser(ctx context.Context, userID int64) error

func (*Manager) RotateUser

func (m *Manager) RotateUser(ctx context.Context, enrollment UserEnrollment) error

func (*Manager) SelectMetadata

func (m *Manager) SelectMetadata(ctx context.Context, descriptor opcatalog.Descriptor, target map[string]any, userID int64) (Metadata, error)

func (*Manager) UserCredential

func (m *Manager) UserCredential(ctx context.Context, userID int64) (*Credential, error)

func (*Manager) ValidateAuthenticatedUserTarget

func (m *Manager) ValidateAuthenticatedUserTarget(ctx context.Context, selector Metadata, target map[string]any) error

ValidateAuthenticatedUserTarget binds implicit /user endpoints to the identity represented by the selected credential.

type Metadata

type Metadata struct {
	Kind                  Kind
	InstallationID        int64
	RepositoryIDs         []int64
	Permissions           map[string]string
	AllowEmptyPermissions bool
	UserID                int64
	APIHost               string
	ExpiresAt             time.Time
}

type UserEnrollment

type UserEnrollment struct {
	UserID           int64     `json:"user_id"`
	Login            string    `json:"login"`
	AccessToken      []byte    `json:"access_token"`
	RefreshToken     []byte    `json:"refresh_token"`
	AccessExpiresAt  time.Time `json:"access_expires_at"`
	RefreshExpiresAt time.Time `json:"refresh_expires_at"`
}

func DecodeUserEnrollment

func DecodeUserEnrollment(data []byte) (UserEnrollment, error)

DecodeUserEnrollment decodes a bounded protected-file payload for the local setup command. Secret values are retained only in the returned byte slices.

type WebhookEvent

type WebhookEvent struct {
	Event                  string
	Delivery               string
	Action                 string
	InstallationID         int64
	Repository             string
	RevokedUserID          int64
	DisableInstallation    bool
	EnableInstallation     bool
	InvalidateInstallation bool
}

func ParseWebhook

func ParseWebhook(header http.Header, body []byte, secret []byte) (WebhookEvent, error)

Jump to

Keyboard shortcuts

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