config

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2025 License: MIT Imports: 10 Imported by: 1 module, 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

View Source
const CurrentConfigVersion = "1"

CurrentConfigVersion is the latest configuration schema version

Variables

This section is empty.

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" json:"app_id"`
	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) 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