gitcred

package
v1.0.52 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CurrentCredentialVersion = 1
	MetadataFilename         = "git.json"

	// KeychainService intentionally reuses the CLI-wide internal keychain
	// service, so Git PAT .enc files stay under Application Support/lark-cli.
	KeychainService = "lark-cli"

	StatusPending   = "pending"
	StatusConfirmed = "confirmed"

	ListStatusValid         = "valid"
	ListStatusExpired       = "expired"
	ListStatusInvalidated   = "invalidated"
	ListStatusMissingSecret = "missing_secret"
	ListStatusIncomplete    = "incomplete"
)

Variables

This section is empty.

Functions

func BuildPATRef

func BuildPATRef(profile ProfileContext, appID string) string

func NormalizeCredentialInput

func NormalizeCredentialInput(input CredentialInput) (string, error)

func NormalizeGitHTTPURL

func NormalizeGitHTTPURL(raw string) (string, error)

Types

type AppStorage

type AppStorage interface {
	Read(appID, key string) ([]byte, error)
	Write(appID, key string, data []byte) error
	Delete(appID, key string) error
}

type CredentialFile

type CredentialFile struct {
	Version int `json:"version"`
	CredentialRecord
}

CredentialFile is the app-scoped non-secret metadata persisted under the Miaoda app storage directory.

type CredentialInput

type CredentialInput struct {
	Protocol string
	Host     string
	Path     string
}

func ParseCredentialInput

func ParseCredentialInput(r io.Reader) (CredentialInput, error)

type CredentialRecord

type CredentialRecord struct {
	AppID         string `json:"app_id"`
	GitHTTPURL    string `json:"git_http_url"`
	Profile       string `json:"profile"`
	ProfileAppID  string `json:"profile_app_id"`
	UserOpenID    string `json:"user_open_id"`
	Username      string `json:"username"`
	PATRef        string `json:"pat_ref"`
	Status        string `json:"status"`
	ExpiresAt     int64  `json:"expires_at"`
	UpdatedAt     int64  `json:"updated_at"`
	LastEraseAt   int64  `json:"last_erase_at,omitempty"`
	InvalidatedAt int64  `json:"invalidated_at,omitempty"`
}

CredentialRecord points to the keychain-stored PAT without storing the PAT plaintext in metadata.

type GitConfig

type GitConfig interface {
	SetHelper(ctx context.Context, gitHTTPURL, appID string) error
	UnsetHelper(ctx context.Context, gitHTTPURL string) error
}

type GlobalGitConfig

type GlobalGitConfig struct {
	HelperCommand string
}

func (GlobalGitConfig) SetHelper

func (g GlobalGitConfig) SetHelper(ctx context.Context, gitHTTPURL, appID string) error

func (GlobalGitConfig) UnsetHelper

func (g GlobalGitConfig) UnsetHelper(ctx context.Context, gitHTTPURL string) error

type InitResult

type InitResult struct {
	AppID         string
	GitHTTPURL    string
	Refreshed     bool
	ConfigWarning string
}

type IssuedCredential

type IssuedCredential struct {
	AppID      string
	GitHTTPURL string
	Username   string
	PAT        string
	ExpiresAt  int64
}

type Issuer

type Issuer interface {
	Issue(ctx context.Context, appID string, profile ProfileContext) (*IssuedCredential, error)
}

type ListRecord

type ListRecord struct {
	AppID         string
	GitHTTPURL    string
	Status        string
	ExpiresAt     int64
	UpdatedAt     int64
	Profile       string
	ProfileAppID  string
	UserOpenID    string
	Expired       bool
	InvalidatedAt int64
}

type ListResult

type ListResult struct {
	Records []ListRecord
}

type Manager

type Manager struct {
	Store     *Store
	Secrets   *SecretStore
	GitConfig GitConfig
	Issuer    Issuer
	Now       func() time.Time
}

func NewManager

func NewManager(store *Store, secrets *SecretStore, gitConfig GitConfig, issuer Issuer) *Manager

func (*Manager) Erase

func (m *Manager) Erase(r io.Reader) error

func (*Manager) Get

func (m *Manager) Get(ctx context.Context, input CredentialInput, current ProfileContext, out, errOut io.Writer) error

func (*Manager) Init

func (m *Manager) Init(ctx context.Context, profile ProfileContext, appID string) (*InitResult, error)

func (*Manager) List

func (m *Manager) List() (*ListResult, error)

func (*Manager) Remove

func (m *Manager) Remove(ctx context.Context, profile ProfileContext, appID string) (*RemoveResult, error)

func (*Manager) StoreCredential

func (m *Manager) StoreCredential(r io.Reader) error

type ProfileContext

type ProfileContext struct {
	Profile      string
	ProfileAppID string
	UserOpenID   string
}

type RemoveResult

type RemoveResult struct {
	AppID         string
	Removed       bool
	Records       []CredentialRecord
	ConfigWarning string
}

type SecretStore

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

func NewSecretStore

func NewSecretStore(kc keychain.KeychainAccess) *SecretStore

func (*SecretStore) Get

func (s *SecretStore) Get(ref string) (string, error)

func (*SecretStore) Remove

func (s *SecretStore) Remove(ref string) error

func (*SecretStore) Set

func (s *SecretStore) Set(ref, pat string) error

type Store

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

func NewAppStore

func NewAppStore(appID string, storage AppStorage) *Store

func NewStore

func NewStore() *Store

func NewStoreAt

func NewStoreAt(path string) *Store

func (*Store) Current

func (s *Store) Current() (*CredentialRecord, error)

func (*Store) DeleteByURL

func (s *Store) DeleteByURL(gitHTTPURL string) (*CredentialRecord, error)

func (*Store) FindByAppID

func (s *Store) FindByAppID(appID string, profile ProfileContext) ([]CredentialRecord, error)

func (*Store) FindByURL

func (s *Store) FindByURL(gitHTTPURL string) (*CredentialRecord, error)

func (*Store) Load

func (s *Store) Load() (*CredentialFile, error)

func (*Store) Path

func (s *Store) Path() string

func (*Store) Records

func (s *Store) Records() ([]CredentialRecord, error)

func (*Store) Save

func (s *Store) Save(file *CredentialFile) error

func (*Store) Upsert

func (s *Store) Upsert(record CredentialRecord) error

Jump to

Keyboard shortcuts

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