Skip to content

Commit 9384224

Browse files
authored
feat: add Extensions to object store PutOptions (#7213)
Follow-up to #7170.
1 parent fc360a9 commit 9384224

File tree

5 files changed

+77
-10
lines changed

5 files changed

+77
-10
lines changed

object_store/src/aws/client.rs

+5
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,11 @@ impl Request<'_> {
389389
Self { builder, ..self }
390390
}
391391

392+
pub(crate) fn with_extensions(self, extensions: ::http::Extensions) -> Self {
393+
let builder = self.builder.extensions(extensions);
394+
Self { builder, ..self }
395+
}
396+
392397
pub(crate) fn with_payload(mut self, payload: PutPayload) -> Self {
393398
if (!self.config.skip_signature && self.config.sign_payload)
394399
|| self.config.checksum.is_some()

object_store/src/aws/mod.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,23 @@ impl ObjectStore for AmazonS3 {
159159
payload: PutPayload,
160160
opts: PutOptions,
161161
) -> Result<PutResult> {
162+
let PutOptions {
163+
mode,
164+
tags,
165+
attributes,
166+
extensions,
167+
} = opts;
168+
162169
let request = self
163170
.client
164171
.request(Method::PUT, location)
165172
.with_payload(payload)
166-
.with_attributes(opts.attributes)
167-
.with_tags(opts.tags)
173+
.with_attributes(attributes)
174+
.with_tags(tags)
175+
.with_extensions(extensions)
168176
.with_encryption_headers();
169177

170-
match (opts.mode, &self.client.config.conditional_put) {
178+
match (mode, &self.client.config.conditional_put) {
171179
(PutMode::Overwrite, _) => request.idempotent(true).do_put().await,
172180
(PutMode::Create, S3ConditionalPut::Disabled) => Err(Error::NotImplemented),
173181
(PutMode::Create, S3ConditionalPut::ETagMatch) => {

object_store/src/azure/client.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,11 @@ impl PutRequest<'_> {
257257
Self { builder, ..self }
258258
}
259259

260+
fn with_extensions(self, extensions: ::http::Extensions) -> Self {
261+
let builder = self.builder.extensions(extensions);
262+
Self { builder, ..self }
263+
}
264+
260265
async fn send(self) -> Result<HttpResponse> {
261266
let credential = self.config.get_credential().await?;
262267
let sensitive = credential
@@ -540,12 +545,20 @@ impl AzureClient {
540545
payload: PutPayload,
541546
opts: PutOptions,
542547
) -> Result<PutResult> {
548+
let PutOptions {
549+
mode,
550+
tags,
551+
attributes,
552+
extensions,
553+
} = opts;
554+
543555
let builder = self
544556
.put_request(path, payload)
545-
.with_attributes(opts.attributes)
546-
.with_tags(opts.tags);
557+
.with_attributes(attributes)
558+
.with_extensions(extensions)
559+
.with_tags(tags);
547560

548-
let builder = match &opts.mode {
561+
let builder = match &mode {
549562
PutMode::Overwrite => builder.idempotent(true),
550563
PutMode::Create => builder.header(&IF_NONE_MATCH, "*"),
551564
PutMode::Update(v) => {

object_store/src/gcp/client.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,11 @@ impl Request<'_> {
231231
}
232232
}
233233

234+
fn with_extensions(self, extensions: ::http::Extensions) -> Self {
235+
let builder = self.builder.extensions(extensions);
236+
Self { builder, ..self }
237+
}
238+
234239
async fn send(self) -> Result<HttpResponse> {
235240
let credential = self.config.credentials.get_credential().await?;
236241
let resp = self
@@ -384,12 +389,21 @@ impl GoogleCloudStorageClient {
384389
payload: PutPayload,
385390
opts: PutOptions,
386391
) -> Result<PutResult> {
392+
let PutOptions {
393+
mode,
394+
// not supported by GCP
395+
tags: _,
396+
attributes,
397+
extensions,
398+
} = opts;
399+
387400
let builder = self
388401
.request(Method::PUT, path)
389402
.with_payload(payload)
390-
.with_attributes(opts.attributes);
403+
.with_attributes(attributes)
404+
.with_extensions(extensions);
391405

392-
let builder = match &opts.mode {
406+
let builder = match &mode {
393407
PutMode::Overwrite => builder.idempotent(true),
394408
PutMode::Create => builder.header(&VERSION_MATCH, "0"),
395409
PutMode::Update(v) => {
@@ -398,7 +412,7 @@ impl GoogleCloudStorageClient {
398412
}
399413
};
400414

401-
match (opts.mode, builder.do_put().await) {
415+
match (mode, builder.do_put().await) {
402416
(PutMode::Create, Err(crate::Error::Precondition { path, source })) => {
403417
Err(crate::Error::AlreadyExists { path, source })
404418
}

object_store/src/lib.rs

+28-1
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,7 @@ impl From<PutResult> for UpdateVersion {
11541154
}
11551155

11561156
/// Options for a put request
1157-
#[derive(Debug, Clone, PartialEq, Eq, Default)]
1157+
#[derive(Debug, Clone, Default)]
11581158
pub struct PutOptions {
11591159
/// Configure the [`PutMode`] for this operation
11601160
pub mode: PutMode,
@@ -1166,8 +1166,35 @@ pub struct PutOptions {
11661166
///
11671167
/// Implementations that don't support an attribute should return an error
11681168
pub attributes: Attributes,
1169+
/// Implementation-specific extensions. Intended for use by [`ObjectStore`] implementations
1170+
/// that need to pass context-specific information (like tracing spans) via trait methods.
1171+
///
1172+
/// These extensions are ignored entirely by backends offered through this crate.
1173+
///
1174+
/// They are also eclused from [`PartialEq`] and [`Eq`].
1175+
pub extensions: ::http::Extensions,
11691176
}
11701177

1178+
impl PartialEq<Self> for PutOptions {
1179+
fn eq(&self, other: &Self) -> bool {
1180+
let Self {
1181+
mode,
1182+
tags,
1183+
attributes,
1184+
extensions: _,
1185+
} = self;
1186+
let Self {
1187+
mode: other_mode,
1188+
tags: other_tags,
1189+
attributes: other_attributes,
1190+
extensions: _,
1191+
} = other;
1192+
(mode == other_mode) && (tags == other_tags) && (attributes == other_attributes)
1193+
}
1194+
}
1195+
1196+
impl Eq for PutOptions {}
1197+
11711198
impl From<PutMode> for PutOptions {
11721199
fn from(mode: PutMode) -> Self {
11731200
Self {

0 commit comments

Comments
 (0)