githubapp

package
v0.0.0-...-e308f56 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package githubapp provides GitHub App authentication and token management.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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 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.

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

func (tm *TokenManager) GetTokenForOrg(ctx context.Context, org string) (string, error)

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) GetTokenForURL

func (tm *TokenManager) GetTokenForURL(ctx context.Context, url string) (string, error)

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.

Jump to

Keyboard shortcuts

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