// Delete a leaf cert/key from Vault.
Delete a leaf cert/key from Vault.
// Delete a leaf cert / key from Vault .
func doBMCDeleteCertsPost(w http.ResponseWriter, r *http.Request) {
	var jdata bmcManageCertPost
	var retData bmcManageCertPostRsp
	funcName := "doBMCDeleteCertsPost"
	err := getReqData(funcName, r, &jdata)
	if err != nil {
		emsg := fmt.Sprintf("ERROR: Problem getting request data: %v", err)
		sendErrorRsp(w, "Bad request data", emsg, r.URL.Path,
			http.StatusInternalServerError)
		logger.Errorf("%s: %s", funcName, emsg)
		return
	}
	domainName, derr := userDomainToCertDomain(jdata.Domain)
	if derr != nil {
		emsg := fmt.Sprintf("%v", err)
		sendErrorRsp(w, "Bad request data", emsg, r.URL.Path,
			http.StatusBadRequest)
		logger.Errorf("%s: %s", funcName, emsg)
		return
	}
	retData.DomainIDs = make([]certRsp, len(jdata.DomainIDs))
	domMap := make(map[string][]int)
	for ix := 0; ix < len(jdata.DomainIDs); ix++ {
		retData.DomainIDs[ix].ID = jdata.DomainIDs[ix]
		retData.DomainIDs[ix].StatusCode = http.StatusOK 
		retData.DomainIDs[ix].StatusMsg = "OK"
		domID, err := hms_certs.CheckDomain([]string{jdata.DomainIDs[ix]}, domainName)
		if err != nil {
			logger.Tracef("%s: Domain check for '%s' failed: %v",
				funcName, jdata.DomainIDs[ix], err)
			retData.DomainIDs[ix].StatusCode = http.StatusBadRequest
			retData.DomainIDs[ix].StatusMsg = fmt.Sprintf("ID '%s' not in stated domain: %v",
				jdata.DomainIDs[ix], err)
			continue
		}
		domMap[domID] = append(domMap[domID], ix)
	}
	for k, _ := range domMap {
		logger.Tracef("%s: Deleting cert for cert domain '%s'", funcName, k)
		err = hms_certs.DeleteCertData(k, false)
		if err != nil {
			logger.Tracef("%s: ERROR deleting cert for '%s': %v",
				funcName, k, err)
			for xx := 0; xx < len(domMap[k]); xx++ {
				retData.DomainIDs[domMap[k][xx]].StatusCode = http.StatusInternalServerError
				retData.DomainIDs[domMap[k][xx]].StatusMsg = fmt.Sprintf("Error deleting cert for '%s', domain '%s: %v",
					jdata.DomainIDs[domMap[k][xx]], jdata.Domain, err)
			}
		}
	}
	ba, baerr := json.Marshal(&retData)
	if baerr != nil {
		emsg := fmt.Sprintf("ERROR marshalling response data: %v", baerr)
		sendErrorRsp(w, "JSON marshal error", emsg, r.URL.Path,
			http.StatusInternalServerError)
		return
	}
	w.Header().Set(CT_TYPE, CT_APPJSON)
	w.WriteHeader(http.StatusOK)
	w.Write(ba)
}
func doBMCDeleteCertsPost ( w http . ResponseWriter , r * http . Request ) { var jdata bmcManageCertPost var retData bmcManageCertPostRsp funcName := " " err := getReqData ( funcName , r , & jdata ) if err != nil { emsg := fmt . Sprintf ( " " , err ) sendErrorRsp ( w , " " , emsg , r . URL . Path , http . StatusInternalServerError ) logger . Errorf ( " " , funcName , emsg ) return } domainName , derr := userDomainToCertDomain ( jdata . Domain ) if derr != nil { emsg := fmt . Sprintf ( " " , err ) sendErrorRsp ( w , " " , emsg , r . URL . Path , http . StatusBadRequest ) logger . Errorf ( " " , funcName , emsg ) return } retData . DomainIDs = make ( [ ] certRsp , len ( jdata . DomainIDs ) ) domMap := make ( map [ string ] [ ] int ) for ix := 0 ; ix < len ( jdata . DomainIDs ) ; ix ++ { retData . DomainIDs [ ix ] . ID = jdata . DomainIDs [ ix ] retData . DomainIDs [ ix ] . StatusCode = http . StatusOK retData . DomainIDs [ ix ] . StatusMsg = " " domID , err := hms_certs . CheckDomain ( [ ] string { jdata . DomainIDs [ ix ] } , domainName ) if err != nil { logger . Tracef ( " " , funcName , jdata . DomainIDs [ ix ] , err ) retData . DomainIDs [ ix ] . StatusCode = http . StatusBadRequest retData . DomainIDs [ ix ] . StatusMsg = fmt . Sprintf ( " " , jdata . DomainIDs [ ix ] , err ) continue } domMap [ domID ] = append ( domMap [ domID ] , ix ) } for k , _ := range domMap { logger . Tracef ( " " , funcName , k ) err = hms_certs . DeleteCertData ( k , false ) if err != nil { logger . Tracef ( " " , funcName , k , err ) for xx := 0 ; xx < len ( domMap [ k ] ) ; xx ++ { retData . DomainIDs [ domMap [ k ] [ xx ] ] . StatusCode = http . StatusInternalServerError retData . DomainIDs [ domMap [ k ] [ xx ] ] . StatusMsg = fmt . Sprintf ( " " , jdata . DomainIDs [ domMap [ k ] [ xx ] ] , jdata . Domain , err ) } } } ba , baerr := json . Marshal ( & retData ) if baerr != nil { emsg := fmt . Sprintf ( " " , baerr ) sendErrorRsp ( w , " " , emsg , r . URL . Path , http . StatusInternalServerError ) return } w . Header ( ) . Set ( CT_TYPE , CT_APPJSON ) w . WriteHeader ( http . StatusOK ) w . Write ( ba ) }
Delete a leaf cert/key from Vault.
Delete a leaf cert / key from Vault .
//Reduce all DomainIDs to a list of actual domain IDs //start with success //Delete certs for all mapped domainIDs //Marshal return data and send.