MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / validateAuthKey

Method validateAuthKey

src/utilities/bcl/RemoteBCL.cpp:439–500  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

437}
438
439bool RemoteBCL::validateAuthKey(const std::string& authKey, const std::string& remoteUrl) {
440 if (authKey.length() == 32) {
441 std::string previousUrl = this->remoteUrl();
442
443 // Check if validation has already run for the given key
444 if (remoteUrl == remoteProductionUrl() && authKey == prodAuthKey() && validProdAuthKey) {
445 return true;
446 } else if (remoteUrl == remoteDevelopmentUrl() && authKey == devAuthKey() && validDevAuthKey) {
447 return true;
448 }
449
450 // Temporarily set url
451 if (remoteUrl == remoteDevelopmentUrl()) {
452 useRemoteDevelopmentUrl();
453 } else {
454 useRemoteProductionUrl();
455 }
456
457 // can't start another request until last one is done
458 if (m_httpResponse && !m_httpResponse->is_done()) {
459 return false;
460 }
461
462 m_lastSearch.clear();
463
464 auto client = getClient(remoteUrl, m_timeOutSeconds);
465 web::uri_builder builder(to_string_t("/api/search/"));
466
467 builder.append_path(to_string_t("*.xml"));
468
469 builder.append_query(to_string_t("api_version"), to_string_t(m_apiVersion));
470 builder.append_query(to_string_t("show_rows"), to_string_t("0"));
471
472 // LOG(Debug, m_remoteUrl << builder.to_string());
473
474 m_httpResponse = client.request(web::http::methods::GET, builder.to_string())
475 .then([](web::http::http_response resp) { return resp.extract_utf8string(); })
476 .then([this](const std::string& xml) {
477 auto remoteQueryResponse = processReply(xml);
478
479 if (remoteQueryResponse) {
480 m_lastSearch = processSearchResponse(*remoteQueryResponse);
481 }
482 });
483
484 waitForSearch();
485
486 // Restore url
487 if (previousUrl == remoteDevelopmentUrl()) {
488 useRemoteDevelopmentUrl();
489 } else {
490 useRemoteProductionUrl();
491 }
492
493 if (remoteUrl == remoteDevelopmentUrl()) {
494 return validDevAuthKey;
495 } else {
496 return validProdAuthKey;

Callers

nothing calls this directly

Calls 5

remoteUrlMethod · 0.95
requestMethod · 0.80
to_stringMethod · 0.80
lengthMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected