Skip to content

Commit

Permalink
Merge branch 'feat/aws_google_kms_support' into feat/google_kms_support
Browse files Browse the repository at this point in the history
# Conflicts:
#	Cargo.toml
#	packages/fuels-accounts/Cargo.toml
#	packages/fuels/Cargo.toml
  • Loading branch information
Salka1988 committed Feb 28, 2025
2 parents 272be43 + 6bab0fd commit e30989b
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 78 deletions.
6 changes: 2 additions & 4 deletions e2e/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,19 @@ tempfile = { workspace = true }
anyhow = { workspace = true, features = ["std"] }
flate2 = { workspace = true, features = ["zlib"] }
fuels-accounts = { workspace = true, features = ["std"] }

reqwest = { workspace = true, features = ["blocking", "default-tls"] }
semver = { workspace = true }
tar = { workspace = true }

[dependencies]
anyhow = { workspace = true }
aws-sdk-kms = { workspace = true, features = ["rustls"] }
fuels = { workspace = true, features = ["kms_signer", "test-helpers"] }
fuels = { workspace = true, features = ["kms-signer", "test-helpers"] }
testcontainers = { workspace = true }
tokio = { workspace = true, features = ["test-util"] }

[features]
default = ["fuels/default", "coin-cache", ]
default = ["fuels/default", "coin-cache"]
fuel-core-lib = ["fuels/fuel-core-lib"]
rocksdb = ["fuels/rocksdb"]
coin-cache = ["fuels/coin-cache"]

23 changes: 17 additions & 6 deletions e2e/src/aws_kms.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::Context;
use aws_sdk_kms::config::{Credentials, Region};
use fuels::accounts::kms::{AwsClient, AwsConfig, KmsKey};
use fuels::accounts::kms::{defaults, AwsClient, BehaviorVersion, Credentials, KmsKey, Region};
use fuels::prelude::Error;
use fuels::types::errors::Context;
use fuels::types::errors::Result;
use testcontainers::{core::ContainerPort, runners::AsyncRunner};
use tokio::io::AsyncBufReadExt;

Expand Down Expand Up @@ -35,23 +36,33 @@ impl AwsKms {
self
}

pub async fn start(self) -> anyhow::Result<AwsKmsProcess> {
pub async fn start(self) -> Result<AwsKmsProcess> {
let container = AwsKmsImage
.start()
.await
.map_err(|e| Error::Other(e.to_string()))
.with_context(|| "Failed to start KMS container")?;

if self.show_logs {
spawn_log_printer(&container);
}

let port = container.get_host_port_ipv4(4566).await?;
let port = container
.get_host_port_ipv4(4566)
.await
.map_err(|e| Error::Other(e.to_string()))?;
let url = format!("http://localhost:{}", port);

let credentials = Credentials::new("test", "test", None, None, "Static Test Credentials");
let region = Region::new("us-east-1");

let config = AwsConfig::for_testing(credentials, region, url.clone()).await;
let config = defaults(BehaviorVersion::latest())
.credentials_provider(credentials)
.endpoint_url(url.clone())
.region(region)
.load()
.await;

let client = AwsClient::new(config);

Ok(AwsKmsProcess {
Expand Down
3 changes: 2 additions & 1 deletion e2e/src/e2e_helpers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::aws_kms::{AwsKms, AwsKmsProcess};
use fuels::types::errors::Result;

pub async fn start_aws_kms(logs: bool) -> anyhow::Result<AwsKmsProcess> {
pub async fn start_aws_kms(logs: bool) -> Result<AwsKmsProcess> {
AwsKms::default().with_show_logs(logs).start().await
}
20 changes: 3 additions & 17 deletions e2e/tests/aws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,8 @@ mod tests {
let wallet = AwsWallet::with_kms_key(your_kms_key_id, kms.client(), Some(provider)).await?;
// ANCHOR_END: use_kms_wallet

let founded_coins = wallet
.get_coins(AssetId::zeroed())
.await?
.first()
.expect("No coins found")
.amount;
assert_eq!(founded_coins, 500000000);
let total_base_balance = wallet.get_asset_balance(&AssetId::zeroed()).await?;
assert_eq!(total_base_balance, amount);
Ok(())
}

Expand Down Expand Up @@ -66,7 +61,7 @@ mod tests {
.first()
.expect("No coins found")
.amount;
assert_eq!(founded_coins, 500000000);
assert_eq!(founded_coins, amount);

Contract::load_from(
"../e2e/sway/contracts/contract_test/out/release/contract_test.bin",
Expand All @@ -75,15 +70,6 @@ mod tests {
.deploy(aws_wallet, TxPolicies::default())
.await?;

let founded_coins = wallet
.get_coins(AssetId::zeroed())
.await?
.first()
.expect("No coins found")
.amount;

assert_eq!(founded_coins, 499999999);

Ok(())
}

Expand Down
2 changes: 0 additions & 2 deletions packages/fuels-accounts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ description = "Fuel Rust SDK accounts."

[dependencies]
async-trait = { workspace = true, default-features = false }

# AWS KMS client
aws-config = { workspace = true, features = [
"behavior-version-latest",
], optional = true }
Expand Down
50 changes: 5 additions & 45 deletions packages/fuels-accounts/src/kms/aws/client.rs
Original file line number Diff line number Diff line change
@@ -1,57 +1,17 @@
use aws_config::{
default_provider::credentials::DefaultCredentialsChain, BehaviorVersion, Region, SdkConfig,
pub use aws_config::{
default_provider::credentials::DefaultCredentialsChain, defaults, BehaviorVersion, Region,
SdkConfig,
};
use aws_sdk_kms::config::Credentials;
pub use aws_sdk_kms::config::Credentials;
use aws_sdk_kms::Client;

#[derive(Clone)]
pub struct AwsConfig {
sdk_config: SdkConfig,
}

impl AwsConfig {
pub async fn from_environment() -> Self {
let loader = aws_config::defaults(BehaviorVersion::latest())
.credentials_provider(DefaultCredentialsChain::builder().build().await);

Self {
sdk_config: loader.load().await,
}
}

#[cfg(feature = "test-helpers")]
pub async fn for_testing(
credentials: Credentials,
region: Region,
endpoint_url: String,
) -> Self {
let sdk_config = aws_config::defaults(BehaviorVersion::latest())
.credentials_provider(credentials)
.endpoint_url(endpoint_url)
.region(region)
.load()
.await;

Self { sdk_config }
}

pub fn endpoint_url(&self) -> Option<&str> {
self.sdk_config.endpoint_url()
}

pub fn region(&self) -> Option<&Region> {
self.sdk_config.region()
}
}

#[derive(Clone, Debug)]
pub struct AwsClient {
client: Client,
}

impl AwsClient {
pub fn new(config: AwsConfig) -> Self {
let config = config.sdk_config;
pub fn new(config: SdkConfig) -> Self {
let client = Client::new(&config);

Self { client }
Expand Down
2 changes: 1 addition & 1 deletion packages/fuels-accounts/src/kms/aws/wallet.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::accounts_utils::try_provider_error;
use crate::kms::aws::client::AwsClient;
pub use crate::kms::aws::client::AwsClient;
use crate::provider::Provider;
use crate::wallet::Wallet;
use crate::{Account, ViewOnlyAccount};
Expand Down
2 changes: 1 addition & 1 deletion packages/fuels-accounts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub mod wallet;

#[cfg(feature = "std")]
pub use account::*;
#[cfg(feature = "kms_signer")]
#[cfg(feature = "kms-signer")]
pub mod kms;

#[cfg(feature = "coin-cache")]
Expand Down
2 changes: 1 addition & 1 deletion packages/fuels/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ std = [
]
fuel-core-lib = ["fuels-test-helpers?/fuel-core-lib"]
rocksdb = ["fuels-test-helpers?/rocksdb"]
kms_signer = ["fuels-accounts/kms_signer"]
kms-signer = ["fuels-accounts/kms-signer"]
Empty file.

0 comments on commit e30989b

Please sign in to comment.