storage

package
v5.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OriginConfiguration = "configuration"
	OriginCommand       = "command"
	OriginMigration     = "migration"
)
View Source
const (
	ExtIssuer   = ".issuer.crt"
	ExtCert     = ".crt"
	ExtKey      = ".key"
	ExtPEM      = ".pem"
	ExtPFX      = ".pfx"
	ExtResource = ".json"
)
View Source
const RootPathWarningMessage = `` /* 329-byte string literal not displayed */

Variables

This section is empty.

Functions

func CreateNonExistingFolder

func CreateNonExistingFolder(path string) error

func GetEffectiveAccountID

func GetEffectiveAccountID(email, id string) string

GetEffectiveAccountID returns the effective account ID.

func ReadCSRFile

func ReadCSRFile(filename string) (*x509.CertificateRequest, error)

ReadCSRFile reads a CSR file.

func ReadCertificateFile

func ReadCertificateFile(filename string) ([]*x509.Certificate, error)

ReadCertificateFile reads a certificate file.

func ReadJSONFile

func ReadJSONFile[T any](filename string) (*T, error)

func ReadPrivateKeyFile

func ReadPrivateKeyFile(filename string) (crypto.Signer, error)

ReadPrivateKeyFile reads a private key file.

func SanitizedName

func SanitizedName(name string) string

SanitizedName Make sure no funny chars are in the cert names (like wildcards ;)).

Types

type Account

type Account struct {
	ID      string             `json:"id"`
	Email   string             `json:"email"`
	KeyType certcrypto.KeyType `json:"keyType"`
	Server  string             `json:"server"`

	Origin string `json:"origin,omitempty"`

	Registration  *acme.ExtendedAccount `json:"registration"`
	NeedsRecovery bool                  `json:"-"`
	// contains filtered or unexported fields
}

Account represents a users local saved credentials.

func NewRecoverableAccount

func NewRecoverableAccount(server, email, id, keyPath string) (*Account, error)

func (*Account) GetEmail

func (a *Account) GetEmail() string

GetEmail returns the email address for the account.

func (*Account) GetID

func (a *Account) GetID() string

GetID returns the effective account ID.

func (*Account) GetKeyType

func (a *Account) GetKeyType() certcrypto.KeyType

GetKeyType returns the key type of the account.

func (*Account) GetPrivateKey

func (a *Account) GetPrivateKey() crypto.Signer

GetPrivateKey returns the private account key.

func (*Account) GetRegistration

func (a *Account) GetRegistration() *acme.ExtendedAccount

GetRegistration returns the server registration.

func (*Account) SetPrivateKey

func (a *Account) SetPrivateKey(key crypto.Signer)

SetPrivateKey sets the private account key.

type AccountsStorage

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

AccountsStorage A storage for account data.

rootPath:

./.lego/accounts/
     │      └── root accounts directory
     └── "path" option

rootUserPath:

./.lego/accounts/localhost_14000/foo@example.com/
     │      │             │             └── accountID
     │      │             └── CA server ("server" option)
     │      └── root accounts directory
     └── "path" option

keyPath:

./.lego/accounts/localhost_14000/foo@example.com/foo@example.com.key
     │      │             │             │            └── private key
     │      │             │             └── accountID
     │      │             └── CA server ("server" option)
     │      └── root accounts directory
     └── "path" option

accountFilePath:

./.lego/accounts/localhost_14000/foo@example.com/account.json
     │      │             │             │            └── account file
     │      │             │             └── accountID
     │      │             └── CA server ("server" option)
     │      └── root accounts directory
     └── "path" option

func NewAccountsStorage

func NewAccountsStorage(basePath string) *AccountsStorage

NewAccountsStorage Creates a new AccountsStorage.

func (*AccountsStorage) Get

func (s *AccountsStorage) Get(server string, keyType certcrypto.KeyType, email, accountID string) (*Account, error)

Get gets an account from a file or creates a new one (the files are saved).

func (*AccountsStorage) GetRootPath

func (s *AccountsStorage) GetRootPath() string

GetRootPath returns the root path of the storage of the accounts.

func (*AccountsStorage) Save

func (s *AccountsStorage) Save(account *Account) error

Save saves the account to a file (only the JSON file).

func (*AccountsStorage) SavePrivateKey

func (s *AccountsStorage) SavePrivateKey(account *Account) error

SavePrivateKey saves the private key to a file defined by the account.

type Archiver

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

Archiver manages the archiving of accounts and certificates.

func NewArchiver

func NewArchiver(basePath string) *Archiver

NewArchiver creates a new Archiver.

func (*Archiver) Accounts

func (m *Archiver) Accounts(cfg *configuration.Configuration) error

func (*Archiver) Certificate

func (m *Archiver) Certificate(certID string) error

func (*Archiver) Certificates

func (m *Archiver) Certificates(certificates map[string]*configuration.Certificate) error

func (*Archiver) ListArchivedAccounts

func (m *Archiver) ListArchivedAccounts() ([]string, error)

func (*Archiver) ListArchivedCertificates

func (m *Archiver) ListArchivedCertificates() ([]string, error)

func (*Archiver) Restore

func (m *Archiver) Restore(archivePath string) error

type Certificate

type Certificate struct {
	*certificate.Resource

	Origin string `json:"origin,omitempty"`
}

type CertificatesStorage

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

CertificatesStorage a certificates' storage.

rootPath:

./.lego/certificates/
     │      └── root certificates directory
     └── "path" option

archivePath:

./.lego/archives/
     │      └── archived certificates directory
     └── "path" option

func NewCertificatesStorage

func NewCertificatesStorage(basePath string) *CertificatesStorage

NewCertificatesStorage create a new certificates storage.

func (*CertificatesStorage) ExistsFile

func (s *CertificatesStorage) ExistsFile(certID, extension string) bool

func (*CertificatesStorage) GetFileName

func (s *CertificatesStorage) GetFileName(certID, extension string) string

func (*CertificatesStorage) GetRootPath

func (s *CertificatesStorage) GetRootPath() string

func (*CertificatesStorage) ReadCertificate

func (s *CertificatesStorage) ReadCertificate(certID string) ([]*x509.Certificate, error)

func (*CertificatesStorage) ReadFile

func (s *CertificatesStorage) ReadFile(certID, extension string) ([]byte, error)

func (*CertificatesStorage) ReadPrivateKey

func (s *CertificatesStorage) ReadPrivateKey(certID string) (crypto.Signer, error)

func (*CertificatesStorage) ReadResource

func (s *CertificatesStorage) ReadResource(certID string) (*Certificate, error)

func (*CertificatesStorage) Save

func (s *CertificatesStorage) Save(certRes *Certificate, opts *SaveOptions) error

Save saves the certificate and related files. - the resource file (JSON) - the certificate file - the private key file (if any) - the issuer certificate file (if any) - the PFX file (if needed) - the PEM file (if needed).

type ConfigurationStorage

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

ConfigurationStorage is a storage for the configuration. The backup is the effective configuration and cannot be used directly.

func NewConfigurationStorage

func NewConfigurationStorage(basePath string) *ConfigurationStorage

NewConfigurationStorage creates a new ConfigurationStorage.

func (*ConfigurationStorage) Backup

Backup saves the configuration to the storage.

func (*ConfigurationStorage) ReadBackup

ReadBackup reads the backup configuration.

type PrivateKeyNotFound

type PrivateKeyNotFound struct {
	AccountID string
}

func (*PrivateKeyNotFound) Error

func (e *PrivateKeyNotFound) Error() string

type SaveOptions

type SaveOptions struct {
	PEM         bool
	PFX         bool
	PFXFormat   string
	PFXPassword string
}

SaveOptions contains the options for saving a certificate.

type Storage

type Storage struct {
	Certificate   *CertificatesStorage
	Account       *AccountsStorage
	Archiver      *Archiver
	Configuration *ConfigurationStorage
}

func New

func New(basePath string) *Storage

Jump to

Keyboard shortcuts

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