diff --git a/.changelog/1773800575.md b/.changelog/1773800575.md deleted file mode 100644 index 621d5d7f145..00000000000 --- a/.changelog/1773800575.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -applies_to: -- aws-sdk-rust -authors: -- codeshaunted -references: -- smithy-rs#4570 -breaking: false -new_feature: true -bug_fix: false ---- - -Enables custom implementations of `Env` and `Fs` from `aws_types` using `Env::from_custom` and `Fs::from_custom` respectively. -Also updates `ProviderConfig` and `ConfigLoader` in `aws_config` to take advantage of this change. diff --git a/aws/rust-runtime/Cargo.lock b/aws/rust-runtime/Cargo.lock index 98e6e64d61f..500f5786dfe 100644 --- a/aws/rust-runtime/Cargo.lock +++ b/aws/rust-runtime/Cargo.lock @@ -371,7 +371,7 @@ dependencies = [ [[package]] name = "aws-types" -version = "1.4.0" +version = "1.3.15" dependencies = [ "aws-credential-types", "aws-smithy-async", diff --git a/aws/rust-runtime/aws-config/Cargo.toml b/aws/rust-runtime/aws-config/Cargo.toml index 782cff2f73c..75ecbddfbe6 100644 --- a/aws/rust-runtime/aws-config/Cargo.toml +++ b/aws/rust-runtime/aws-config/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aws-config" -version = "1.9.0" +version = "1.8.16" authors = [ "AWS Rust SDK Team ", "Russell Cohen ", diff --git a/aws/rust-runtime/aws-config/src/lib.rs b/aws/rust-runtime/aws-config/src/lib.rs index 0b5da4cd117..cf0fd3f1622 100644 --- a/aws/rust-runtime/aws-config/src/lib.rs +++ b/aws/rust-runtime/aws-config/src/lib.rs @@ -549,24 +549,6 @@ mod loader { self } - /// Override the environment variable abstraction used during config resolution. - /// - /// This can be used with [`Env::from_custom`] to provide a custom environment - /// variable backend (e.g., remote config stores, vaults). - pub fn env(mut self, env: Env) -> Self { - self.env = Some(env); - self - } - - /// Override the filesystem abstraction used during config resolution. - /// - /// This can be used with [`Fs::from_custom`] to provide a custom filesystem - /// backend (e.g., in-memory stores, encrypted filesystems). - pub fn fs(mut self, fs: Fs) -> Self { - self.fs = Some(fs); - self - } - /// Override the access token provider used to build [`SdkConfig`]. /// /// # Examples @@ -1059,6 +1041,19 @@ mod loader { } } + #[cfg(test)] + impl ConfigLoader { + pub(crate) fn env(mut self, env: Env) -> Self { + self.env = Some(env); + self + } + + pub(crate) fn fs(mut self, fs: Fs) -> Self { + self.fs = Some(fs); + self + } + } + #[cfg(test)] mod test { #[allow(deprecated)] diff --git a/aws/rust-runtime/aws-types/Cargo.toml b/aws/rust-runtime/aws-types/Cargo.toml index 1b81789f263..915404d5482 100644 --- a/aws/rust-runtime/aws-types/Cargo.toml +++ b/aws/rust-runtime/aws-types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aws-types" -version = "1.4.0" +version = "1.3.15" authors = ["AWS Rust SDK Team ", "Russell Cohen "] description = "Cross-service types for the AWS SDK." edition = "2021" diff --git a/aws/rust-runtime/aws-types/src/os_shim_internal.rs b/aws/rust-runtime/aws-types/src/os_shim_internal.rs index c6ca207ff03..7a11a717c48 100644 --- a/aws/rust-runtime/aws-types/src/os_shim_internal.rs +++ b/aws/rust-runtime/aws-types/src/os_shim_internal.rs @@ -11,36 +11,11 @@ use std::collections::HashMap; use std::env::VarError; use std::ffi::OsString; use std::fmt::Debug; -use std::future::Future; -use std::panic::{RefUnwindSafe, UnwindSafe}; use std::path::{Path, PathBuf}; -use std::pin::Pin; use std::sync::{Arc, Mutex}; use crate::os_shim_internal::fs::Fake; -/// Trait for custom environment variable providers. -pub trait ProvideEnv: Debug + Send + Sync + UnwindSafe + RefUnwindSafe { - /// Get the value of environment variable `k`. - fn get(&self, k: &str) -> Result; -} - -/// Trait for custom filesystem providers. -pub trait ProvideFs: Debug + Send + Sync + UnwindSafe + RefUnwindSafe { - /// Read the entire contents of the file at `path`. - fn read_to_end( - &self, - path: &Path, - ) -> Pin>> + Send + '_>>; - - /// Write `contents` to the file at `path`. - fn write( - &self, - path: &Path, - contents: &[u8], - ) -> Pin> + Send + '_>>; -} - /// File system abstraction /// /// Simple abstraction enabling in-memory mocking of the file system @@ -75,11 +50,6 @@ impl Fs { Fs(fs::Inner::Real) } - /// Create an `Fs` backed by a custom `ProvideFs` implementation. - pub fn from_custom(provider: impl ProvideFs + 'static) -> Self { - Self(fs::Inner::Custom(Arc::new(provider))) - } - /// Create `Fs` from a map of `OsString` to `Vec`. pub fn from_raw_map(fs: HashMap>) -> Self { Fs(fs::Inner::Fake(Arc::new(Fake::MapFs(Mutex::new(fs))))) @@ -177,7 +147,6 @@ impl Fs { std::fs::read(real_path.join(actual_path)) } }, - Inner::Custom(provider) => provider.read_to_end(path).await, } } @@ -218,9 +187,6 @@ impl Fs { std::fs::write(real_path.join(actual_path), contents)?; } }, - Inner::Custom(provider) => { - return provider.write(path.as_ref(), contents.as_ref()).await - } } Ok(()) } @@ -232,13 +198,10 @@ mod fs { use std::path::PathBuf; use std::sync::{Arc, Mutex}; - use super::ProvideFs; - #[derive(Clone, Debug)] pub(super) enum Inner { Real, Fake(Arc), - Custom(Arc), } #[derive(Debug)] @@ -276,7 +239,6 @@ impl Env { match &self.0 { Inner::Real => std::env::var(k), Inner::Fake(map) => map.get(k).cloned().ok_or(VarError::NotPresent), - Inner::Custom(provider) => provider.get(k), } } @@ -305,11 +267,6 @@ impl Env { pub fn real() -> Self { Self(env::Inner::Real) } - - /// Create an `Env` backed by a custom `ProvideEnv` implementation. - pub fn from_custom(provider: impl ProvideEnv + 'static) -> Self { - Self(env::Inner::Custom(Arc::new(provider))) - } } impl From> for Env { @@ -322,26 +279,18 @@ mod env { use std::collections::HashMap; use std::sync::Arc; - use super::ProvideEnv; - #[derive(Clone, Debug)] pub(super) enum Inner { Real, Fake(Arc>), - Custom(Arc), } } #[cfg(test)] mod test { - use std::collections::HashMap; use std::env::VarError; - use std::future::Future; - use std::path::{Path, PathBuf}; - use std::pin::Pin; - use std::sync::Mutex; - use crate::os_shim_internal::{Env, Fs, ProvideEnv, ProvideFs}; + use crate::os_shim_internal::{Env, Fs}; #[test] fn env_works() { @@ -383,83 +332,6 @@ mod test { assert_eq!(b"test", &result[..]); } - #[test] - fn custom_env_works() { - #[derive(Debug)] - struct CustomEnvProvider { - vars: HashMap, - } - - impl ProvideEnv for CustomEnvProvider { - fn get(&self, k: &str) -> Result { - self.vars.get(k).cloned().ok_or(VarError::NotPresent) - } - } - - let mut vars = HashMap::new(); - vars.insert("FOO".to_string(), "BAR".to_string()); - let env = Env::from_custom(CustomEnvProvider { vars }); - assert_eq!(env.get("FOO").unwrap(), "BAR"); - assert_eq!( - env.get("OTHER").expect_err("not present"), - VarError::NotPresent - ); - } - - #[tokio::test] - async fn custom_fs_round_trip() { - #[derive(Debug)] - struct InMemoryFs { - files: Mutex>>, - } - - impl ProvideFs for InMemoryFs { - fn read_to_end( - &self, - path: &Path, - ) -> Pin>> + Send + '_>> { - let path = path.to_path_buf(); - Box::pin(async move { - self.files - .lock() - .unwrap() - .get(&path) - .cloned() - .ok_or_else(|| std::io::ErrorKind::NotFound.into()) - }) - } - - fn write( - &self, - path: &Path, - contents: &[u8], - ) -> Pin> + Send + '_>> { - let path = path.to_path_buf(); - let contents = contents.to_vec(); - Box::pin(async move { - self.files.lock().unwrap().insert(path, contents); - Ok(()) - }) - } - } - - let provider = InMemoryFs { - files: Mutex::new(HashMap::new()), - }; - let fs = Fs::from_custom(provider); - - fs.read_to_end("/missing") - .await - .expect_err("file doesn't exist yet"); - - fs.write("/test-file", b"hello") - .await - .expect("write succeeds"); - - let result = fs.read_to_end("/test-file").await.expect("read succeeds"); - assert_eq!(result, b"hello"); - } - #[cfg(unix)] #[tokio::test] async fn real_fs_write_sets_owner_only_permissions_on_unix() {