Help us shape the future of Go! Take the 2026 Go Developer Survey

config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const CurrentConfigVersion = "1"

CurrentConfigVersion is the latest configuration schema version

Variables

View Source
var (
	ErrConfigNotExists  = errors.New("configuration file not found: ")
	ErrConfigInvalid    = errors.New("invalid configuration: ")
	ErrConfigUnreadable = errors.New("failed to read configuration file: ")
	ErrConfigUnparsable = errors.New("failed to parse configuration: ")
)

Common errors returned by the loader

View Source
var (
	ErrNoGitHubAppDefined = errors.New("at least one github_app or pat is required")
)

Common errors returned by config

Functions

func ConfigExists

func ConfigExists(configPath string) bool

ConfigExists checks if a configuration file exists at the given path

func OutputJSON

func OutputJSON(w io.Writer, apps []GitHubApp) error

OutputJSON outputs apps as JSON

func OutputYAML

func OutputYAML(w io.Writer, apps []GitHubApp) error

OutputYAML outputs apps as YAML

Types

type Config

type Config struct {
	Version    string                `yaml:"version" json:"version"`
	GitHubApps []GitHubApp           `yaml:"github_apps" json:"github_apps"`
	PATs       []PersonalAccessToken `yaml:"pats,omitempty" json:"pats,omitempty"`
}

Config represents the GitHub App authentication configuration

func Load

func Load() (*Config, error)

Load loads configuration using the default loader

func LoadOrCreate

func LoadOrCreate() (*Config, error)

LoadOrCreate loads existing configuration or creates a new one

func (*Config) AddOrUpdateApp

func (c *Config) AddOrUpdateApp(app *GitHubApp)

AddOrUpdateApp adds a new app or updates an existing one

func (*Config) AddOrUpdatePAT

func (c *Config) AddOrUpdatePAT(pat *PersonalAccessToken)

AddOrUpdatePAT adds a new PAT or updates an existing one

func (*Config) GetApp

func (c *Config) GetApp(appID int64) (*GitHubApp, error)

GetApp finds an app by ID

func (*Config) GetByPriority

func (c *Config) GetByPriority() []GitHubApp

GetByPriority returns GitHub Apps sorted by priority (highest first)

func (*Config) RemoveApp

func (c *Config) RemoveApp(appID int64) bool

RemoveApp removes an app by ID

func (*Config) RemovePAT

func (c *Config) RemovePAT(name string) bool

RemovePAT removes a PAT by name

func (*Config) Save

func (c *Config) Save() error

Save saves the configuration to the default location

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the configuration

type GitHubApp

type GitHubApp struct {
	Name             string             `yaml:"name" json:"name"`
	AppID            int64              `yaml:"app_id,omitempty" json:"app_id,omitempty"`
	ClientID         string             `yaml:"client_id,omitempty" json:"client_id,omitempty"`
	InstallationID   int64              `yaml:"installation_id" json:"installation_id"`
	PrivateKeyPath   string             `yaml:"private_key_path,omitempty" json:"private_key_path,omitempty"`
	PrivateKeySource PrivateKeySource   `yaml:"private_key_source,omitempty" json:"private_key_source,omitempty"`
	Patterns         []string           `yaml:"patterns" json:"patterns"`
	Priority         int                `yaml:"priority" json:"priority"` // Deprecated: Ignored in favor of longest prefix
	Scope            *InstallationScope `yaml:"scope,omitempty" json:"scope,omitempty"`
}

GitHubApp represents a single GitHub App configuration

func (*GitHubApp) DeletePrivateKey

func (app *GitHubApp) DeletePrivateKey(secretMgr *secrets.Manager) error

DeletePrivateKey removes the private key from secure storage

func (*GitHubApp) GetIdentifier added in v0.0.7

func (g *GitHubApp) GetIdentifier() string

GetIdentifier returns the public identifier for the GitHub App. Client ID is preferred when present; otherwise the numeric App ID is returned as a string.

func (*GitHubApp) GetIssuer added in v0.0.7

func (g *GitHubApp) GetIssuer() any

GetIssuer returns the value to use as the JWT iss claim. It returns the Client ID string when available, otherwise the numeric App ID.

func (*GitHubApp) GetPrivateKey

func (app *GitHubApp) GetPrivateKey(secretMgr *secrets.Manager) (string, error)

GetPrivateKey retrieves the private key from the appropriate source based on the PrivateKeySource configuration

func (*GitHubApp) HasPrivateKey

func (app *GitHubApp) HasPrivateKey(secretMgr *secrets.Manager) bool

HasPrivateKey checks if the app has a private key configured

func (*GitHubApp) SetPrivateKey

func (app *GitHubApp) SetPrivateKey(secretMgr *secrets.Manager, privateKey string) (secrets.StorageBackend, error)

SetPrivateKey stores the private key securely It attempts to use keyring first, falling back to filesystem if unavailable

func (*GitHubApp) Validate

func (g *GitHubApp) Validate() error

Validate validates a single GitHub App configuration

type InstallationScope

type InstallationScope struct {
	// Core scope information
	RepositorySelection string `yaml:"repository_selection" json:"repository_selection"` // "all" or "selected"
	AccountLogin        string `yaml:"account_login" json:"account_login"`               // org or user name
	AccountType         string `yaml:"account_type" json:"account_type"`                 // "Organization" or "User"

	// Repository list (only populated if repository_selection == "selected")
	Repositories []RepositoryInfo `yaml:"repositories,omitempty" json:"repositories,omitempty"`

	// Cache metadata
	LastFetched time.Time `yaml:"last_fetched" json:"last_fetched"`
	LastUpdated time.Time `yaml:"last_updated" json:"last_updated"` // From GitHub API
	CacheExpiry time.Time `yaml:"cache_expiry" json:"cache_expiry"`
}

InstallationScope represents cached GitHub App installation scope information

type Loader

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

Loader handles loading GitHub App configurations from files

func NewDefaultLoader

func NewDefaultLoader() *Loader

NewDefaultLoader creates a loader with the default configuration path

func NewLoader

func NewLoader(configPath string) *Loader

NewLoader creates a new configuration loader

func (*Loader) GetConfigPath

func (l *Loader) GetConfigPath() string

GetConfigPath returns the configuration path that would be used

func (*Loader) Load

func (l *Loader) Load() (*Config, error)

Load loads the configuration from the configured path

func (*Loader) LoadWithFallback

func (l *Loader) LoadWithFallback() (*Config, error)

LoadWithFallback loads configuration, returns nil if file doesn't exist (no error)

type PersonalAccessToken

type PersonalAccessToken struct {
	Name        string           `yaml:"name" json:"name"`
	TokenSource PrivateKeySource `yaml:"private_key_source,omitempty" json:"private_key_source,omitempty"`
	Patterns    []string         `yaml:"patterns" json:"patterns"`
	Priority    int              `yaml:"priority" json:"priority"`
	// Username for HTTP basic auth (optional, defaults to "x-access-token" for GitHub)
	Username string `yaml:"username,omitempty" json:"username,omitempty"`
}

func (*PersonalAccessToken) DeletePAT

func (p *PersonalAccessToken) DeletePAT(secretMgr *secrets.Manager) error

DeletePAT removes the PAT from secure storage

func (*PersonalAccessToken) GetPAT

func (p *PersonalAccessToken) GetPAT(secretMgr *secrets.Manager) (string, error)

GetPAT retrieves the Personal Access Token from the appropriate source

func (*PersonalAccessToken) SetPAT

func (p *PersonalAccessToken) SetPAT(secretMgr *secrets.Manager, token string) (secrets.StorageBackend, error)

SetPAT stores the Personal Access Token securely

func (*PersonalAccessToken) Validate

func (p *PersonalAccessToken) Validate() error

type PrivateKeySource

type PrivateKeySource string

PrivateKeySource indicates where the private key is stored

const (
	// PrivateKeySourceKeyring indicates the key is in the OS keyring
	PrivateKeySourceKeyring PrivateKeySource = "keyring"
	// PrivateKeySourceFilesystem indicates the key is in a file
	PrivateKeySourceFilesystem PrivateKeySource = "filesystem"
	// PrivateKeySourceInline indicates the key was provided inline (legacy)
	PrivateKeySourceInline PrivateKeySource = "inline"
)

type RepositoryInfo

type RepositoryInfo struct {
	FullName string `yaml:"full_name" json:"full_name"` // "owner/repo"
	Private  bool   `yaml:"private" json:"private"`
}

RepositoryInfo represents a cached repository

Jump to

Keyboard shortcuts

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