Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ reqsign-http-send-reqwest = { version = "3.0.0", path = "context/http-send-reqwe
reqsign-huaweicloud-obs = { version = "2.0.2", path = "services/huaweicloud-obs" }
reqsign-oracle = { version = "2.0.2", path = "services/oracle" }
reqsign-tencent-cos = { version = "2.0.2", path = "services/tencent-cos" }
reqsign-volcengine-tos = { version = "2.0.2", path = "services/volcengine-tos" }

# Crates.io dependencies
anyhow = "1"
Expand Down
4 changes: 3 additions & 1 deletion reqsign/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ reqsign-google = { workspace = true, optional = true }
reqsign-huaweicloud-obs = { workspace = true, optional = true }
reqsign-oracle = { workspace = true, optional = true }
reqsign-tencent-cos = { workspace = true, optional = true }
reqsign-volcengine-tos = { workspace = true, optional = true }

# Context implementations (optional but included by default)
reqsign-command-execute-tokio = { workspace = true, optional = true }
Expand All @@ -66,9 +67,10 @@ google = ["dep:reqsign-google"]
huaweicloud = ["dep:reqsign-huaweicloud-obs"]
oracle = ["dep:reqsign-oracle"]
tencent = ["dep:reqsign-tencent-cos"]
volcengine = ["dep:reqsign-volcengine-tos"]

# Full feature set
full = ["aliyun", "aws", "azure", "google", "huaweicloud", "oracle", "tencent"]
full = ["aliyun", "aws", "azure", "google", "huaweicloud", "oracle", "tencent", "volcengine"]

[dev-dependencies]
anyhow = "1"
Expand Down
3 changes: 3 additions & 0 deletions reqsign/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ pub mod oracle;

#[cfg(feature = "tencent")]
pub mod tencent;

#[cfg(feature = "volcengine")]
pub mod volcengine;
67 changes: 67 additions & 0 deletions reqsign/src/volcengine.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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.

//! Volcengine TOS service support with convenience APIs
//!
//! This module provides Volcengine TOS signing functionality along with convenience
//! functions for common use cases.

// Re-export all Volcengine TOS signing types
pub use reqsign_volcengine_tos::*;

#[cfg(feature = "default-context")]
use crate::{Signer, default_context};

/// Default Volcengine TOS Signer type with commonly used components
#[cfg(feature = "default-context")]
pub type DefaultSigner = Signer<Credential>;

/// Create a default Volcengine TOS signer with standard configuration
///
/// This function creates a signer with:
/// - Default context (with Tokio file reader, reqwest HTTP client, OS environment)
/// - Default credential provider (reads from env vars)
/// - Request signer for the specified region
///
/// # Example
///
/// ```no_run
/// # #[tokio::main]
/// # async fn main() -> reqsign_core::Result<()> {
/// // Create a signer for Volcengine TOS in cn-beijing region
/// let signer = reqsign::volcengine::default_signer("cn-beijing");
///
/// // Sign a request
/// let mut req = http::Request::builder()
/// .method("GET")
/// .uri("https://mybucket.tos-cn-beijing.volces.com/myobject")
/// .body(())
/// .unwrap()
/// .into_parts()
/// .0;
///
/// signer.sign(&mut req, None).await?;
/// # Ok(())
/// # }
/// ```
#[cfg(feature = "default-context")]
pub fn default_signer(region: &str) -> DefaultSigner {
let ctx = default_context();
let provider = DefaultCredentialProvider::new();
let signer = RequestSigner::new(region);
Signer::new(ctx, provider, signer)
}
42 changes: 42 additions & 0 deletions services/volcengine-tos/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.

[package]
name = "reqsign-volcengine-tos"
version = "2.0.2"

description = "Volcengine TOS signing implementation for reqsign."

edition.workspace = true
license.workspace = true
repository.workspace = true
rust-version.workspace = true

[dependencies]
anyhow = { workspace = true }
async-trait = { workspace = true }
http = { workspace = true }
log = { workspace = true }
percent-encoding = { workspace = true }
reqsign-core = { workspace = true }

[dev-dependencies]
anyhow = { workspace = true }
env_logger = { workspace = true }
reqsign-file-read-tokio = { workspace = true }
reqsign-http-send-reqwest = { workspace = true }
tokio = { workspace = true, features = ["full"] }
38 changes: 38 additions & 0 deletions services/volcengine-tos/src/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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.

use percent_encoding::{AsciiSet, NON_ALPHANUMERIC};

pub const ENV_ACCESS_KEY_ID: &str = "VOLCENGINE_ACCESS_KEY_ID";
pub const ENV_SECRET_ACCESS_KEY: &str = "VOLCENGINE_SECRET_ACCESS_KEY";
pub const ENV_SESSION_TOKEN: &str = "VOLCENGINE_SESSION_TOKEN";

pub static VOLCENGINE_URI_ENCODE_SET: AsciiSet = NON_ALPHANUMERIC
.remove(b'-')
.remove(b'_')
.remove(b'.')
.remove(b'~')
.remove(b'/');

pub static VOLCENGINE_QUERY_ENCODE_SET: AsciiSet = NON_ALPHANUMERIC
.remove(b'-')
.remove(b'_')
.remove(b'.')
.remove(b'~');

pub const EMPTY_PAYLOAD_SHA256: &str =
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
62 changes: 62 additions & 0 deletions services/volcengine-tos/src/credential.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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.

use reqsign_core::SigningCredential;
use reqsign_core::utils::Redact;
use std::fmt::{Debug, Formatter};

/// Credential for Volcengine TOS.
#[derive(Clone)]
pub struct Credential {
/// Access key id.
pub access_key_id: String,
/// Secret access key.
pub secret_access_key: String,
/// Session token.
pub session_token: Option<String>,
}

impl Credential {
pub fn new(access_key_id: &str, secret_access_key: &str) -> Self {
Self {
access_key_id: access_key_id.to_string(),
secret_access_key: secret_access_key.to_string(),
session_token: None,
}
}

pub fn with_session_token(mut self, token: &str) -> Self {
self.session_token = Some(token.to_string());
self
}
}

impl Debug for Credential {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Credential")
.field("access_key_id", &Redact::from(&self.access_key_id))
.field("secret_access_key", &Redact::from(&self.secret_access_key))
.field("session_token", &Redact::from(&self.session_token))
.finish()
}
}

impl SigningCredential for Credential {
fn is_valid(&self) -> bool {
!self.access_key_id.is_empty() && !self.secret_access_key.is_empty()
}
}
31 changes: 31 additions & 0 deletions services/volcengine-tos/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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.

//! Volcengine TOS signing implementation for reqsign.

mod constants;
mod credential;
pub use credential::Credential;

mod provide_credential;
pub use provide_credential::*;

mod sign_request;
mod uri;
pub use uri::{percent_encode_path, percent_encode_query};

pub use sign_request::RequestSigner;
Loading
Loading