connections

package
v1.5.58 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectionService

type ConnectionService interface {
	SaveConnection(ctx context.Context, params SaveConnectionParams) error
	SaveInstallation(ctx context.Context, userID uuid.UUID, provider string, installationID string) error
	GetConnection(ctx context.Context, userID uuid.UUID, provider string) (*ExternalConnection, error)
	GetConnectionByProviderID(ctx context.Context, provider string, providerUserID string) (*ExternalConnection, error)
	GetUserConnections(ctx context.Context, userID uuid.UUID) ([]*ExternalConnection, error)
	ListUserRepositories(ctx context.Context, userID uuid.UUID, provider string) ([]types.Repository, error)
	ListUserRepositoriesPaginated(ctx context.Context, userID uuid.UUID, provider string, search string, namespace string, page int, limit int) ([]types.Repository, error)
	ListUserNamespaces(ctx context.Context, userID uuid.UUID, provider string) ([]types.Namespace, error)
	ListRepositoryContents(ctx context.Context, userID uuid.UUID, provider string, repoFullName string, path string) ([]types.ContentItem, error)
	DeleteConnection(ctx context.Context, userID uuid.UUID, provider string) error
}

func NewConnectionService

func NewConnectionService(db ConnectionStorage, tokenEncryptionKey string, clients map[string]types.ProviderClient, logFn LoggerFunc) ConnectionService

NewConnectionService creates a new instance of ConnectionService. logFn is used to extract a logger from context for structured logging.

type ConnectionStorage

type ConnectionStorage interface {
	SaveConnection(ctx context.Context, conn *ExternalConnection) error
	GetConnection(ctx context.Context, userID uuid.UUID, provider string) (*ExternalConnection, error)
	GetConnectionByProviderID(ctx context.Context, provider string, providerUserID string) (*ExternalConnection, error)
	ListConnections(ctx context.Context, userID uuid.UUID) ([]*ExternalConnection, error)
	UpdateInstallationID(ctx context.Context, userID uuid.UUID, provider string, installationID string) error
	DeleteConnection(ctx context.Context, userID uuid.UUID, provider string) error
}

ConnectionStorage defines the interface for storing external connections.

func NewConnectionRepository

func NewConnectionRepository(db *gorm.DB) ConnectionStorage

type ExternalConnection

type ExternalConnection struct {
	gormutil.BaseModel
	UserID         uuid.UUID `json:"user_id" gorm:"type:uuid;uniqueIndex:idx_user_provider"`
	Provider       string    `json:"provider" gorm:"uniqueIndex:idx_user_provider"` // e.g., "github", "google"
	ProviderUserID string    `json:"provider_user_id"`                              // The ID assigned by the provider
	AccessToken    string    `json:"-"`                                             // Should be encrypted
	RefreshToken   string    `json:"-"`                                             // Should be encrypted
	ExpiresAt      time.Time `json:"expires_at"`
	Username       string    `json:"username"` // The handle on the provider
	AvatarURL      string    `json:"avatar_url"`
	InstallationID string    `json:"installation_id"` // For GitHub Apps
}

ExternalConnection represents a link between a local user and an external OAuth provider.

type LoggerFunc added in v1.5.55

type LoggerFunc func(context.Context) *slog.Logger

LoggerFunc extracts a logger from context. This allows callers to inject their own logger strategy (e.g. middleware.GetLoggerFromContext) without coupling this package to any specific middleware implementation.

type SaveConnectionParams added in v1.5.56

type SaveConnectionParams struct {
	UserID         uuid.UUID
	Provider       string
	ProviderUserID string
	Username       string
	AvatarURL      string
	AccessToken    string
	RefreshToken   string
	ExpiresAt      time.Time
	InstallationID string
}

SaveConnectionParams holds all data needed to save or update an external connection.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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