| 756 | } |
| 757 | |
| 758 | Status JWKSMgr::Init(const std::string& jwks_uri, bool jwks_verify_server_certificate, |
| 759 | const std::string& jwks_ca_certificate, bool is_local_file) { |
| 760 | Status status; |
| 761 | jwks_uri_ = jwks_uri; |
| 762 | jwks_verify_server_certificate_ = jwks_verify_server_certificate; |
| 763 | jwks_ca_certificate_ = jwks_ca_certificate; |
| 764 | std::shared_ptr<JWKSSnapshot> new_jwks = std::make_shared<JWKSSnapshot>(); |
| 765 | if (is_local_file) { |
| 766 | status = new_jwks->LoadKeysFromFile(jwks_uri); |
| 767 | if (!status.ok()) { |
| 768 | LOG(ERROR) << "Failed to load JWKS: " << status; |
| 769 | return status; |
| 770 | } |
| 771 | SetJWKSSnapshot(new_jwks); |
| 772 | } else { |
| 773 | if (FLAGS_jwks_update_frequency_s <= 0) { |
| 774 | LOG(WARNING) << "Invalid value for flag jwks_update_frequency_s: " |
| 775 | << FLAGS_jwks_update_frequency_s << ", use default value 60."; |
| 776 | FLAGS_jwks_update_frequency_s = 60; |
| 777 | } |
| 778 | if (FLAGS_jwks_pulling_timeout_s <= 0) { |
| 779 | LOG(WARNING) << "Invalid value for flag jwks_pulling_timeout_s: " |
| 780 | << FLAGS_jwks_pulling_timeout_s << ", use default value 10."; |
| 781 | FLAGS_jwks_pulling_timeout_s = 10; |
| 782 | } |
| 783 | |
| 784 | bool is_changed = false; |
| 785 | status = new_jwks->LoadKeysFromUrl(jwks_uri, jwks_verify_server_certificate, |
| 786 | jwks_ca_certificate, current_jwks_checksum_, &is_changed); |
| 787 | if (!status.ok()) { |
| 788 | LOG(ERROR) << "Failed to load JWKS: " << status; |
| 789 | return status; |
| 790 | } |
| 791 | DCHECK(is_changed); |
| 792 | if (is_changed) SetJWKSSnapshot(new_jwks); |
| 793 | |
| 794 | // Start a working thread to periodically check the JWKS URL for updates. |
| 795 | RETURN_IF_ERROR(Thread::Create("impala-server", "JWKS-mgr", |
| 796 | &JWKSMgr::UpdateJWKSThread, this, &jwks_update_thread_)); |
| 797 | } |
| 798 | |
| 799 | if (new_jwks->IsEmpty()) LOG(WARNING) << "JWKS file is empty."; |
| 800 | return Status::OK(); |
| 801 | } |
| 802 | |
| 803 | void JWKSMgr::UpdateJWKSThread() { |
| 804 | std::shared_ptr<JWKSSnapshot> new_jwks; |
nothing calls this directly
no test coverage detected