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)
| 144 | // includes the certificate file itself, the private key, and the |
| 145 | // metadata file. |
| 146 | func (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 |