// HPE blade cert replacement.
//
// Algo:
//
// o GET /redfish/v1/Managers  to get the manager ID (should be only one entry)
// o GET /redfish/v1/Managers/X to get Oem SecurityService URL.
// o GET /redfish/v1/Managers/X/SecurityService to get ETAG and URL of
//   cert mod endpoint from the "Links" data.
// o GET /redfish/v1/Managers/X/SecurityService/HttpsCert
//   This should get the action in the Actions section.
//
// xxxxxxxxx below is current behavior, will change in 1.5 xxxxxxxxxxxxx
// o POST /redfish/v1/Managers/1/SecurityService/HttpsCert/Actions/HpeHttpsCert.GenerateCSR
//       Data is a standard blade-level CSR.
// o GET /redfish/v1/Managers/1/SecurityService/HttpsCert
//       Look for a present and populated CertificateSigningRequest field.
//       Loop over the GET operations until this is populated.
// o Post CSR to the Vault PKI via hms_certs.
// o Get the generated cert from Vault PKI.
// o Store cert in Vault K/V.
// xxxxxxxxx
//
// o POST /redfish/v1/Managers/1/SecurityService/HttpsCert/Actions/HpeHttpsCert.ImportCertificate/
//   Data is cert from CSR. No private key.
HPE blade cert replacement.



o GET /redfish/v1/Managers  to get the manager ID (should be only one entry)
o GET /redfish/v1/Managers/X to get Oem SecurityService URL.
o GET /redfish/v1/Managers/X/SecurityService to get ETAG and URL of
cert mod endpoint from the "Links" data.
o GET /redfish/v1/Managers/X/SecurityService/HttpsCert
This should get the action in the Actions section.

xxxxxxxxx below is current behavior, will change in 1.5 xxxxxxxxxxxxx
o POST /redfish/v1/Managers/1/SecurityService/HttpsCert/Actions/HpeHttpsCert.GenerateCSR
Data is a standard blade-level CSR.
o GET /redfish/v1/Managers/1/SecurityService/HttpsCert
Look for a present and populated CertificateSigningRequest field.
Loop over the GET operations until this is populated.
o Post CSR to the Vault PKI via hms_certs.
o Get the generated cert from Vault PKI.
o Store cert in Vault K/V.

o POST /redfish/v1/Managers/1/SecurityService/HttpsCert/Actions/HpeHttpsCert.ImportCertificate
Data is cert from CSR. No private key.
// HPE blade cert replacement . // // Algo : // // o GET / redfish / v1 / Managers to get the manager ID ( should be only one entry ) // o GET / redfish / v1 / Managers / X to get Oem SecurityService URL . // o GET / redfish / v1 / Managers / X / SecurityService to get ETAG and URL of // cert mod endpoint from the " Links " data . // o GET / redfish / v1 / Managers / X / SecurityService / HttpsCert // This should get the action in the Actions section . // // xxxxxxxxx below is current behavior will change in 1 . 5 xxxxxxxxxxxxx // o POST / redfish / v1 / Managers / 1 / SecurityService / HttpsCert / Actions / HpeHttpsCert . GenerateCSR // Data is a standard blade - level CSR . // o GET / redfish / v1 / Managers / 1 / SecurityService / HttpsCert // Look for a present and populated CertificateSigningRequest field . // Loop over the GET operations until this is populated . // o Post CSR to the Vault PKI via hms_certs . // o Get the generated cert from Vault PKI . // o Store cert in Vault K / V . // xxxxxxxxx // // o POST / redfish / v1 / Managers / 1 / SecurityService / HttpsCert / Actions / HpeHttpsCert . ImportCertificate / // Data is cert from CSR . No private key .
func doHPECerts(taskList []trsapi.HttpTask, targList []string, certs []bmcCertData) error {
	var err error
	funcName := "doHPECerts()"
	logger.Tracef("%s: Fetching Managers data.", funcName)
	populateTaskList(taskList, targList, HPE_MGR_API, "GET", nil)
	err = doOp(taskList)
	if err != nil {
		logger.Errorf("%s: Problem executing cert set: %v",
			funcName, err)
		return err
	}
	ignoreBadTasks(funcName, taskList)
	logger.Tracef("%s: Parsing Managers data, setup for target manager fetch.",
		funcName)
	for ii := 0; ii < len(taskList); ii++ {
		if taskList[ii].Ignore {
			continue
		}
		var jdata hpeManagers
		targ := targFromTask(&taskList[ii])
		err = grabTaskRspData(funcName, &taskList[ii], &jdata)
		if err != nil {
			logger.Errorf("%s: Problem getting response from '%s': %v",
				funcName, taskList[ii].Request.URL.Path, err)
			return err
		}
		logger.Tracef("%s, '%s': Managers: '%v'",
			funcName, taskList[ii].Request.URL.Path, jdata)
		url := dfltProtocol + "://" + targ + jdata.Members[0].ID
		taskList[ii].Request.URL, _ = neturl.Parse(url)
	}
	err = doOp(taskList)
	if err != nil {
		logger.Errorf("%s: Problem executing cert set: %v",
			funcName, err)
		return err
	}
	ignoreBadTasks(funcName, taskList)
	logger.Tracef("%s: Parsing target Manager data, setup for security service data fetch.",
		funcName)
	for ii := 0; ii < len(taskList); ii++ {
		if taskList[ii].Ignore {
			continue
		}
		var jdata hpeManagerData
		targ := targFromTask(&taskList[ii])
		err = grabTaskRspData(funcName, &taskList[ii], &jdata)
		if err != nil {
			logger.Errorf("%s: Problem getting response from '%s': %v",
				funcName, taskList[ii].Request.URL.Path, err)
			return err
		}
		url := dfltProtocol + "://" + targ + jdata.Oem.HPE.Links.SecurityService.ID
		taskList[ii].Request.URL, _ = neturl.Parse(url)
	}
	err = doOp(taskList)
	if err != nil {
		logger.Errorf("%s: Problem executing cert set: %v",
			funcName, err)
		return err
	}
	ignoreBadTasks(funcName, taskList)
	logger.Tracef("%s: Parsing security service data, setup for cert info fetch.",
		funcName)
	for ii := 0; ii < len(taskList); ii++ {
		if taskList[ii].Ignore {
			continue
		}
		var jdata hpeSecurityService
		targ := targFromTask(&taskList[ii])
		err = grabTaskRspData(funcName, &taskList[ii], &jdata)
		if err != nil {
			logger.Errorf("%s: Problem getting response from '%s': %v",
				funcName, taskList[ii].Request.URL.Path, err)
			return err
		}
		url := dfltProtocol + "://" + targ + jdata.Links.HttpsCert.ID
		taskList[ii].Request.URL, _ = neturl.Parse(url)
	}
	err = doOp(taskList)
	if err != nil {
		logger.Errorf("%s: Problem executing cert set: %v",
			funcName, err)
		return err
	}
	ignoreBadTasks(funcName, taskList)
	logger.Tracef("%s: Parsing cert info, setup for cert replacement.",
		funcName)
	for ii := 0; ii < len(taskList); ii++ {
		if taskList[ii].Ignore {
			continue
		}
		var jdata hpeSecurityServiceHttpsCert
		targ := targFromTask(&taskList[ii])
		err = grabTaskRspData(funcName, &taskList[ii], &jdata)
		if err != nil {
			logger.Errorf("%s: Problem getting response from '%s': %v",
				funcName, taskList[ii].Request.URL.Path, err)
			return err
		}
		pld := makeRFCertPayload(VendorHPE, certs[ii], "", "")
		url := dfltProtocol + "://" + targ + jdata.Actions.ImportCertificate.Target
		taskList[ii].Request, _ = http.NewRequest("POST", url, bytes.NewBuffer(pld))
		taskList[ii].Request.Header.Set(CT_TYPE, CT_APPJSON)
	}
	err = doOp(taskList)
	if err != nil {
		logger.Errorf("%s: Problem executing cert set: %v",
			funcName, err)
		return err
	}
	ignoreBadTasks(funcName, taskList)
	logger.Tracef("%s: Finished cert replacement.", funcName)
	return nil
}
func doHPECerts ( taskList [ ] trsapi . HttpTask , targList [ ] string , certs [ ] bmcCertData ) error { var err error funcName := " " logger . Tracef ( " " , funcName ) populateTaskList ( taskList , targList , HPE_MGR_API , " " , nil ) err = doOp ( taskList ) if err != nil { logger . Errorf ( " " , funcName , err ) return err } ignoreBadTasks ( funcName , taskList ) logger . Tracef ( " " , funcName ) for ii := 0 ; ii < len ( taskList ) ; ii ++ { if taskList [ ii ] . Ignore { continue } var jdata hpeManagers targ := targFromTask ( & taskList [ ii ] ) err = grabTaskRspData ( funcName , & taskList [ ii ] , & jdata ) if err != nil { logger . Errorf ( " " , funcName , taskList [ ii ] . Request . URL . Path , err ) return err } logger . Tracef ( " " , funcName , taskList [ ii ] . Request . URL . Path , jdata ) url := dfltProtocol + " " + targ + jdata . Members [ 0 ] . ID taskList [ ii ] . Request . URL , _ = neturl . Parse ( url ) } err = doOp ( taskList ) if err != nil { logger . Errorf ( " " , funcName , err ) return err } ignoreBadTasks ( funcName , taskList ) logger . Tracef ( " " , funcName ) for ii := 0 ; ii < len ( taskList ) ; ii ++ { if taskList [ ii ] . Ignore { continue } var jdata hpeManagerData targ := targFromTask ( & taskList [ ii ] ) err = grabTaskRspData ( funcName , & taskList [ ii ] , & jdata ) if err != nil { logger . Errorf ( " " , funcName , taskList [ ii ] . Request . URL . Path , err ) return err } url := dfltProtocol + " " + targ + jdata . Oem . HPE . Links . SecurityService . ID taskList [ ii ] . Request . URL , _ = neturl . Parse ( url ) } err = doOp ( taskList ) if err != nil { logger . Errorf ( " " , funcName , err ) return err } ignoreBadTasks ( funcName , taskList ) logger . Tracef ( " " , funcName ) for ii := 0 ; ii < len ( taskList ) ; ii ++ { if taskList [ ii ] . Ignore { continue } var jdata hpeSecurityService targ := targFromTask ( & taskList [ ii ] ) err = grabTaskRspData ( funcName , & taskList [ ii ] , & jdata ) if err != nil { logger . Errorf ( " " , funcName , taskList [ ii ] . Request . URL . Path , err ) return err } url := dfltProtocol + " " + targ + jdata . Links . HttpsCert . ID taskList [ ii ] . Request . URL , _ = neturl . Parse ( url ) } err = doOp ( taskList ) if err != nil { logger . Errorf ( " " , funcName , err ) return err } ignoreBadTasks ( funcName , taskList ) logger . Tracef ( " " , funcName ) for ii := 0 ; ii < len ( taskList ) ; ii ++ { if taskList [ ii ] . Ignore { continue } var jdata hpeSecurityServiceHttpsCert targ := targFromTask ( & taskList [ ii ] ) err = grabTaskRspData ( funcName , & taskList [ ii ] , & jdata ) if err != nil { logger . Errorf ( " " , funcName , taskList [ ii ] . Request . URL . Path , err ) return err } pld := makeRFCertPayload ( VendorHPE , certs [ ii ] , " " , " " ) url := dfltProtocol + " " + targ + jdata . Actions . ImportCertificate . Target taskList [ ii ] . Request , _ = http . NewRequest ( " " , url , bytes . NewBuffer ( pld ) ) taskList [ ii ] . Request . Header . Set ( CT_TYPE , CT_APPJSON ) } err = doOp ( taskList ) if err != nil { logger . Errorf ( " " , funcName , err ) return err } ignoreBadTasks ( funcName , taskList ) logger . Tracef ( " " , funcName ) return nil }
HPE blade cert replacement.
HPE blade cert replacement .
// GET /redfish/v1/Managers  to get the manager ID (should be only // one entry) //Get the Manager ID and set up the next stage //TODO: will it always just be one manager? //Get the Oem data from the manager account // Get the Cert URL // Get the action info, set the stage for the cert POST //Set up for the cert post