Create a new SignerClient
(signer_server_url: Url, jwt_secret: Jwt, module_id: ModuleId)
| 36 | impl SignerClient { |
| 37 | /// Create a new SignerClient |
| 38 | pub fn new(signer_server_url: Url, jwt_secret: Jwt, module_id: ModuleId) -> eyre::Result<Self> { |
| 39 | let jwt = create_jwt(&module_id, &jwt_secret)?; |
| 40 | |
| 41 | let mut auth_value = |
| 42 | HeaderValue::from_str(&format!("Bearer {jwt}")).wrap_err("invalid jwt")?; |
| 43 | auth_value.set_sensitive(true); |
| 44 | |
| 45 | let mut headers = HeaderMap::new(); |
| 46 | headers.insert(AUTHORIZATION, auth_value); |
| 47 | |
| 48 | let client = reqwest::Client::builder() |
| 49 | .timeout(DEFAULT_REQUEST_TIMEOUT) |
| 50 | .default_headers(headers) |
| 51 | .build()?; |
| 52 | |
| 53 | Ok(Self { |
| 54 | url: signer_server_url, |
| 55 | client, |
| 56 | last_jwt_refresh: Instant::now(), |
| 57 | module_id, |
| 58 | jwt_secret, |
| 59 | }) |
| 60 | } |
| 61 | |
| 62 | fn refresh_jwt(&mut self) -> Result<(), SignerClientError> { |
| 63 | if self.last_jwt_refresh.elapsed() > Duration::from_secs(SIGNER_JWT_EXPIRATION) { |
nothing calls this directly
no test coverage detected