NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

public async Task<object> PushDataToPricing(string id, string submissionId, int version)
{
int quoteId = 0;
string reqBody = "";
object dynamicObj = new object();

// Get Bearer Token
var bearerToken = await GetMulesoftToken();
var maskedToken = MaskToken(bearerToken); // ✅ Sanitize before logging
_logger.LogInformation("APIM Token Received (masked): " + maskedToken);

if (!string.IsNullOrEmpty(bearerToken))
{
try
{
int raf_version = await GetRafVersionFromSubmissionMasterAsync(submissionId);
var subDetails = await _cosmosDbService.GetSubmissionDetailsByIdAsync(submissionId, version);
_logger.LogInformation("Submission Summary Extracted");

var submission_summary = await _cosmosDbService.GetSubmissionSummaryByIdAsync(submissionId, version);
_logger.LogInformation("Submission Details Extracted");

var client = new HttpClient();
string revenueSize = submission_summary?.client?.annual_revenue;
var cyberDomainData = await GetCyberDomainData(revenueSize);

var results = new List<PromptOutput>();
var query = new QueryDefinition(CosmosQueries.SQL_CORE_EVAL_PREVIOUS_VERSION_V2)
.WithParameter("@submissionId", submissionId)
.WithParameter("@version", version);

_logger.LogInformation($"Pricing Query For Execution: {query.QueryText}");
var iterator = _promptOutputConatiner.GetItemQueryIterator<PromptOutput>(query);
while (iterator.HasMoreResults)
{
var response = await iterator.ReadNextAsync();
results.AddRange(response.Resource);
}

var ppr = await PreparePricingPushRequestV2(results, subDetails, raf_version, submission_summary, cyberDomainData);
reqBody = JsonConvert.SerializeObject(ppr);

_logger.LogInformation($"RuleBook Push Request Payload : {reqBody}");

client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", bearerToken);
var content = new StringContent(reqBody, Encoding.UTF8, "application/json");

var pushRes = await client.PostAsync(_apimEndpoint, content);
string pushResBody = await pushRes.Content.ReadAsStringAsync();
dynamic res = JsonConvert.DeserializeObject(pushResBody);

if (pushRes.IsSuccessStatusCode)
{
string rulebookQuoteReference = res?.RulebookQuoteReference;
string recordEntryGuidStr = res?.RecordEntryGuid;
Guid? recordEntryGuid = Guid.TryParse(recordEntryGuidStr, out var guid) ? guid : null;

await _cosmosDbService.UpdateQuoteLogFieldsAsync(
id,
recordEntryGuidStr,
rulebookQuoteReference,
null,
null,
DateTime.UtcNow,
DateTime.UtcNow
);

// Save success log
var historyLog = new Quotelog
{
id = Guid.NewGuid().ToString(),
RecordEntryGuid = recordEntryGuid,
RulebookQuoteReference = rulebookQuoteReference,
ErrorCode = null,
ErrorMessage = null,
ErrorDescription = null,
RequestDateTime = DateTime.UtcNow,
ResponseDateTime = DateTime.UtcNow
};
await _cosmosDbService.InsertQuoteHistoryLogAsync(historyLog);

dynamicObj = new
{
RecordEntryGuid = recordEntryGuidStr,
RulebookQuoteReference = rulebookQuoteReference
};
}
else
{
string errorCode = res?.errorCode;
string errorDescription = res?.errorDescription;

_logger.LogError("Error pushing to Rulebook " + pushResBody);

await _cosmosDbService.UpdateQuoteLogFieldsAsync(
id,
null,
null,
errorCode,
errorDescription,
DateTime.UtcNow,
DateTime.UtcNow
);

// Save error log
var historyLog = new Quotelog
{
id = Guid.NewGuid().ToString(),
RecordEntryGuid = null,
RulebookQuoteReference = null,
ErrorCode = errorCode,
ErrorMessage = errorDescription,
ErrorDescription = errorDescription,
RequestDateTime = DateTime.UtcNow,
ResponseDateTime = DateTime.UtcNow
};
await _cosmosDbService.InsertQuoteHistoryLogAsync(historyLog);

dynamicObj = new
{
errorCode = errorCode,
errorMessage = errorDescription,
errorDescription = errorDescription,
DateTime.UtcNow
};
}
}
catch (Exception error)
{
_logger.LogError($"Rulebook Exception: {error}");
_logger.LogInformation($"Rulebook Push Request Payload : {reqBody}");

// Save exception log
var historyLog = new Quotelog
{
id = Guid.NewGuid().ToString(),
RecordEntryGuid = null,
RulebookQuoteReference = null,
ErrorCode = "Exception",
ErrorMessage = error.Message,
ErrorDescription = error.ToString(),
RequestDateTime = DateTime.UtcNow,
ResponseDateTime = DateTime.UtcNow
};
await _cosmosDbService.InsertQuoteHistoryLogAsync(historyLog);

}
}
else
{
_logger.LogCritical("APIM Token NOT Received");

// Save token failure log
var historyLog = new Quotelog
{
RecordEntryGuid = null,
RulebookQuoteReference = null,
ErrorCode = "TOKEN_FAILURE",
ErrorMessage = "Bearer token was null or empty.",
ErrorDescription = "Could not fetch APIM bearer token.",
RequestDateTime = DateTime.UtcNow,
ResponseDateTime = DateTime.UtcNow
};
await _cosmosDbService.InsertQuoteHistoryLogAsync(historyLog);
_logger.LogInformation("Saving quote history: " + JsonConvert.SerializeObject(historyLog));

}

return dynamicObj;
}

/// <summary>
/// ✅ Helper to mask token before logging (prevents vulnerability)
/// </summary>
private string MaskToken(string token)
{
if (string.IsNullOrEmpty(token) || token.Length <= 8)
return "****";

return token.Substring(0, 4) + new string('*', token.Length - 8) + token.Substring(token.Length - 4);
}
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.