func SetCerts(certs []core.CertBundle) error { // in case of failure oldCerts, err := database.GetCerts() if err != nil { return err } // apply certs to proxymgr err = proxymgr.SetCerts(certs) if err != nil { return err } if !database.CentralStore { // save to backend err = database.SetCerts(certs) 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) SetCerts(certs []core.CertBundle) error { err := common.SetCerts(certs) if err != nil { return err } if database.CentralStore { return database.SetCerts(certs) } return nil }
func TestSetCerts(t *testing.T) { certs := []core.CertBundle{testCert} if err := database.SetCerts(certs); err != nil { t.Errorf("Failed to SET certs - %v", err) } certs, err := database.GetCerts() if err != nil { t.Error(err) } if len(certs) != 1 { t.Errorf("Wrong number of certs") } }
// SetCerts tells all members to replace the certs in their database with a new set. // rolls back on failure func (r Redis) SetCerts(certs []core.CertBundle) error { conn := pool.Get() defer conn.Close() oldCerts, err := common.GetCerts() if err != nil { return err } // publishJson to others err = r.publishJson(conn, "set-certs", certs) if err != nil { // if i failed to publishJson, request should fail return err } actionHash := fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("set-certs %s", certs)))) // ensure all members applied action err = r.waitForMembers(conn, actionHash) if err != nil { uActionHash := fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("set-certs %s", 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.SetCerts(certs) } return nil }