mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-30 16:59:52 +00:00
03888bd266
TransitionClient::new() in crates/s3-client/src/transition_api.rs computes trailing_header_support = opts.trailing_headers && override_signer_type == SignatureV4, but override_signer_type is hardcoded to SignatureDefault at construction and never mutated afterwards, so the expression is always false regardless of opts.trailing_headers. The resulting field also has no live reader: its only reference is inside PutObjectOptions::validate() in crates/s3-client/src/api_put_object.rs, which is itself #[allow(dead_code, reason = "MinIO-parity ... no caller in this port")], and even there the reference to trailing_header_support is commented out. So trailing_headers: true in the seven warm_backend_*.rs constructors has never had any effect on request signing or chunked/trailing-header behavior (stream_sha256 signing is gated separately by metadata.stream_sha256 && !self.secure). Remove the misleading dead configuration from the seven provider constructors so it doesn't look like intentional, load-bearing behavior to future readers. Found during adversarial self-check while implementing rustfs/backlog#2040 (out of that issue's scope).
154 lines
5.3 KiB
Rust
154 lines
5.3 KiB
Rust
// Copyright 2024 RustFS Team
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
#![allow(unused_imports)]
|
|
#![allow(unused_variables)]
|
|
#![allow(unused_mut)]
|
|
#![allow(unused_assignments)]
|
|
#![allow(unused_must_use)]
|
|
#![allow(clippy::all)]
|
|
|
|
use std::collections::HashMap;
|
|
use std::sync::Arc;
|
|
|
|
use crate::services::tier::{
|
|
tier_config::TierAzure,
|
|
warm_backend::{WarmBackend, WarmBackendGetOpts, build_transition_put_options},
|
|
warm_backend_s3::WarmBackendS3,
|
|
};
|
|
use rustfs_s3_client::{
|
|
admin_handler_utils::AdminError,
|
|
api_put_object::PutObjectOptions,
|
|
credentials::{Credentials, SignatureType, Static, Value},
|
|
transition_api::{BucketLookupType, Options, ReadCloser, ReaderImpl, TransitionClient, TransitionCore},
|
|
};
|
|
use tracing::warn;
|
|
|
|
const MAX_MULTIPART_PUT_OBJECT_SIZE: i64 = 1024 * 1024 * 1024 * 1024 * 5;
|
|
const MAX_PARTS_COUNT: i64 = 10000;
|
|
const _MAX_PART_SIZE: i64 = 1024 * 1024 * 1024 * 5;
|
|
const MIN_PART_SIZE: i64 = 1024 * 1024 * 128;
|
|
|
|
pub struct WarmBackendAzure(WarmBackendS3);
|
|
|
|
impl WarmBackendAzure {
|
|
pub async fn new(conf: &TierAzure, tier: &str) -> Result<Self, std::io::Error> {
|
|
if conf.access_key == "" || conf.secret_key == "" {
|
|
return Err(std::io::Error::other("both access and secret keys are required"));
|
|
}
|
|
|
|
if conf.bucket == "" {
|
|
return Err(std::io::Error::other("no bucket name was provided"));
|
|
}
|
|
|
|
let u = match url::Url::parse(&conf.endpoint) {
|
|
Ok(u) => u,
|
|
Err(e) => {
|
|
return Err(std::io::Error::other(e.to_string()));
|
|
}
|
|
};
|
|
|
|
let creds = Credentials::new(Static(Value {
|
|
access_key_id: conf.access_key.clone(),
|
|
secret_access_key: conf.secret_key.clone(),
|
|
session_token: "".to_string(),
|
|
signer_type: SignatureType::SignatureV4,
|
|
..Default::default()
|
|
}));
|
|
let opts = Options {
|
|
creds,
|
|
secure: u.scheme() == "https",
|
|
region: conf.region.clone(),
|
|
bucket_lookup: BucketLookupType::BucketLookupDNS,
|
|
..Default::default()
|
|
};
|
|
let scheme = u.scheme();
|
|
let default_port = if scheme == "https" { 443 } else { 80 };
|
|
let host = u
|
|
.host_str()
|
|
.ok_or_else(|| std::io::Error::other("Invalid endpoint URL: missing host"))?;
|
|
let client = TransitionClient::new(&format!("{}:{}", host, u.port().unwrap_or(default_port)), opts, "azure").await?;
|
|
|
|
let client = Arc::new(client);
|
|
let core = TransitionCore(Arc::clone(&client));
|
|
Ok(Self(WarmBackendS3 {
|
|
client,
|
|
core,
|
|
bucket: conf.bucket.clone(),
|
|
prefix: conf.prefix.strip_suffix("/").unwrap_or(&conf.prefix).to_owned(),
|
|
storage_class: "".to_string(),
|
|
}))
|
|
}
|
|
}
|
|
|
|
#[async_trait::async_trait]
|
|
impl WarmBackend for WarmBackendAzure {
|
|
async fn put_with_meta(
|
|
&self,
|
|
object: &str,
|
|
r: ReaderImpl,
|
|
length: i64,
|
|
meta: HashMap<String, String>,
|
|
) -> Result<String, std::io::Error> {
|
|
let part_size = optimal_part_size(length)?;
|
|
let client = self.0.client.clone();
|
|
let res = client
|
|
.put_object(&self.0.bucket, &self.0.get_dest(object), r, length, &{
|
|
let mut opts = build_transition_put_options(self.0.storage_class.clone(), meta);
|
|
opts.part_size = part_size as u64;
|
|
opts.disable_content_sha256 = true;
|
|
opts
|
|
})
|
|
.await?;
|
|
//self.ToObjectError(err, object)
|
|
Ok(res.version_id)
|
|
}
|
|
|
|
async fn put(&self, object: &str, r: ReaderImpl, length: i64) -> Result<String, std::io::Error> {
|
|
self.put_with_meta(object, r, length, HashMap::new()).await
|
|
}
|
|
|
|
async fn get(&self, object: &str, rv: &str, opts: WarmBackendGetOpts) -> Result<ReadCloser, std::io::Error> {
|
|
self.0.get(object, rv, opts).await
|
|
}
|
|
|
|
async fn remove(&self, object: &str, rv: &str) -> Result<(), std::io::Error> {
|
|
self.0.remove(object, rv).await
|
|
}
|
|
|
|
async fn in_use(&self) -> Result<bool, std::io::Error> {
|
|
self.0.in_use().await
|
|
}
|
|
}
|
|
|
|
fn optimal_part_size(object_size: i64) -> Result<i64, std::io::Error> {
|
|
let mut object_size = object_size;
|
|
if object_size == -1 {
|
|
object_size = MAX_MULTIPART_PUT_OBJECT_SIZE;
|
|
}
|
|
|
|
if object_size > MAX_MULTIPART_PUT_OBJECT_SIZE {
|
|
return Err(std::io::Error::other("entity too large"));
|
|
}
|
|
|
|
let configured_part_size = MIN_PART_SIZE;
|
|
let mut part_size_flt = object_size as f64 / MAX_PARTS_COUNT as f64;
|
|
part_size_flt = (part_size_flt as f64 / configured_part_size as f64).ceil() * configured_part_size as f64;
|
|
|
|
let part_size = part_size_flt as i64;
|
|
if part_size == 0 {
|
|
return Ok(MIN_PART_SIZE);
|
|
}
|
|
Ok(part_size)
|
|
}
|