MCPcopy
hub / github.com/caddyserver/certmagic / saveCertResource

Method saveCertResource

crypto.go:146–171  ·  view source on GitHub ↗

saveCertResource saves the certificate resource to disk. This includes the certificate file itself, the private key, and the metadata file.

(ctx context.Context, issuer Issuer, cert CertificateResource)

Source from the content-addressed store, hash-verified

144// includes the certificate file itself, the private key, and the
145// metadata file.
146func (cfg *Config) saveCertResource(ctx context.Context, issuer Issuer, cert CertificateResource) error {
147 metaBytes, err := json.MarshalIndent(cert, "", "\t")
148 if err != nil {
149 return fmt.Errorf("encoding certificate metadata: %v", err)
150 }
151
152 issuerKey := issuer.IssuerKey()
153 certKey := cert.NamesKey()
154
155 all := []keyValue{
156 {
157 key: StorageKeys.SitePrivateKey(issuerKey, certKey),
158 value: cert.PrivateKeyPEM,
159 },
160 {
161 key: StorageKeys.SiteCert(issuerKey, certKey),
162 value: cert.CertificatePEM,
163 },
164 {
165 key: StorageKeys.SiteMeta(issuerKey, certKey),
166 value: metaBytes,
167 },
168 }
169
170 return storeTx(ctx, cfg.Storage, all)
171}
172
173// loadCertResourceAnyIssuer loads and returns the certificate resource from any
174// of the configured issuers. If multiple are found (e.g. if there are 3 issuers

Callers 3

TestSaveCertResourceFunction · 0.95
obtainCertMethod · 0.95
renewCertMethod · 0.95

Calls 6

storeTxFunction · 0.85
NamesKeyMethod · 0.80
SitePrivateKeyMethod · 0.80
SiteCertMethod · 0.80
SiteMetaMethod · 0.80
IssuerKeyMethod · 0.65

Tested by 1

TestSaveCertResourceFunction · 0.76