func DeleteCert(cert core.CertBundle) error { // in case of failure oldCerts, err := database.GetCerts() if err != nil { return err } // apply to proxymgr err = proxymgr.DeleteCert(cert) if err != nil { return err } if !database.CentralStore { // save to backend err = database.DeleteCert(cert) if err != nil { // undo proxymgr action if uerr := proxymgr.SetCerts(oldCerts); uerr != nil { err = fmt.Errorf("%v - %v", err.Error(), uerr.Error()) } return err } } return nil }
func (n None) DeleteCert(cert core.CertBundle) error { err := common.DeleteCert(cert) if err != nil { return err } if database.CentralStore { return database.DeleteCert(cert) } return nil }
func TestDeleteCert(t *testing.T) { if err := database.DeleteCert(testCert); err != nil { t.Errorf("Failed to DELETE cert - %v", err) } certs, err := database.GetCerts() if err != nil { t.Error(err) } if len(certs) != 0 { t.Errorf("Failed to delete cert") } }
// DeleteCert tells all members to remove the cert from their database. // rolls back on failure func (r Redis) DeleteCert(cert core.CertBundle) error { conn := pool.Get() defer conn.Close() oldCerts, err := common.GetCerts() // this should not return nil to ensure the cert is gone from entire cluster if err != nil && !strings.Contains(err.Error(), "No Cert Found") { return err } // publishJson to others err = r.publishJson(conn, "delete-cert", cert) if err != nil { // if i failed to publishJson, request should fail return err } actionHash := fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("delete-cert %s", cert)))) // ensure all members applied action err = r.waitForMembers(conn, actionHash) if err != nil { uActionHash := fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("set-certs", oldCerts)))) // cleanup rollback cruft. clear actionHash ensures no mistakes on re-submit defer conn.Do("DEL", uActionHash, actionHash) // attempt rollback - no need to waitForMembers here uerr := r.publishJson(conn, "set-certs", oldCerts) if uerr != nil { err = fmt.Errorf("%v - %v", err, uerr) } return err } if database.CentralStore { return database.DeleteCert(cert) } return nil }