githubtoken

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTokenNotFound = errors.New("github token not found")

ErrTokenNotFound is returned when no GitHub token is stored.

Functions

func IsValidTokenPrefix

func IsValidTokenPrefix(token string) bool

IsValidTokenPrefix checks whether a token has a recognised GitHub PAT prefix.

Types

type Repository

type Repository interface {
	UpsertGitHubToken(ctx context.Context, encryptedToken string, now time.Time) error
	ReadGitHubToken(ctx context.Context) (string, error)
	DeleteGitHubToken(ctx context.Context) error
}

Repository defines the data access methods for the encrypted GitHub token.

type Service

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

Service manages the GitHub token lifecycle: encryption, storage, and in-memory caching of the decrypted token and GitHub client.

func NewService

func NewService(repo Repository, encryptionKey []byte, insecureSkipVerify bool) *Service

NewService creates a new GitHubTokenService.

func (*Service) DeleteToken

func (s *Service) DeleteToken(ctx context.Context) error

DeleteToken removes the token from the database and clears the in-memory cache.

func (*Service) GetClient

func (s *Service) GetClient() *github.Client

GetClient returns the cached GitHub client. Returns nil if no token is configured.

func (*Service) GetToken

func (s *Service) GetToken() string

GetToken returns the cached decrypted token. Returns empty string if no token is configured.

func (*Service) HasToken

func (s *Service) HasToken() bool

HasToken reports whether a GitHub token is currently configured.

func (*Service) IsFineGrained

func (s *Service) IsFineGrained() bool

IsFineGrained reports whether the configured token is a fine-grained PAT.

func (*Service) Load

func (s *Service) Load(ctx context.Context) error

Load reads the encrypted token from the database and hydrates the in-memory cache. Call this on server startup. If no token is stored, this is a no-op.

func (*Service) SaveToken

func (s *Service) SaveToken(ctx context.Context, plaintext string) error

SaveToken encrypts the token, stores it in the database, and updates the in-memory cache.

Jump to

Keyboard shortcuts

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