| 801 | } |
| 802 | |
| 803 | void JWKSMgr::UpdateJWKSThread() { |
| 804 | std::shared_ptr<JWKSSnapshot> new_jwks; |
| 805 | int64_t timeout_millis = FLAGS_jwks_update_frequency_s * 1000; |
| 806 | while (true) { |
| 807 | // This Get() will time out until shutdown, when the promise is set. |
| 808 | bool timed_out; |
| 809 | shut_down_promise_.Get(timeout_millis, &timed_out); |
| 810 | if (!timed_out) break; |
| 811 | |
| 812 | new_jwks = std::make_shared<JWKSSnapshot>(); |
| 813 | bool is_changed = false; |
| 814 | Status status = |
| 815 | new_jwks->LoadKeysFromUrl(jwks_uri_, jwks_verify_server_certificate_, |
| 816 | jwks_ca_certificate_, current_jwks_checksum_, &is_changed); |
| 817 | if (!status.ok()) { |
| 818 | LOG(WARNING) << "Failed to update JWKS: " << status; |
| 819 | } else if (is_changed) { |
| 820 | SetJWKSSnapshot(new_jwks); |
| 821 | } |
| 822 | new_jwks.reset(); |
| 823 | } |
| 824 | // The promise must be set to true. |
| 825 | DCHECK(shut_down_promise_.IsSet()); |
| 826 | DCHECK(shut_down_promise_.Get()); |
| 827 | } |
| 828 | |
| 829 | JWKSSnapshotPtr JWKSMgr::GetJWKSSnapshot() const { |
| 830 | std::lock_guard<std::mutex> l(current_jwks_lock_); |
nothing calls this directly
no test coverage detected