atomic-integration-proxy 0.4.3

OAuth/catalog integration proxy (pinned OpenAPI catalog, connections owned by Atomic agents, Atomic v2 request signatures, delegations and frame capabilities) used by Atomic Server and LocalThought
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
//! The consumer routes (`webhook-subscriptions` ยง7), mounted only with
//! `WEBHOOKS_ENABLED=true`. Every one is signed (Atomic v2, single use) by
//! the subscription's consumer: the connection's owner, a delegate, or a
//! runtime of a delegated app, checked on every request, so removing a
//! delegation stops reads at once. Ids in paths are not credentials.
//!
//! | route | effect |
//! |---|---|
//! | `POST /connections/{id}/subscriptions` | access check, then a subscription on the platform's shared hook |
//! | `GET /subscriptions/{id}` | the subscription |
//! | `DELETE /subscriptions/{id}` | ends it |
//! | `POST /subscriptions/{id}/renew` | access check, then a new lease |
//! | `GET /subscriptions/{id}/events?after=&limit=&maxBytes=&wait=` | a page of at most `maxBytes` payload bytes; waits up to `wait` (at most 25) seconds for one |
//! | `POST /subscriptions/{id}/ack` `{generation, cursor}` | acknowledges up to the cursor |
//! | `POST /subscriptions/{id}/reconciled` `{generation, barrier}` | access check, then `active` |

use std::collections::BTreeMap;
use std::sync::Arc;
use std::time::Duration;

use axum::{
    body::Bytes,
    extract::{OriginalUri, Path, Query, State},
    http::{header, HeaderMap, Method, StatusCode},
    response::{IntoResponse, Response},
    Json,
};
use serde::Deserialize;

use super::provider::{check_access, deliveries, parameters, Checked};
use super::store::{ended, now, AccessCheck, Binding, InboxError, NewSubscription};
use super::Webhooks;
use crate::{api_error::ApiError, security::Standing, AppState};

/// Longest long-poll wait (`fetch.maxWaitSeconds`).
pub const MAX_WAIT: Duration = Duration::from_secs(25);
const MAX_PARAMETERS: usize = 16;

fn no_store(mut response: Response) -> Response {
    response
        .headers_mut()
        .insert(header::CACHE_CONTROL, "no-store".parse().unwrap());
    response
}

/// An inbox error as the spec's Error record, or its
/// `reconciliation-required` result for an ended subscription.
fn inbox_error(error: InboxError) -> Response {
    if let InboxError::Ended(result) = error {
        return no_store((StatusCode::GONE, Json(*result)).into_response());
    }
    let status = match &error {
        InboxError::UnknownSubscription => StatusCode::NOT_FOUND,
        InboxError::ObsoleteGeneration
        | InboxError::CursorNotIssued
        | InboxError::CursorAhead
        | InboxError::BarrierMismatch
        | InboxError::NotReconciling => StatusCode::CONFLICT,
        InboxError::QuotaExceeded => StatusCode::TOO_MANY_REQUESTS,
        InboxError::UnknownConnection | InboxError::UnknownHook => StatusCode::FORBIDDEN,
        InboxError::AccessCheckRequired => StatusCode::FORBIDDEN,
        InboxError::Database(_)
        | InboxError::CapacityUnavailable
        | InboxError::AccessUnavailable
        | InboxError::Ended(_) => StatusCode::SERVICE_UNAVAILABLE,
    };
    if let InboxError::Database(message) = &error {
        tracing::error!(%message, "webhook inbox request failed");
    }
    no_store(
        (
            status,
            Json(serde_json::json!({"status": "error", "code": error.code()})),
        )
            .into_response(),
    )
}

fn bad_request(message: &'static str) -> Response {
    no_store(ApiError::BadRequest(message).into_response())
}

fn webhooks(state: &AppState) -> Result<Arc<Webhooks>, Box<Response>> {
    state
        .webhooks
        .clone()
        .ok_or_else(|| Box::new(no_store(StatusCode::NOT_FOUND.into_response())))
}

/// Device grants can only consume fixed change hints, never retained provider
/// bodies. Selection is checked for every subscription operation.
async fn notification_signer(
    state: &AppState,
    security: &crate::security::Security,
    method: &Method,
    uri: &axum::http::Uri,
    headers: &HeaderMap,
    body: &[u8],
) -> Result<(crate::agent_id::AgentId, Option<Vec<String>>), ApiError> {
    if let Some(token) = crate::device::bearer(headers)? {
        let principal = crate::device::principal(state, token).await?;
        if !state
            .webhooks
            .as_ref()
            .is_some_and(|w| w.notifications_only)
            || !principal
                .scope
                .split_ascii_whitespace()
                .any(|s| s == crate::device::NOTIFICATION_SCOPE)
        {
            return Err(ApiError::TokenScope);
        }
        return Ok((principal.owner, Some(principal.connections)));
    }
    Ok((
        crate::signature::authenticate(state, security, method, uri, headers, body).await?,
        None,
    ))
}

/// Authenticates the request and checks the signer is still the
/// subscription's consumer with standing on its connection.
async fn consumer(
    state: &AppState,
    id: &str,
    method: &Method,
    uri: &axum::http::Uri,
    headers: &HeaderMap,
    body: &[u8],
) -> Result<(Arc<Webhooks>, Binding), Box<Response>> {
    let webhooks = webhooks(state)?;
    let security = state
        .security
        .as_ref()
        .ok_or_else(|| Box::new(no_store(ApiError::Unavailable.into_response())))?;
    let (signer, selected) = notification_signer(state, security, method, uri, headers, body)
        .await
        .map_err(|e| Box::new(no_store(e.into_response())))?;
    let binding = match webhooks.store.binding(id).await {
        Ok(Some(binding)) if binding.consumer == signer.as_str() => binding,
        Ok(_) => return Err(Box::new(inbox_error(InboxError::UnknownSubscription))),
        Err(error) => return Err(Box::new(inbox_error(error))),
    };
    if selected
        .as_ref()
        .is_some_and(|ids| !ids.contains(&binding.connection_id))
    {
        return Err(Box::new(no_store(ApiError::TokenScope.into_response())));
    }
    // Standing is checked whatever the subscription's state, so a former
    // consumer reads nothing, not even a closed subscription's tombstone.
    let standing = security
        .standing(&binding.connection_id, &binding.owner, signer.as_str())
        .await
        .map_err(|_| Box::new(no_store(ApiError::Unavailable.into_response())))?;
    if standing == Standing::None {
        // The delegation or runtime was removed: nothing more is served.
        if binding.live {
            let _ = webhooks.store.close(id, ended::STANDING_LOST, now()).await;
        }
        return Err(Box::new(no_store(ApiError::NotDelegated.into_response())));
    }
    let owner = crate::agent_id::parse(&binding.owner)
        .ok_or_else(|| Box::new(no_store(ApiError::Internal.into_response())))?;
    crate::check_access(state, &owner)
        .await
        .map_err(|e| Box::new(no_store(e.into_response())))?;
    Ok((webhooks, binding))
}

/// Re-runs the binding's access check with its recorded parameters.
async fn recheck(state: &AppState, binding: &Binding) -> AccessCheck {
    let (Some(deliveries), Some(values)) = (
        deliveries(state, &binding.platform),
        parameters(&binding.access_parameters),
    ) else {
        return AccessCheck::Failed;
    };
    check_access(
        state,
        &binding.connection_id,
        &binding.platform,
        &deliveries,
        &binding.source_kind,
        &values,
    )
    .await
    .against(&binding.source_key)
}

#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
pub struct SubscribeBody {
    source: String,
    #[serde(default)]
    parameters: BTreeMap<String, String>,
    events: Vec<String>,
}

/// `POST /connections/{id}/subscriptions`
pub async fn subscribe(
    State(state): State<AppState>,
    Path(connection_id): Path<String>,
    method: Method,
    OriginalUri(uri): OriginalUri,
    headers: HeaderMap,
    body: Bytes,
) -> Response {
    let webhooks = match webhooks(&state) {
        Ok(webhooks) => webhooks,
        Err(response) => return *response,
    };
    let Some(security) = state.security.as_ref() else {
        return no_store(ApiError::Unavailable.into_response());
    };
    let (signer, selected) =
        match notification_signer(&state, security, &method, &uri, &headers, &body).await {
            Ok(signer) => signer,
            Err(error) => return no_store(error.into_response()),
        };
    if selected
        .as_ref()
        .is_some_and(|ids| !ids.contains(&connection_id))
    {
        return no_store(ApiError::TokenScope.into_response());
    }
    if connection_id.len() != 43 {
        return no_store(ApiError::UnknownConnection.into_response());
    }
    let record = match security.load_connection(&connection_id).await {
        Ok(Some(record)) => record,
        Ok(None) => return no_store(ApiError::UnknownConnection.into_response()),
        Err(_) => return no_store(ApiError::Unavailable.into_response()),
    };
    match security
        .standing(&connection_id, &record.owner, signer.as_str())
        .await
    {
        Ok(Standing::None) => return no_store(ApiError::NotDelegated.into_response()),
        Ok(_) => {}
        Err(_) => return no_store(ApiError::Unavailable.into_response()),
    }
    let Some(owner) = crate::agent_id::parse(&record.owner) else {
        return no_store(ApiError::Internal.into_response());
    };
    if let Err(error) = crate::check_access(&state, &owner).await {
        return no_store(error.into_response());
    }
    // Before anything reaches the provider.
    if let Err(retry) = webhooks
        .limits
        .subscribe_per_owner
        .take(owner.as_str(), std::time::Instant::now())
    {
        return super::limits::too_many(retry);
    }
    let Ok(request) = serde_json::from_slice::<SubscribeBody>(&body) else {
        return bad_request("expected {source, parameters, events}");
    };
    let Some(deliveries) = deliveries(&state, &record.platform) else {
        return bad_request("this platform declares no webhook deliveries");
    };
    if !deliveries.sources.contains_key(&request.source) {
        return bad_request("unknown source kind");
    }
    let mut events = request.events.clone();
    events.sort();
    events.dedup();
    if events.is_empty()
        || events.len() != request.events.len()
        || !events.iter().all(|event| {
            deliveries
                .events
                .get(event)
                .is_some_and(|declared| declared.source == request.source)
        })
    {
        return bad_request("events must be distinct declared events of the source kind");
    }
    if request.parameters.len() > MAX_PARAMETERS {
        return bad_request("too many parameters");
    }
    if deliveries.shared_profile.is_none() {
        // Creating a provider hook is a provider write; this release makes none.
        return bad_request("this platform has no shared application hook");
    }
    if webhooks.shared_secret(&record.platform).is_none() {
        return inbox_error(InboxError::CapacityUnavailable);
    }
    let key = match check_access(
        &state,
        &connection_id,
        &record.platform,
        &deliveries,
        &request.source,
        &request.parameters,
    )
    .await
    {
        Checked::Passed(key) => key,
        Checked::Failed => {
            return no_store(
                ApiError::AccessDenied("the access check failed".into()).into_response(),
            )
        }
        Checked::Unavailable => return inbox_error(InboxError::AccessUnavailable),
        Checked::Invalid(message) => return bad_request(message),
    };
    let current = now();
    let hook = match webhooks
        .store
        .ensure_shared_hook(&record.platform, current)
        .await
    {
        Ok(hook) => hook,
        Err(error) => return inbox_error(error),
    };
    match webhooks
        .store
        .create_subscription(
            NewSubscription {
                connection_id,
                owner: record.owner,
                consumer: signer.as_str().to_owned(),
                hook_id: hook.hook_id,
                source_kind: request.source,
                source_key: key,
                events,
                access_parameters: serde_json::to_string(&request.parameters).unwrap_or_default(),
            },
            current,
        )
        .await
    {
        Ok(view) => no_store((StatusCode::CREATED, Json(view)).into_response()),
        Err(error) => inbox_error(error),
    }
}

/// `GET /subscriptions/{id}`
pub async fn get(
    State(state): State<AppState>,
    Path(id): Path<String>,
    method: Method,
    OriginalUri(uri): OriginalUri,
    headers: HeaderMap,
    body: Bytes,
) -> Response {
    let (webhooks, binding) = match consumer(&state, &id, &method, &uri, &headers, &body).await {
        Ok(found) => found,
        Err(response) => return *response,
    };
    match webhooks.store.get(&id, &binding.consumer, now()).await {
        Ok(view) => no_store(Json(view).into_response()),
        Err(error) => inbox_error(error),
    }
}

/// `DELETE /subscriptions/{id}`
pub async fn delete(
    State(state): State<AppState>,
    Path(id): Path<String>,
    method: Method,
    OriginalUri(uri): OriginalUri,
    headers: HeaderMap,
    body: Bytes,
) -> Response {
    let (webhooks, binding) = match consumer(&state, &id, &method, &uri, &headers, &body).await {
        Ok(found) => found,
        Err(response) => return *response,
    };
    match webhooks.store.delete(&id, &binding.consumer, now()).await {
        Ok(view) => no_store(Json(view).into_response()),
        Err(error) => inbox_error(error),
    }
}

/// `POST /subscriptions/{id}/renew`
pub async fn renew(
    State(state): State<AppState>,
    Path(id): Path<String>,
    method: Method,
    OriginalUri(uri): OriginalUri,
    headers: HeaderMap,
    body: Bytes,
) -> Response {
    let (webhooks, binding) = match consumer(&state, &id, &method, &uri, &headers, &body).await {
        Ok(found) => found,
        Err(response) => return *response,
    };
    let access = recheck(&state, &binding).await;
    match webhooks
        .store
        .renew(&id, &binding.consumer, access, now())
        .await
    {
        Ok(view) => no_store(Json(view).into_response()),
        Err(error) => inbox_error(error),
    }
}

#[derive(Deserialize)]
pub struct EventsQuery {
    after: Option<String>,
    limit: Option<i64>,
    /// Payload bytes per page, base64 (Webhook Subscriptions 0.2.0-draft
    /// ยง7). Zero, or anything that is not an integer, is refused with `400`
    /// by the query extractor.
    #[serde(rename = "maxBytes")]
    max_bytes: Option<std::num::NonZeroU64>,
    wait: Option<u64>,
    /// Accepted for the spec's route; the cursor carries the generation.
    #[allow(dead_code)]
    generation: Option<String>,
}

/// `GET /subscriptions/{id}/events`
pub async fn events(
    State(state): State<AppState>,
    Path(id): Path<String>,
    Query(query): Query<EventsQuery>,
    method: Method,
    OriginalUri(uri): OriginalUri,
    headers: HeaderMap,
    body: Bytes,
) -> Response {
    let (webhooks, binding) = match consumer(&state, &id, &method, &uri, &headers, &body).await {
        Ok(found) => found,
        Err(response) => return *response,
    };
    let limit = query.limit.unwrap_or(i64::MAX);
    let requested = Duration::from_secs(query.wait.unwrap_or(0)).min(MAX_WAIT);
    // A waiting slot, within the caps per consumer and in all; without one
    // the request answers at once instead of waiting.
    let waiting = if requested.is_zero() {
        None
    } else {
        match WaitingSlot::take(&webhooks, &binding.consumer) {
            Some(slot) => Some(slot),
            // Over the caps: try again shortly rather than poll at once.
            None => {
                let mut response = inbox_error(InboxError::CapacityUnavailable);
                *response.status_mut() = StatusCode::TOO_MANY_REQUESTS;
                response
                    .headers_mut()
                    .insert(header::RETRY_AFTER, "5".parse().unwrap());
                return response;
            }
        }
    };
    let deadline = tokio::time::Instant::now() + requested;
    // Released on drop, also when the client goes away mid-poll.
    let waker = Waiter::new(webhooks.store.clone(), &id);
    let mut checked = false;
    let response = loop {
        // Registered before the read, so a delivery stored between the read
        // and the wait still wakes this request. Only this subscription's
        // deliveries wake it.
        let notified = waker.notified();
        tokio::pin!(notified);
        notified.as_mut().enable();
        match webhooks
            .store
            .fetch_within(
                &id,
                &binding.consumer,
                query.after.as_deref(),
                limit,
                query.max_bytes.map(std::num::NonZeroU64::get),
                now(),
            )
            .await
        {
            Ok(page)
                if page.events.is_empty()
                    && page.reconciliation_required.is_none()
                    && tokio::time::Instant::now() < deadline =>
            {
                tokio::select! {
                    _ = &mut notified => continue,
                    _ = tokio::time::sleep_until(deadline) => {
                        break no_store(Json(page).into_response());
                    }
                }
            }
            Ok(page) => break no_store(Json(page).into_response()),
            Err(InboxError::AccessCheckRequired) if !checked => {
                // The receiver runs the check itself rather than serve
                // events on a stale one (Webhook Deliveries ยง4.4.1).
                checked = true;
                let access = recheck(&state, &binding).await;
                if let Err(error) = webhooks
                    .store
                    .record_access_check(&id, &binding.consumer, access, now())
                    .await
                {
                    break inbox_error(error);
                }
            }
            Err(error) => break inbox_error(error),
        }
    };
    drop(waker);
    drop(waiting);
    response
}

/// A long poll's wakeup, released from the store's map on drop.
struct Waiter {
    store: Arc<super::Store>,
    id: String,
    notify: Option<Arc<tokio::sync::Notify>>,
}

impl Waiter {
    fn new(store: Arc<super::Store>, id: &str) -> Self {
        let notify = store.waiter(id);
        Self {
            store,
            id: id.to_owned(),
            notify: Some(notify),
        }
    }

    fn notified(&self) -> tokio::sync::futures::Notified<'_> {
        self.notify.as_ref().expect("held until drop").notified()
    }
}

impl Drop for Waiter {
    fn drop(&mut self) {
        if let Some(notify) = self.notify.take() {
            self.store.release_waiter(&self.id, notify);
        }
    }
}

/// One waiting long poll, counted per consumer and in all until dropped.
struct WaitingSlot {
    webhooks: Arc<Webhooks>,
    consumer: String,
}

impl WaitingSlot {
    fn take(webhooks: &Arc<Webhooks>, consumer: &str) -> Option<Self> {
        let mut waiting = webhooks.waiting.lock().unwrap_or_else(|e| e.into_inner());
        let total: usize = waiting.values().sum();
        let mine = waiting.get(consumer).copied().unwrap_or(0);
        if total >= super::MAX_WAITERS || mine >= super::MAX_WAITERS_PER_CONSUMER {
            return None;
        }
        waiting.insert(consumer.to_owned(), mine + 1);
        Some(Self {
            webhooks: webhooks.clone(),
            consumer: consumer.to_owned(),
        })
    }
}

impl Drop for WaitingSlot {
    fn drop(&mut self) {
        let mut waiting = self
            .webhooks
            .waiting
            .lock()
            .unwrap_or_else(|e| e.into_inner());
        if let Some(count) = waiting.get_mut(&self.consumer) {
            *count -= 1;
            if *count == 0 {
                waiting.remove(&self.consumer);
            }
        }
    }
}

#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
pub struct AckBody {
    generation: String,
    cursor: String,
}

/// `POST /subscriptions/{id}/ack`
pub async fn ack(
    State(state): State<AppState>,
    Path(id): Path<String>,
    method: Method,
    OriginalUri(uri): OriginalUri,
    headers: HeaderMap,
    body: Bytes,
) -> Response {
    let (webhooks, binding) = match consumer(&state, &id, &method, &uri, &headers, &body).await {
        Ok(found) => found,
        Err(response) => return *response,
    };
    let Ok(request) = serde_json::from_slice::<AckBody>(&body) else {
        return bad_request("expected {generation, cursor}");
    };
    match webhooks
        .store
        .acknowledge(
            &id,
            &binding.consumer,
            Some(&request.generation),
            &request.cursor,
            now(),
        )
        .await
    {
        Ok(acknowledged) => no_store(Json(acknowledged).into_response()),
        Err(error) => inbox_error(error),
    }
}

#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ReconciledBody {
    generation: String,
    barrier: String,
}

/// `POST /subscriptions/{id}/reconciled`
pub async fn reconciled(
    State(state): State<AppState>,
    Path(id): Path<String>,
    method: Method,
    OriginalUri(uri): OriginalUri,
    headers: HeaderMap,
    body: Bytes,
) -> Response {
    let (webhooks, binding) = match consumer(&state, &id, &method, &uri, &headers, &body).await {
        Ok(found) => found,
        Err(response) => return *response,
    };
    let Ok(request) = serde_json::from_slice::<ReconciledBody>(&body) else {
        return bad_request("expected {generation, barrier}");
    };
    let access = recheck(&state, &binding).await;
    match webhooks
        .store
        .complete_reconciliation(
            &id,
            &binding.consumer,
            &request.generation,
            &request.barrier,
            access,
            now(),
        )
        .await
    {
        Ok(view) => no_store(Json(view).into_response()),
        Err(error) => inbox_error(error),
    }
}

/// The webhook routes, added to the router only when the inbox is on.
pub fn router() -> axum::Router<AppState> {
    use axum::routing::{get as get_route, post};
    axum::Router::new()
        // The handler reads the raw body itself, after its checks, up to
        // the verification cap; no extractor buffers it first.
        .route("/webhooks/:endpoint_id", post(super::ingress::receive))
        .route("/connections/:connection_id/subscriptions", post(subscribe))
        .route("/subscriptions/:id", get_route(get).delete(delete))
        .route("/subscriptions/:id/renew", post(renew))
        .route("/subscriptions/:id/events", get_route(events))
        .route("/subscriptions/:id/ack", post(ack))
        .route("/subscriptions/:id/reconciled", post(reconciled))
}