Documentation
¶
Overview ¶
Package credentials provides a secure storage and management system for user credentials. The service uses the "go-keyring" library to interact with the system's native keyring service. For systems that do not support a native keyring service, an alternative using a file at ~/.connect-credentials to persist credentials is implemented.
This package is not thread safe! Manipulation of credentials from multiple threads can result in data loss. A distributed write lock is required to ensure threads do not overwrite the credential store.
Support for breaking changes to the Credentials schema is supported via version system. The current implementation supports a single version (Version 0), but is designed to be extendable to future versions. For example, adding a new field to Credential.
Migration instructions: - Modify the current version to retain the current Credential structure (i.e., copy the struct of Credential to CredentialV0) - Modify Credential to include required changes. - Create a new version (e.g., CredentialV1) and assign Credential to it (.e.g, CredentialV1 = Credential) - Increment CurrentVersion to match the new version (e.g., CredentialVersion = 1) - Add a case statement for the new version to ToCredential. - Modify the existing ToCredential implementation to accommodate changes to Credential.
Key components include: - Credential: The main structure representing a single credential. - CredentialRecord: A structure for storing credential data along with its version for future compatibility. - CredentialsService (interface): A service that provides methods for managing credentials.
- keyringCredentialsService: The service using the system's native keyring.
- fileCredentialsService: Fallback service for persising credentials in file when keyring is not available.
Author: Posit Software, PBC Copyright (C) 2024 by Posit Software, PBC.
Index ¶
- Constants
- func NewFileCredentialsService(log logging.Logger) (*fileCredentialsService, error)
- func NewKeyringCredentialsService(log logging.Logger) *keyringCredentialsService
- type CorruptedError
- type Credential
- type CredentialRecord
- type CredentialTable
- type CredentialV0
- type CredentialsService
- type IncompleteCredentialError
- type LoadError
- type NameCollisionError
- type NotFoundError
- type URLCollisionError
- type VersionError
Constants ¶
const CurrentVersion = 0
const ServiceName = "Posit Publisher Safe Storage"
Variables ¶
This section is empty.
Functions ¶
func NewFileCredentialsService ¶ added in v1.1.7
func NewKeyringCredentialsService ¶ added in v1.1.7
Types ¶
type CorruptedError ¶
type CorruptedError struct {
GUID string
}
func NewCorruptedError ¶ added in v1.1.7
func NewCorruptedError(guid string) *CorruptedError
func (*CorruptedError) Error ¶
func (e *CorruptedError) Error() string
type Credential ¶
type Credential struct {
GUID string `json:"guid"`
Name string `json:"name"`
URL string `json:"url"`
ApiKey string `json:"apiKey"`
}
func (*Credential) ConflictCheck ¶ added in v1.1.7
func (c *Credential) ConflictCheck(compareWith Credential) error
type CredentialRecord ¶
type CredentialRecord struct {
GUID string `json:"guid"`
Version uint `json:"version"`
Data json.RawMessage `json:"data"`
}
func (*CredentialRecord) ToCredential ¶
func (cr *CredentialRecord) ToCredential() (*Credential, error)
ToCredential converts a CredentialRecord to a Credential based on its version.
type CredentialTable ¶
type CredentialTable = map[string]CredentialRecord
type CredentialV0 ¶
type CredentialV0 = Credential
type CredentialsService ¶
type CredentialsService interface {
Delete(guid string) error
Get(guid string) (*Credential, error)
List() ([]Credential, error)
Set(name string, url string, ak string) (*Credential, error)
}
func NewCredentialsService ¶ added in v1.1.7
func NewCredentialsService(log logging.Logger) (CredentialsService, error)
The main credentials service constructor that determines if the system's keyring is available to be used, if not, returns a file based credentials service.
type IncompleteCredentialError ¶ added in v1.1.7
type IncompleteCredentialError struct{}
func NewIncompleteCredentialError ¶ added in v1.1.7
func NewIncompleteCredentialError() *IncompleteCredentialError
func (*IncompleteCredentialError) Error ¶ added in v1.1.7
func (e *IncompleteCredentialError) Error() string
type NameCollisionError ¶ added in v1.1.5
Name is used by another credential
func NewNameCollisionError ¶ added in v1.1.7
func NewNameCollisionError(name, url string) *NameCollisionError
func (*NameCollisionError) Error ¶ added in v1.1.5
func (e *NameCollisionError) Error() string
type NotFoundError ¶
type NotFoundError struct {
GUID string
}
func NewNotFoundError ¶ added in v1.1.7
func NewNotFoundError(guid string) *NotFoundError
func (*NotFoundError) Error ¶
func (e *NotFoundError) Error() string
type URLCollisionError ¶
URL is used by another credential
func NewURLCollisionError ¶ added in v1.1.7
func NewURLCollisionError(name, url string) *URLCollisionError
func (*URLCollisionError) Error ¶
func (e *URLCollisionError) Error() string
type VersionError ¶
type VersionError struct {
Version uint
}
func NewVersionError ¶ added in v1.1.7
func NewVersionError(v uint) *VersionError
func (*VersionError) Error ¶
func (e *VersionError) Error() string