Documentation
¶
Overview ¶
Package githubapp provides GitHub App authentication and token management.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewAPIClient ¶ added in v0.6.0
NewAPIClient copies a client and adds API call counts and low-quota warnings.
Types ¶
type Config ¶
type Config struct {
AppID string `hcl:"app-id,optional" help:"GitHub App ID"`
PrivateKeyPath string `hcl:"private-key-path,optional" help:"Path to GitHub App private key (PEM format)"`
Installations map[string]string `hcl:"installations,optional" help:"Deprecated: installations are now discovered dynamically via the GitHub API"`
FallbackOrg string `` /* 147-byte string literal not displayed */
}
Config represents the configuration for a single GitHub App.
type JWTGenerator ¶
type JWTGenerator struct {
// contains filtered or unexported fields
}
func NewJWTGenerator ¶
func NewJWTGenerator(appID, privateKeyPath string, expiration time.Duration) (*JWTGenerator, error)
func (*JWTGenerator) GenerateJWT ¶
func (g *JWTGenerator) GenerateJWT() (string, error)
type RateLimitPoller ¶ added in v0.6.0
type RateLimitPoller struct {
// contains filtered or unexported fields
}
RateLimitPoller samples the primary API budgets of known App installations.
func NewRateLimitPoller ¶ added in v0.6.0
func NewRateLimitPoller(manager *TokenManager, interval time.Duration) *RateLimitPoller
NewRateLimitPoller uses a one-minute interval when interval is nonpositive.
type TokenCacheConfig ¶
type TokenCacheConfig struct {
RefreshBuffer time.Duration // How early to refresh before expiration
JWTExpiration time.Duration // GitHub allows max 10 minutes
}
TokenCacheConfig configures token caching behavior.
func DefaultTokenCacheConfig ¶
func DefaultTokenCacheConfig() TokenCacheConfig
DefaultTokenCacheConfig returns default token cache configuration. RefreshBuffer must exceed the longest subprocess that bakes a token into its environment, so a token can't expire mid-call (GitHub App tokens have a fixed 1 h TTL).
type TokenManager ¶
type TokenManager struct {
// contains filtered or unexported fields
}
TokenManager manages GitHub App installation tokens across one or more apps.
func NewTokenManagerForTest ¶
func NewTokenManagerForTest(t *testing.T, configs []Config, logger *slog.Logger, apiBase string, httpClient *http.Client) *TokenManager
NewTokenManagerForTest creates a TokenManager with a custom API base URL and HTTP client for testing.
func (*TokenManager) GetTokenForOrg ¶
GetTokenForOrg returns an installation token for the given GitHub organization. It dynamically discovers the installation ID via the GitHub API on first use, caches the result, and falls back to the fallback org's token for orgs where the app is not installed.
func (*TokenManager) GetTokenForOrgWithOwner ¶ added in v0.6.0
func (tm *TokenManager) GetTokenForOrgWithOwner(ctx context.Context, org string) (string, string, error)
GetTokenForOrgWithOwner also returns the owner whose installation minted the token.
func (*TokenManager) GetTokenForURL ¶
GetTokenForURL extracts the org from a GitHub URL and returns an installation token.
type TokenManagerProvider ¶
type TokenManagerProvider func() (*TokenManager, error)
TokenManagerProvider is a function that lazily creates a singleton TokenManager.
func NewTokenManagerProvider ¶
func NewTokenManagerProvider(configs []Config, logger *slog.Logger) TokenManagerProvider
NewTokenManagerProvider creates a provider that lazily initializes a TokenManager from one or more GitHub App configurations.