gestalt-sdk 0.0.1-alpha.19

Rust SDK scaffolding and generated protocol bindings for Gestalt executable providers
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
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
// Code generated by sdkgen. DO NOT EDIT.

//! Generated native types and clients for s3.proto.

use crate::codec::host_service::{HostServiceChannel, connect_host_service, plain_channel};
use crate::codec::s3::{
    from_wire_copy_object_response, from_wire_create_object_access_url_response,
    from_wire_head_object_response, from_wire_list_objects_response,
    from_wire_presign_object_response, from_wire_read_object_chunk,
    from_wire_write_object_response, to_wire_copy_object_request,
    to_wire_create_object_access_url_request, to_wire_delete_object_request,
    to_wire_head_object_request, to_wire_list_objects_request, to_wire_presign_object_request,
    to_wire_read_object_request, to_wire_write_object_request,
};
use crate::generated::v1;
use crate::rpc_support::{GestaltError, gestalt_error_code};
use tokio_stream::StreamExt;

/// Open enum for `gestalt.provider.v1.PresignMethod`; unknown numeric values are preserved.
pub type PresignMethod = i32;

/// PresignMethod identifies the HTTP verb encoded into a presigned URL.
///
/// Named values of `PresignMethod`.
pub mod presign_method {
    /// PRESIGN_METHOD_UNSPECIFIED.
    pub const PRESIGN_METHOD_UNSPECIFIED: i32 = 0;
    /// PRESIGN_METHOD_GET.
    pub const PRESIGN_METHOD_GET: i32 = 1;
    /// PRESIGN_METHOD_PUT.
    pub const PRESIGN_METHOD_PUT: i32 = 2;
    /// PRESIGN_METHOD_DELETE.
    pub const PRESIGN_METHOD_DELETE: i32 = 3;
    /// PRESIGN_METHOD_HEAD.
    pub const PRESIGN_METHOD_HEAD: i32 = 4;
}

/// ByteRange requests a half-open slice of an object's bytes.
///
/// Native message type for `gestalt.provider.v1.ByteRange`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct ByteRange {
    /// The `start` field; None when unset.
    pub start: Option<i64>,
    /// The `end` field; None when unset.
    pub end: Option<i64>,
}

/// CopyObjectRequest copies one object to another location.
///
/// Native message type for `gestalt.provider.v1.CopyObjectRequest`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct CopyObjectRequest {
    /// The `source` field; None when unset.
    pub source: Option<S3ObjectRef>,
    /// The `destination` field; None when unset.
    pub destination: Option<S3ObjectRef>,
    /// The `if_match` field.
    pub if_match: String,
    /// The `if_none_match` field.
    pub if_none_match: String,
}

/// CopyObjectResponse returns metadata for the copied object.
///
/// Native message type for `gestalt.provider.v1.CopyObjectResponse`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct CopyObjectResponse {
    /// The `meta` field; None when unset.
    pub meta: Option<S3ObjectMeta>,
}

/// CreateObjectAccessURLRequest asks the host to mint an HTTP object-access URL
/// for a plugin-scoped S3 binding. The host authorizes and scopes the URL, then
/// streams object bytes through the backing S3 provider.
///
/// Native message type for `gestalt.provider.v1.CreateObjectAccessURLRequest`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct CreateObjectAccessURLRequest {
    /// The `ref` field; None when unset.
    pub r#ref: Option<S3ObjectRef>,
    /// The `method` field.
    pub method: PresignMethod,
    /// The `expires_seconds` field.
    pub expires_seconds: i64,
    /// The `content_type` field.
    pub content_type: String,
    /// The `content_disposition` field.
    pub content_disposition: String,
    /// The `headers` field.
    pub headers: std::collections::BTreeMap<String, String>,
}

/// CreateObjectAccessURLResponse returns a hosted object-access URL plus any
/// headers the caller must include when using it.
///
/// Native message type for `gestalt.provider.v1.CreateObjectAccessURLResponse`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct CreateObjectAccessURLResponse {
    /// The `url` field.
    pub url: String,
    /// The `method` field.
    pub method: PresignMethod,
    /// The `expires_at` field; None when unset.
    pub expires_at: Option<std::time::SystemTime>,
    /// The `headers` field.
    pub headers: std::collections::BTreeMap<String, String>,
}

/// DeleteObjectRequest removes one object.
///
/// Native message type for `gestalt.provider.v1.DeleteObjectRequest`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct DeleteObjectRequest {
    /// The `ref` field; None when unset.
    pub r#ref: Option<S3ObjectRef>,
}

/// HeadObjectRequest fetches metadata for one object.
///
/// Native message type for `gestalt.provider.v1.HeadObjectRequest`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct HeadObjectRequest {
    /// The `ref` field; None when unset.
    pub r#ref: Option<S3ObjectRef>,
}

/// HeadObjectResponse returns object metadata.
///
/// Native message type for `gestalt.provider.v1.HeadObjectResponse`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct HeadObjectResponse {
    /// The `meta` field; None when unset.
    pub meta: Option<S3ObjectMeta>,
}

/// ListObjectsRequest lists objects in the provider's configured bucket.
///
/// Native message type for `gestalt.provider.v1.ListObjectsRequest`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct ListObjectsRequest {
    /// The `prefix` field.
    pub prefix: String,
    /// The `delimiter` field.
    pub delimiter: String,
    /// The `continuation_token` field.
    pub continuation_token: String,
    /// The `start_after` field.
    pub start_after: String,
    /// The `max_keys` field.
    pub max_keys: i32,
}

/// ListObjectsResponse is one page of list-objects results.
///
/// Native message type for `gestalt.provider.v1.ListObjectsResponse`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct ListObjectsResponse {
    /// The `objects` field.
    pub objects: Vec<S3ObjectMeta>,
    /// The `common_prefixes` field.
    pub common_prefixes: Vec<String>,
    /// The `next_continuation_token` field.
    pub next_continuation_token: String,
    /// The `has_more` field.
    pub has_more: bool,
}

/// PresignObjectRequest asks the provider to mint a presigned URL.
///
/// Native message type for `gestalt.provider.v1.PresignObjectRequest`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct PresignObjectRequest {
    /// The `ref` field; None when unset.
    pub r#ref: Option<S3ObjectRef>,
    /// The `method` field.
    pub method: PresignMethod,
    /// The `expires_seconds` field.
    pub expires_seconds: i64,
    /// The `content_type` field.
    pub content_type: String,
    /// The `content_disposition` field.
    pub content_disposition: String,
    /// The `headers` field.
    pub headers: std::collections::BTreeMap<String, String>,
}

/// PresignObjectResponse returns a presigned URL plus any required headers.
///
/// Native message type for `gestalt.provider.v1.PresignObjectResponse`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct PresignObjectResponse {
    /// The `url` field.
    pub url: String,
    /// The `method` field.
    pub method: PresignMethod,
    /// The `expires_at` field; None when unset.
    pub expires_at: Option<std::time::SystemTime>,
    /// The `headers` field.
    pub headers: std::collections::BTreeMap<String, String>,
}

/// Values of the `result` oneof in `ReadObjectChunk`; the message field is None when unset.
#[allow(clippy::enum_variant_names, clippy::large_enum_variant)]
#[derive(Clone, Debug, PartialEq)]
pub enum ReadObjectChunkResult {
    /// The `meta` variant.
    Meta(S3ObjectMeta),
    /// The `data` variant.
    Data(Vec<u8>),
}

/// ReadObjectChunk is one frame in a streaming object read.
///
/// Native message type for `gestalt.provider.v1.ReadObjectChunk`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct ReadObjectChunk {
    /// The `result` oneof; None when unset.
    pub result: Option<ReadObjectChunkResult>,
}

/// ReadObjectRequest opens a streaming object read.
///
/// Native message type for `gestalt.provider.v1.ReadObjectRequest`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct ReadObjectRequest {
    /// The `ref` field; None when unset.
    pub r#ref: Option<S3ObjectRef>,
    /// The `range` field; None when unset.
    pub range: Option<ByteRange>,
    /// The `if_match` field.
    pub if_match: String,
    /// The `if_none_match` field.
    pub if_none_match: String,
    /// The `if_modified_since` field; None when unset.
    pub if_modified_since: Option<std::time::SystemTime>,
    /// The `if_unmodified_since` field; None when unset.
    pub if_unmodified_since: Option<std::time::SystemTime>,
}

/// S3ObjectMeta describes one object returned by the provider.
///
/// Native message type for `gestalt.provider.v1.S3ObjectMeta`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct S3ObjectMeta {
    /// The `ref` field; None when unset.
    pub r#ref: Option<S3ObjectRef>,
    /// The `etag` field.
    pub etag: String,
    /// The `size` field.
    pub size: i64,
    /// The `content_type` field.
    pub content_type: String,
    /// The `last_modified` field; None when unset.
    pub last_modified: Option<std::time::SystemTime>,
    /// The `metadata` field.
    pub metadata: std::collections::BTreeMap<String, String>,
    /// The `storage_class` field.
    pub storage_class: String,
}

/// S3ObjectRef identifies one object or object version.
///
/// Native message type for `gestalt.provider.v1.S3ObjectRef`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct S3ObjectRef {
    /// The `key` field.
    pub key: String,
    /// The `version_id` field.
    pub version_id: String,
}

/// WriteObjectOpen carries the metadata frame that must be sent first in a
/// write-object stream.
///
/// Native message type for `gestalt.provider.v1.WriteObjectOpen`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct WriteObjectOpen {
    /// The `ref` field; None when unset.
    pub r#ref: Option<S3ObjectRef>,
    /// The `content_type` field.
    pub content_type: String,
    /// The `cache_control` field.
    pub cache_control: String,
    /// The `content_disposition` field.
    pub content_disposition: String,
    /// The `content_encoding` field.
    pub content_encoding: String,
    /// The `content_language` field.
    pub content_language: String,
    /// The `metadata` field.
    pub metadata: std::collections::BTreeMap<String, String>,
    /// The `if_match` field.
    pub if_match: String,
    /// The `if_none_match` field.
    pub if_none_match: String,
}

/// Values of the `msg` oneof in `WriteObjectRequest`; the message field is None when unset.
#[allow(clippy::enum_variant_names, clippy::large_enum_variant)]
#[derive(Clone, Debug, PartialEq)]
pub enum WriteObjectRequestMsg {
    /// The `open` variant.
    Open(WriteObjectOpen),
    /// The `data` variant.
    Data(Vec<u8>),
}

/// WriteObjectRequest is one frame in a write-object stream.
///
/// Native message type for `gestalt.provider.v1.WriteObjectRequest`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct WriteObjectRequest {
    /// The `msg` oneof; None when unset.
    pub msg: Option<WriteObjectRequestMsg>,
}

/// WriteObjectResponse returns metadata for the committed object.
///
/// Native message type for `gestalt.provider.v1.WriteObjectResponse`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct WriteObjectResponse {
    /// The `meta` field; None when unset.
    pub meta: Option<S3ObjectMeta>,
}

/// S3 models the shared Gestalt S3-provider protocol.
///
/// Client for the `gestalt.provider.v1.S3` service.
pub struct S3 {
    inner: v1::s3_client::S3Client<HostServiceChannel>,
    timeout: Option<std::time::Duration>,
}

impl S3 {
    /// Creates a client over an established channel.
    pub fn new(channel: tonic::transport::Channel) -> Self {
        Self {
            inner: v1::s3_client::S3Client::new(plain_channel(channel)),
            timeout: None,
        }
    }

    /// Sets a deadline applied to every unary call; calls that run past it
    /// fail with DEADLINE_EXCEEDED. Streaming calls are unaffected.
    pub fn with_timeout(mut self, timeout: std::time::Duration) -> Self {
        self.timeout = Some(timeout);
        self
    }

    /// Connects to the `s3` host service described by the environment.
    pub async fn connect() -> Result<Self, GestaltError> {
        Self::connect_named("").await
    }

    /// Connects to the named `s3` host-service binding.
    pub async fn connect_named(name: &str) -> Result<Self, GestaltError> {
        Ok(Self {
            inner: v1::s3_client::S3Client::new(connect_host_service("s3", name).await?),
            timeout: None,
        })
    }

    /// Calls `gestalt.provider.v1.S3.HeadObject`.
    pub async fn head_object(
        &mut self,
        r#ref: Option<S3ObjectRef>,
    ) -> Result<HeadObjectResponse, GestaltError> {
        let request = HeadObjectRequest { r#ref };
        let mut tonic_request = tonic::Request::new(to_wire_head_object_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = self.inner.head_object(tonic_request).await?;
        Ok(from_wire_head_object_response(response.into_inner()))
    }

    /// Calls `gestalt.provider.v1.S3.HeadObject` with the full request and response messages.
    pub async fn head_object_raw(
        &mut self,
        request: HeadObjectRequest,
    ) -> Result<HeadObjectResponse, GestaltError> {
        let mut tonic_request = tonic::Request::new(to_wire_head_object_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = self.inner.head_object(tonic_request).await?;
        Ok(from_wire_head_object_response(response.into_inner()))
    }

    /// The first response frame carries object metadata. All subsequent frames
    /// carry byte chunks. Zero-byte objects therefore emit exactly one frame.
    ///
    /// Calls `gestalt.provider.v1.S3.ReadObject`, returning the `meta` header and a payload stream.
    pub async fn read_object(
        &mut self,
        request: ReadObjectRequest,
    ) -> Result<(S3ObjectMeta, S3ReadObjectData), GestaltError> {
        let mut frames = self
            .inner
            .read_object(to_wire_read_object_request(request))
            .await?
            .into_inner();
        let frame = frames.message().await?.map(from_wire_read_object_chunk);
        let meta = match frame.and_then(|frame| frame.result) {
            Some(ReadObjectChunkResult::Meta(value)) => value,
            _ => {
                return Err(GestaltError::new(
                    gestalt_error_code::INTERNAL,
                    "stream did not begin with the expected header frame",
                ));
            }
        };
        Ok((meta, S3ReadObjectData { inner: frames }))
    }

    /// The first response frame carries object metadata. All subsequent frames
    /// carry byte chunks. Zero-byte objects therefore emit exactly one frame.
    ///
    /// Calls `gestalt.provider.v1.S3.ReadObject`, returning a stream of converted frames.
    pub async fn read_object_raw(
        &mut self,
        request: ReadObjectRequest,
    ) -> Result<S3ReadObjectStream, GestaltError> {
        let response = self
            .inner
            .read_object(to_wire_read_object_request(request))
            .await?;
        Ok(S3ReadObjectStream {
            inner: response.into_inner(),
        })
    }

    /// The first request frame must carry WriteObjectOpen metadata. All
    /// subsequent frames carry raw bytes. The response is emitted only after the
    /// object has been durably committed by the provider.
    ///
    /// Calls `gestalt.provider.v1.S3.WriteObject`, sending the `open` header frame and then one frame per `data` chunk.
    pub async fn write_object(
        &mut self,
        open: WriteObjectOpen,
        data: impl tokio_stream::Stream<Item = Vec<u8>> + Send + 'static,
    ) -> Result<WriteObjectResponse, GestaltError> {
        let requests = tokio_stream::once(WriteObjectRequest {
            msg: Some(WriteObjectRequestMsg::Open(open)),
        })
        .chain(data.map(|chunk| WriteObjectRequest {
            msg: Some(WriteObjectRequestMsg::Data(chunk)),
        }))
        .map(to_wire_write_object_request);
        let response = self.inner.write_object(requests).await?;
        Ok(from_wire_write_object_response(response.into_inner()))
    }

    /// The first request frame must carry WriteObjectOpen metadata. All
    /// subsequent frames carry raw bytes. The response is emitted only after the
    /// object has been durably committed by the provider.
    ///
    /// Calls `gestalt.provider.v1.S3.WriteObject` with the full request and response messages.
    pub async fn write_object_raw(
        &mut self,
        requests: impl tokio_stream::Stream<Item = WriteObjectRequest> + Send + 'static,
    ) -> Result<WriteObjectResponse, GestaltError> {
        let response = self
            .inner
            .write_object(requests.map(to_wire_write_object_request))
            .await?;
        Ok(from_wire_write_object_response(response.into_inner()))
    }

    /// Calls `gestalt.provider.v1.S3.DeleteObject`.
    pub async fn delete_object(&mut self, r#ref: Option<S3ObjectRef>) -> Result<(), GestaltError> {
        let request = DeleteObjectRequest { r#ref };
        let mut tonic_request = tonic::Request::new(to_wire_delete_object_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        self.inner.delete_object(tonic_request).await?;
        Ok(())
    }

    /// Calls `gestalt.provider.v1.S3.DeleteObject` with the full request and response messages.
    pub async fn delete_object_raw(
        &mut self,
        request: DeleteObjectRequest,
    ) -> Result<(), GestaltError> {
        let mut tonic_request = tonic::Request::new(to_wire_delete_object_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        self.inner.delete_object(tonic_request).await?;
        Ok(())
    }

    /// Calls `gestalt.provider.v1.S3.ListObjects`.
    pub async fn list_objects(
        &mut self,
        prefix: String,
        delimiter: String,
        continuation_token: String,
        start_after: String,
        max_keys: i32,
    ) -> Result<ListObjectsResponse, GestaltError> {
        let request = ListObjectsRequest {
            prefix,
            delimiter,
            continuation_token,
            start_after,
            max_keys,
        };
        let mut tonic_request = tonic::Request::new(to_wire_list_objects_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = self.inner.list_objects(tonic_request).await?;
        Ok(from_wire_list_objects_response(response.into_inner()))
    }

    /// Calls `gestalt.provider.v1.S3.ListObjects` with the full request and response messages.
    pub async fn list_objects_raw(
        &mut self,
        request: ListObjectsRequest,
    ) -> Result<ListObjectsResponse, GestaltError> {
        let mut tonic_request = tonic::Request::new(to_wire_list_objects_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = self.inner.list_objects(tonic_request).await?;
        Ok(from_wire_list_objects_response(response.into_inner()))
    }

    /// Calls `gestalt.provider.v1.S3.CopyObject`.
    pub async fn copy_object(
        &mut self,
        if_match: String,
        if_none_match: String,
        source: Option<S3ObjectRef>,
        destination: Option<S3ObjectRef>,
    ) -> Result<CopyObjectResponse, GestaltError> {
        let request = CopyObjectRequest {
            if_match,
            if_none_match,
            source,
            destination,
        };
        let mut tonic_request = tonic::Request::new(to_wire_copy_object_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = self.inner.copy_object(tonic_request).await?;
        Ok(from_wire_copy_object_response(response.into_inner()))
    }

    /// Calls `gestalt.provider.v1.S3.CopyObject` with the full request and response messages.
    pub async fn copy_object_raw(
        &mut self,
        request: CopyObjectRequest,
    ) -> Result<CopyObjectResponse, GestaltError> {
        let mut tonic_request = tonic::Request::new(to_wire_copy_object_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = self.inner.copy_object(tonic_request).await?;
        Ok(from_wire_copy_object_response(response.into_inner()))
    }

    /// Calls `gestalt.provider.v1.S3.PresignObject`.
    pub async fn presign_object(
        &mut self,
        method: PresignMethod,
        expires_seconds: i64,
        r#ref: Option<S3ObjectRef>,
        options: S3PresignObjectOptions,
    ) -> Result<PresignObjectResponse, GestaltError> {
        let request = PresignObjectRequest {
            method,
            expires_seconds,
            r#ref,
            content_type: options.content_type,
            content_disposition: options.content_disposition,
            ..Default::default()
        };
        let mut tonic_request = tonic::Request::new(to_wire_presign_object_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = self.inner.presign_object(tonic_request).await?;
        Ok(from_wire_presign_object_response(response.into_inner()))
    }

    /// Calls `gestalt.provider.v1.S3.PresignObject` with the full request and response messages.
    pub async fn presign_object_raw(
        &mut self,
        request: PresignObjectRequest,
    ) -> Result<PresignObjectResponse, GestaltError> {
        let mut tonic_request = tonic::Request::new(to_wire_presign_object_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = self.inner.presign_object(tonic_request).await?;
        Ok(from_wire_presign_object_response(response.into_inner()))
    }
}

/// Optional parameters of [`S3::presign_object`]; the default value leaves every
/// option unset.
#[derive(Clone, Debug, Default)]
pub struct S3PresignObjectOptions {
    /// The `content_type` field.
    pub content_type: String,
    /// The `content_disposition` field.
    pub content_disposition: String,
}

/// Payload stream returned by `S3::read_object`; the header frame has already been consumed.
pub struct S3ReadObjectData {
    inner: tonic::Streaming<v1::ReadObjectChunk>,
}

impl S3ReadObjectData {
    /// Receives the next payload chunk, or None when the stream ends.
    pub async fn recv(&mut self) -> Result<Option<Vec<u8>>, GestaltError> {
        match self.inner.message().await?.map(from_wire_read_object_chunk) {
            None => Ok(None),
            Some(frame) => match frame.result {
                Some(ReadObjectChunkResult::Data(value)) => Ok(Some(value)),
                _ => Err(GestaltError::new(
                    gestalt_error_code::INTERNAL,
                    "unexpected frame in payload stream",
                )),
            },
        }
    }

    /// Buffers the remaining payload chunks into one byte vector, like the
    /// AWS SDK's `ByteStream::collect`.
    pub async fn collect(&mut self) -> Result<Vec<u8>, GestaltError> {
        let mut out = Vec::new();
        while let Some(chunk) = self.recv().await? {
            out.extend_from_slice(&chunk);
        }
        Ok(out)
    }
}

/// The first response frame carries object metadata. All subsequent frames
/// carry byte chunks. Zero-byte objects therefore emit exactly one frame.
///
/// Stream of converted `ReadObjectChunk` frames; transport errors convert to GestaltError.
pub struct S3ReadObjectStream {
    inner: tonic::Streaming<v1::ReadObjectChunk>,
}

impl S3ReadObjectStream {
    /// Receives the next frame, or None when the stream ends.
    pub async fn recv(&mut self) -> Result<Option<ReadObjectChunk>, GestaltError> {
        Ok(self.inner.message().await?.map(from_wire_read_object_chunk))
    }
}

/// S3ObjectAccess models host-mediated object access for plugin-scoped S3
/// bindings. It is registered by gestaltd for apps and is not implemented by
/// S3 providers.
///
/// Client for the `gestalt.provider.v1.S3ObjectAccess` service.
pub struct S3ObjectAccess {
    inner: v1::s3_object_access_client::S3ObjectAccessClient<tonic::transport::Channel>,
    timeout: Option<std::time::Duration>,
}

impl S3ObjectAccess {
    /// Creates a client over an established channel.
    pub fn new(channel: tonic::transport::Channel) -> Self {
        Self {
            inner: v1::s3_object_access_client::S3ObjectAccessClient::new(channel),
            timeout: None,
        }
    }

    /// Sets a deadline applied to every unary call; calls that run past it
    /// fail with DEADLINE_EXCEEDED. Streaming calls are unaffected.
    pub fn with_timeout(mut self, timeout: std::time::Duration) -> Self {
        self.timeout = Some(timeout);
        self
    }

    /// Calls `gestalt.provider.v1.S3ObjectAccess.CreateObjectAccessURL`.
    pub async fn create_object_access_url(
        &mut self,
        method: PresignMethod,
        expires_seconds: i64,
        r#ref: Option<S3ObjectRef>,
        options: S3ObjectAccessCreateObjectAccessURLOptions,
    ) -> Result<CreateObjectAccessURLResponse, GestaltError> {
        let request = CreateObjectAccessURLRequest {
            method,
            expires_seconds,
            r#ref,
            content_type: options.content_type,
            content_disposition: options.content_disposition,
            ..Default::default()
        };
        let mut tonic_request =
            tonic::Request::new(to_wire_create_object_access_url_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = self.inner.create_object_access_url(tonic_request).await?;
        Ok(from_wire_create_object_access_url_response(
            response.into_inner(),
        ))
    }

    /// Calls `gestalt.provider.v1.S3ObjectAccess.CreateObjectAccessURL` with the full request and response messages.
    pub async fn create_object_access_url_raw(
        &mut self,
        request: CreateObjectAccessURLRequest,
    ) -> Result<CreateObjectAccessURLResponse, GestaltError> {
        let mut tonic_request =
            tonic::Request::new(to_wire_create_object_access_url_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = self.inner.create_object_access_url(tonic_request).await?;
        Ok(from_wire_create_object_access_url_response(
            response.into_inner(),
        ))
    }
}

/// Optional parameters of [`S3ObjectAccess::create_object_access_url`]; the default value leaves every
/// option unset.
#[derive(Clone, Debug, Default)]
pub struct S3ObjectAccessCreateObjectAccessURLOptions {
    /// The `content_type` field.
    pub content_type: String,
    /// The `content_disposition` field.
    pub content_disposition: String,
}