id stringlengths 22 133 | text stringlengths 40 40.2k | arch stringclasses 1
value | syntax stringclasses 1
value | kind stringclasses 4
values | repo stringclasses 27
values | path stringlengths 5 116 | license stringclasses 6
values | commit stringlengths 40 40 | source_host stringclasses 1
value | category stringclasses 16
values | source_url stringlengths 85 196 | line_start int64 1 4.28k | line_end int64 4 4.31k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
awslabs/aws-sdk-rust:sdk/aws-types/src/os_shim_internal.rs:5 | Self::real()
}
}
impl Env {
pub fn get(&self, k: &str) -> Result<String, VarError> {
use env::Inner;
match &self.0 {
Inner::Real => std::env::var(k),
Inner::Fake(map) => map.get(k).cloned().ok_or(VarError::NotPresent),
}
}
/// Create a fake process envir... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/os_shim_internal.rs | Apache-2.0 | acfa8b17206870802e0074a0869147cada5550b5 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/acfa8b17206870802e0074a0869147cada5550b5/sdk/aws-types/src/os_shim_internal.rs | 161 | 220 |
awslabs/aws-sdk-rust:sdk/aws-types/src/os_shim_internal.rs:6 | impl From<HashMap<String, String>> for Env {
fn from(hash_map: HashMap<String, String>) -> Self {
Self(env::Inner::Fake(Arc::new(hash_map)))
}
}
mod env {
use std::collections::HashMap;
use std::sync::Arc;
#[derive(Clone, Debug)]
pub enum Inner {
Real,
Fake(Arc<HashMap<... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/os_shim_internal.rs | Apache-2.0 | acfa8b17206870802e0074a0869147cada5550b5 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/acfa8b17206870802e0074a0869147cada5550b5/sdk/aws-types/src/os_shim_internal.rs | 201 | 260 |
awslabs/aws-sdk-rust:sdk/aws-types/src/os_shim_internal.rs:7 | }
}
/// Time Source that can be manually moved for tests
///
/// # Examples
///
/// ```rust
/// # struct Client {
/// # // stub
/// # }
/// #
/// # impl Client {
/// # fn with_timesource(ts: TimeSource) -> Self {
/// # Client { }
/// # }
/// # }
/// use aws_types::os_shim_internal::{ManualTimeSource, ... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/os_shim_internal.rs | Apache-2.0 | acfa8b17206870802e0074a0869147cada5550b5 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/acfa8b17206870802e0074a0869147cada5550b5/sdk/aws-types/src/os_shim_internal.rs | 241 | 300 |
awslabs/aws-sdk-rust:sdk/aws-types/src/os_shim_internal.rs:8 | }
pub fn advance(&mut self, delta: Duration) {
let mut now = self.now.lock().unwrap();
*now += delta;
}
pub fn queries(&self) -> impl Deref<Target = Vec<SystemTime>> + '_ {
self.queries.lock().unwrap()
}
pub fn now(&self) -> SystemTime {
let ts = *self.now.lock().u... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/os_shim_internal.rs | Apache-2.0 | acfa8b17206870802e0074a0869147cada5550b5 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/acfa8b17206870802e0074a0869147cada5550b5/sdk/aws-types/src/os_shim_internal.rs | 281 | 340 |
awslabs/aws-sdk-rust:sdk/aws-types/src/os_shim_internal.rs:9 | assert_eq!(env.get("FOO").unwrap(), "BAR");
assert_eq!(
env.get("OTHER").expect_err("no present"),
VarError::NotPresent
)
}
#[test]
fn fs_works() {
let fs = Fs::from_test_dir(".", "/users/test-data");
let _ = fs
.read_to_end("/users/test-d... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/os_shim_internal.rs | Apache-2.0 | acfa8b17206870802e0074a0869147cada5550b5 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/acfa8b17206870802e0074a0869147cada5550b5/sdk/aws-types/src/os_shim_internal.rs | 321 | 356 |
awslabs/aws-sdk-rust:sdk/aws-types/src/os_shim_internal.rs:7 | }
}
/// Time Source that can be manually moved for tests
///
/// # Examples
///
/// ```rust
/// # struct Client {
/// # // stub
/// # }
/// #
/// # impl Client {
/// # fn with_timesource(ts: TimeSource) -> Self {
/// # Client { }
/// # }
/// # }
/// use aws_types::os_shim_internal::{ManualTimeSource, ... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/os_shim_internal.rs | Apache-2.0 | 74bae11ae1af170e33fb695488f1f514f21884ae | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/74bae11ae1af170e33fb695488f1f514f21884ae/sdk/aws-types/src/os_shim_internal.rs | 241 | 300 |
awslabs/aws-sdk-rust:sdk/aws-types/src/os_shim_internal.rs:8 | *now = time;
}
pub fn advance(&mut self, delta: Duration) {
let mut now = self.now.lock().unwrap();
*now += delta;
}
pub fn queries(&self) -> impl Deref<Target = Vec<SystemTime>> + '_ {
self.queries.lock().unwrap()
}
pub fn now(&self) -> SystemTime {
let ts = *... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/os_shim_internal.rs | Apache-2.0 | 74bae11ae1af170e33fb695488f1f514f21884ae | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/74bae11ae1af170e33fb695488f1f514f21884ae/sdk/aws-types/src/os_shim_internal.rs | 281 | 340 |
awslabs/aws-sdk-rust:sdk/aws-types/src/os_shim_internal.rs:9 | let env = Env::from_slice(&[("FOO", "BAR")]);
assert_eq!(env.get("FOO").unwrap(), "BAR");
assert_eq!(
env.get("OTHER").expect_err("no present"),
VarError::NotPresent
)
}
#[test]
fn fs_works() {
let fs = Fs::from_test_dir(".", "/users/test-data");
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/os_shim_internal.rs | Apache-2.0 | 74bae11ae1af170e33fb695488f1f514f21884ae | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/74bae11ae1af170e33fb695488f1f514f21884ae/sdk/aws-types/src/os_shim_internal.rs | 321 | 357 |
awslabs/aws-sdk-rust:sdk/aws-types/src/os_shim_internal.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
//! Abstractions for testing code that interacts with the operating system:
//! - Reading environment variables
//! - Reading from the file system
use crate::os_shim_internal::fs::Fake;
use std::collec... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/os_shim_internal.rs | Apache-2.0 | e80f07446df510d85f2d499860b730929c5d5a94 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/e80f07446df510d85f2d499860b730929c5d5a94/sdk/aws-types/src/os_shim_internal.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-types/src/os_shim_internal.rs:2 | Fs::real()
}
}
impl Fs {
pub fn real() -> Self {
Fs(fs::Inner::Real)
}
pub fn from_raw_map(fs: HashMap<OsString, Vec<u8>>) -> Self {
Fs(fs::Inner::Fake(Arc::new(Fake::MapFs(fs))))
}
pub fn from_map(data: HashMap<String, Vec<u8>>) -> Self {
let fs = data.into_iter().map... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/os_shim_internal.rs | Apache-2.0 | e80f07446df510d85f2d499860b730929c5d5a94 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/e80f07446df510d85f2d499860b730929c5d5a94/sdk/aws-types/src/os_shim_internal.rs | 41 | 100 |
awslabs/aws-sdk-rust:sdk/aws-types/src/os_shim_internal.rs:3 | namespaced_to: impl Into<PathBuf>,
) -> Self {
Self(fs::Inner::Fake(Arc::new(Fake::NamespacedFs {
real_path: test_directory.into(),
namespaced_to: namespaced_to.into(),
})))
}
/// Read the entire contents of a file
///
/// **Note**: This function is currently... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/os_shim_internal.rs | Apache-2.0 | e80f07446df510d85f2d499860b730929c5d5a94 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/e80f07446df510d85f2d499860b730929c5d5a94/sdk/aws-types/src/os_shim_internal.rs | 81 | 140 |
awslabs/aws-sdk-rust:sdk/aws-types/src/os_shim_internal.rs:4 | use std::path::PathBuf;
use std::sync::Arc;
#[derive(Clone, Debug)]
pub enum Inner {
Real,
Fake(Arc<Fake>),
}
#[derive(Debug)]
pub enum Fake {
MapFs(HashMap<OsString, Vec<u8>>),
NamespacedFs {
real_path: PathBuf,
namespaced_to: PathBuf,
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/os_shim_internal.rs | Apache-2.0 | e80f07446df510d85f2d499860b730929c5d5a94 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/e80f07446df510d85f2d499860b730929c5d5a94/sdk/aws-types/src/os_shim_internal.rs | 121 | 180 |
awslabs/aws-sdk-rust:sdk/aws-types/src/os_shim_internal.rs:5 | match &self.0 {
Inner::Real => std::env::var(k),
Inner::Fake(map) => map.get(k).cloned().ok_or(VarError::NotPresent),
}
}
/// Create a fake process environment from a slice of tuples.
///
/// # Examples
/// ```rust
/// use aws_types::os_shim_internal::Env;
//... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/os_shim_internal.rs | Apache-2.0 | e80f07446df510d85f2d499860b730929c5d5a94 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/e80f07446df510d85f2d499860b730929c5d5a94/sdk/aws-types/src/os_shim_internal.rs | 161 | 220 |
awslabs/aws-sdk-rust:sdk/aws-types/src/os_shim_internal.rs:6 | use std::collections::HashMap;
use std::sync::Arc;
#[derive(Clone, Debug)]
pub enum Inner {
Real,
Fake(Arc<HashMap<String, String>>),
}
}
#[cfg(test)]
mod test {
use crate::os_shim_internal::{Env, Fs};
use futures_util::FutureExt;
use std::env::VarError;
#[test]
fn... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/os_shim_internal.rs | Apache-2.0 | e80f07446df510d85f2d499860b730929c5d5a94 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/e80f07446df510d85f2d499860b730929c5d5a94/sdk/aws-types/src/os_shim_internal.rs | 201 | 242 |
awslabs/aws-sdk-rust:sdk/aws-types/src/os_shim_internal.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
//! Abstractions for testing code that interacts with the operating system:
//! - Reading environment variables
//! - Reading from the file system
use crate::os_shim_internal::fs::Fake;
use std::collec... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/os_shim_internal.rs | Apache-2.0 | 74cd8a14231e1a005a2f554b072fc9782def5519 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/74cd8a14231e1a005a2f554b072fc9782def5519/sdk/aws-types/src/os_shim_internal.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-types/src/os_shim_internal.rs:4 | use std::path::PathBuf;
use std::sync::Arc;
#[derive(Clone, Debug)]
pub enum Inner {
Real,
Fake(Arc<Fake>),
}
#[derive(Debug)]
pub enum Fake {
MapFs(HashMap<OsString, Vec<u8>>),
NamespacedFs {
real_path: PathBuf,
namespaced_to: PathBuf,
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/os_shim_internal.rs | Apache-2.0 | 74cd8a14231e1a005a2f554b072fc9782def5519 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/74cd8a14231e1a005a2f554b072fc9782def5519/sdk/aws-types/src/os_shim_internal.rs | 121 | 180 |
awslabs/aws-sdk-rust:sdk/aws-types/src/os_shim_internal.rs:5 | match &self.0 {
Inner::Real => std::env::var(k),
Inner::Fake(map) => map.get(k).cloned().ok_or(VarError::NotPresent),
}
}
/// Create a fake process environment from a slice of tuples.
///
/// # Example
/// ```rust
/// use aws_types::os_shim_internal::Env;
///... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/os_shim_internal.rs | Apache-2.0 | 74cd8a14231e1a005a2f554b072fc9782def5519 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/74cd8a14231e1a005a2f554b072fc9782def5519/sdk/aws-types/src/os_shim_internal.rs | 161 | 220 |
awslabs/aws-sdk-rust:sdk/aws-types/src/os_shim_internal.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
//! Abstractions for testing code that interacts with the operating system:
//! - Reading environment variables
//! - Reading from the file system
use crate::os_shim_internal::fs::Fake;
use std::collec... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/os_shim_internal.rs | Apache-2.0 | dab3b0a97d8213105549f35914670dd7bd91d619 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/dab3b0a97d8213105549f35914670dd7bd91d619/sdk/aws-types/src/os_shim_internal.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-types/src/os_shim_internal.rs:3 | namespaced_to: impl Into<PathBuf>,
) -> Self {
Self(fs::Inner::Fake(Arc::new(Fake::NamespacedFs {
real_path: test_directory.into(),
namespaced_to: namespaced_to.into(),
})))
}
/// Read the entire contents of a file
///
/// **Note**: This function is currently... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/os_shim_internal.rs | Apache-2.0 | dab3b0a97d8213105549f35914670dd7bd91d619 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/dab3b0a97d8213105549f35914670dd7bd91d619/sdk/aws-types/src/os_shim_internal.rs | 81 | 140 |
awslabs/aws-sdk-rust:sdk/aws-types/src/os_shim_internal.rs:4 | use std::path::PathBuf;
use std::sync::Arc;
#[derive(Clone)]
pub enum Inner {
Real,
Fake(Arc<Fake>),
}
pub enum Fake {
MapFs(HashMap<OsString, Vec<u8>>),
NamespacedFs {
real_path: PathBuf,
namespaced_to: PathBuf,
},
}
}
/// Envir... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/os_shim_internal.rs | Apache-2.0 | dab3b0a97d8213105549f35914670dd7bd91d619 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/dab3b0a97d8213105549f35914670dd7bd91d619/sdk/aws-types/src/os_shim_internal.rs | 121 | 180 |
awslabs/aws-sdk-rust:sdk/aws-types/src/os_shim_internal.rs:5 | Inner::Real => std::env::var(k),
Inner::Fake(map) => map.get(k).cloned().ok_or(VarError::NotPresent),
}
}
/// Create a fake process environment from a slice of tuples.
///
/// # Example
/// ```rust
/// use aws_types::os_shim_internal::Env;
/// let mock_env = Env::from_sl... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/os_shim_internal.rs | Apache-2.0 | dab3b0a97d8213105549f35914670dd7bd91d619 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/dab3b0a97d8213105549f35914670dd7bd91d619/sdk/aws-types/src/os_shim_internal.rs | 161 | 220 |
awslabs/aws-sdk-rust:sdk/aws-types/src/os_shim_internal.rs:6 | use std::sync::Arc;
#[derive(Clone)]
pub enum Inner {
Real,
Fake(Arc<HashMap<String, String>>),
}
}
#[cfg(test)]
mod test {
use crate::os_shim_internal::{Env, Fs};
use futures_util::FutureExt;
use std::env::VarError;
#[test]
fn env_works() {
let env = Env::from... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/os_shim_internal.rs | Apache-2.0 | dab3b0a97d8213105549f35914670dd7bd91d619 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/dab3b0a97d8213105549f35914670dd7bd91d619/sdk/aws-types/src/os_shim_internal.rs | 201 | 241 |
awslabs/aws-sdk-rust:sdk/aws-types/src/os_shim_internal.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
//! Abstractions for testing code that interacts with the operating system:
//! - Reading environment variables
//! - Reading from the file system
use std::collections::HashMap;
use std::env::VarError;... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/os_shim_internal.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/os_shim_internal.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-types/src/os_shim_internal.rs:2 | pub fn from_raw_map(fs: HashMap<OsString, Vec<u8>>) -> Self {
Fs(fs::Inner::Fake { fs })
}
pub fn from_map(data: HashMap<String, Vec<u8>>) -> Self {
let fs = data.into_iter().map(|(k, v)| (k.into(), v)).collect();
Fs(fs::Inner::Fake { fs })
}
pub fn exists(&self, path: impl AsR... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/os_shim_internal.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/os_shim_internal.rs | 41 | 100 |
awslabs/aws-sdk-rust:sdk/aws-types/src/os_shim_internal.rs:3 | }
/// Environment variable abstraction
///
/// Environment variables are global to a process, and, as such, are difficult to test with a multi-
/// threaded test runner like Rust's. This enables loading environment variables either from the
/// actual process environment ([`std::env::var`](std::env::var)) or from a ha... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/os_shim_internal.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/os_shim_internal.rs | 81 | 140 |
awslabs/aws-sdk-rust:sdk/aws-types/src/os_shim_internal.rs:4 | )))
}
/// Create a process environment that uses the real process environment
///
/// Calls will be delegated to [`std::env::var`](std::env::var).
pub fn real() -> Self {
Self(env::Inner::Real)
}
}
impl From<HashMap<String, String>> for Env {
fn from(hash_map: HashMap<String, Strin... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/os_shim_internal.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/os_shim_internal.rs | 121 | 147 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile.rs:2 | ///
/// Profile files have a general form similar to INI but with a number of quirks and edge cases. These
/// behaviors are largely to match existing parser implementations and these cases are documented in `test-data/profile-parser-tests.json`
/// in this repo.
///
/// ### The config file `~/.aws/config`
/// ```ini
/... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile.rs | Apache-2.0 | dab3b0a97d8213105549f35914670dd7bd91d619 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/dab3b0a97d8213105549f35914670dd7bd91d619/sdk/aws-types/src/profile.rs | 41 | 100 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile.rs:3 | /// This method creates a ProfileSet directly from a hashmap with no normalization.
///
/// ## Note
///
/// This is probably not what you want! In general, [`load`](load) should be used instead
/// because it will perform input normalization. However, for tests which operate on the
/// normalize... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile.rs | Apache-2.0 | dab3b0a97d8213105549f35914670dd7bd91d619 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/dab3b0a97d8213105549f35914670dd7bd91d619/sdk/aws-types/src/profile.rs | 81 | 140 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile.rs:4 | pub fn selected_profile(&self) -> &str {
self.selected_profile.as_ref()
}
/// Returns true if no profiles are contained in this profile set
pub fn is_empty(&self) -> bool {
self.profiles.is_empty()
}
fn parse(source: Source) -> Result<Self, ProfileParseError> {
let mut base... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile.rs | Apache-2.0 | dab3b0a97d8213105549f35914670dd7bd91d619 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/dab3b0a97d8213105549f35914670dd7bd91d619/sdk/aws-types/src/profile.rs | 121 | 180 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile.rs:5 | properties: HashMap<String, Property>,
}
impl Profile {
pub fn new(name: String, properties: HashMap<String, Property>) -> Self {
Self { name, properties }
}
pub fn name(&self) -> &str {
&self.name
}
pub fn get(&self, name: &str) -> Option<&str> {
self.properties.get(name)... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile.rs | Apache-2.0 | dab3b0a97d8213105549f35914670dd7bd91d619 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/dab3b0a97d8213105549f35914670dd7bd91d619/sdk/aws-types/src/profile.rs | 161 | 220 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile.rs:6 | use crate::profile::source::{File, Source};
use crate::profile::ProfileSet;
use arbitrary::{Arbitrary, Unstructured};
use serde::Deserialize;
use std::collections::HashMap;
use std::error::Error;
use std::fs;
use tracing_test::traced_test;
/// Run all tests from profile-parser-tests.jso... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile.rs | Apache-2.0 | dab3b0a97d8213105549f35914670dd7bd91d619 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/dab3b0a97d8213105549f35914670dd7bd91d619/sdk/aws-types/src/profile.rs | 201 | 260 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile.rs:7 | /// Run all tests from the fuzzing corpus to validate coverage
#[test]
#[ignore]
fn run_fuzz_tests() -> Result<(), Box<dyn Error>> {
let fuzz_corpus = fs::read_dir("fuzz/corpus/profile-parser")?
.map(|res| res.map(|entry| entry.path()))
.collect::<Result<Vec<_>, _>>()?;
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile.rs | Apache-2.0 | dab3b0a97d8213105549f35914670dd7bd91d619 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/dab3b0a97d8213105549f35914670dd7bd91d619/sdk/aws-types/src/profile.rs | 241 | 300 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile.rs:8 | .properties
.into_iter()
.map(|(_, prop)| (prop.key, prop.value))
.collect(),
)
})
.collect()
}
fn make_source(input: ParserInput) -> Source {
Source {
config_file: File {
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile.rs | Apache-2.0 | dab3b0a97d8213105549f35914670dd7bd91d619 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/dab3b0a97d8213105549f35914670dd7bd91d619/sdk/aws-types/src/profile.rs | 281 | 340 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile.rs:9 | (Ok(output), ParserOutput::ErrorContaining(err)) => Err(format!(
"expected an error: {} but parse succeeded:\n{:#?}",
err, output
)),
(Err(err), ParserOutput::Profiles(_expected)) => {
Err(format!("Expected to succeed but got: {}", err))
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile.rs | Apache-2.0 | dab3b0a97d8213105549f35914670dd7bd91d619 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/dab3b0a97d8213105549f35914670dd7bd91d619/sdk/aws-types/src/profile.rs | 321 | 363 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile.rs:2 | ///
/// Profile files have a general form similar to INI but with a number of quirks and edge cases. These
/// behaviors are largely to match existing parser implementations and these cases are documented in `test-data/profile-parser-tests.json`
/// in this repo.
///
/// ### The config file `~/.aws/config`
/// ```ini
/... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile.rs | Apache-2.0 | ce01df45f381f8c211cf6e3f90524295c43e164d | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/ce01df45f381f8c211cf6e3f90524295c43e164d/sdk/aws-types/src/profile.rs | 41 | 100 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile.rs:3 | /// This method creates a ProfileSet directly from a hashmap with no normalization.
///
/// ## Note
///
/// This is probably not what you want! In general, [`load`](load) should be used instead
/// because it will perform input normalization. However, for tests which operate on the
/// normalize... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile.rs | Apache-2.0 | ce01df45f381f8c211cf6e3f90524295c43e164d | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/ce01df45f381f8c211cf6e3f90524295c43e164d/sdk/aws-types/src/profile.rs | 81 | 140 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile.rs:4 | );
Ok(base)
}
fn empty() -> Self {
Self {
profiles: Default::default(),
selected_profile: "default".into(),
}
}
/// Retrieves a key-value pair from the currently selected profile
pub fn get(&self, key: &str) -> Option<&str> {
self.profiles
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile.rs | Apache-2.0 | ce01df45f381f8c211cf6e3f90524295c43e164d | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/ce01df45f381f8c211cf6e3f90524295c43e164d/sdk/aws-types/src/profile.rs | 121 | 180 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile.rs:5 | }
pub fn name(&self) -> &str {
&self.name
}
pub fn get(&self, name: &str) -> Option<&str> {
self.properties.get(name).map(|prop| prop.value())
}
}
/// Key-Value property pair
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Property {
key: String,
value: String,
}
impl Prope... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile.rs | Apache-2.0 | ce01df45f381f8c211cf6e3f90524295c43e164d | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/ce01df45f381f8c211cf6e3f90524295c43e164d/sdk/aws-types/src/profile.rs | 161 | 220 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile.rs:6 | use std::fs;
use tracing_test::traced_test;
/// Run all tests from profile-parser-tests.json
///
/// These represent the bulk of the test cases and reach effectively 100% coverage
#[test]
#[traced_test]
fn run_tests() -> Result<(), Box<dyn Error>> {
let tests = fs::read_to_string("t... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile.rs | Apache-2.0 | ce01df45f381f8c211cf6e3f90524295c43e164d | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/ce01df45f381f8c211cf6e3f90524295c43e164d/sdk/aws-types/src/profile.rs | 201 | 260 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile.rs:7 | };
// don't care if parse fails, just don't panic
let _ = ProfileSet::parse(profile_source);
}
Ok(())
}
// for test comparison purposes, flatten a profile into a hashmap
fn flatten(profile: ProfileSet) -> HashMap<String, HashMap<String, String>> {
profile
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile.rs | Apache-2.0 | ce01df45f381f8c211cf6e3f90524295c43e164d | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/ce01df45f381f8c211cf6e3f90524295c43e164d/sdk/aws-types/src/profile.rs | 241 | 300 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile.rs:8 | // wrapper to generate nicer errors during test failure
fn check(test_case: ParserTest) {
let copy = test_case.clone();
let parsed = ProfileSet::parse(make_source(test_case.input));
let res = match (parsed.map(flatten), &test_case.output) {
(Ok(actual), ParserOutput::Profiles(exp... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile.rs | Apache-2.0 | ce01df45f381f8c211cf6e3f90524295c43e164d | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/ce01df45f381f8c211cf6e3f90524295c43e164d/sdk/aws-types/src/profile.rs | 281 | 340 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile.rs:9 | struct ParserTest {
name: String,
input: ParserInput,
output: ParserOutput,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
enum ParserOutput {
Profiles(HashMap<String, HashMap<String, String>>),
ErrorContaining(String),
}
#[der... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile.rs | Apache-2.0 | ce01df45f381f8c211cf6e3f90524295c43e164d | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/ce01df45f381f8c211cf6e3f90524295c43e164d/sdk/aws-types/src/profile.rs | 321 | 340 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile.rs:2 | ///
/// Profile files have a general form similar to INI but with a number of quirks and edge cases. These
/// behaviors are largely to match existing parser implementations and these cases are documented in `test-data/profile-parser-tests.json`
/// in this repo.
///
/// ### The config file `~/.aws/config`
/// ```ini
/... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/profile.rs | 41 | 100 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile.rs:3 | base.selected_profile = source.profile;
normalize::merge_in(
&mut base,
parse_profile_file(&source.config_file)?,
FileKind::Config,
);
normalize::merge_in(
&mut base,
parse_profile_file(&source.credentials_file)?,
FileKind:... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/profile.rs | 81 | 140 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile.rs:4 | name: String,
properties: HashMap<String, Property>,
}
impl Profile {
pub fn new(name: String, properties: HashMap<String, Property>) -> Self {
Self { name, properties }
}
pub fn get(&self, name: &str) -> Option<&Property> {
self.properties.get(name)
}
}
/// Key-Value property pai... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/profile.rs | 121 | 180 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile.rs:5 | use serde::Deserialize;
use std::collections::HashMap;
use std::error::Error;
use std::fs;
use tracing_test::traced_test;
/// Run all tests from profile-parser-tests.json
///
/// These represent the bulk of the test cases and reach effectively 100% coverage
#[test]
#[traced_test]
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/profile.rs | 161 | 220 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile.rs:6 | contents: creds.unwrap_or_default().to_string(),
},
profile: "default".into(),
};
// don't care if parse fails, just don't panic
let _ = ProfileSet::parse(profile_source);
}
Ok(())
}
// for test comparison purposes, flatten a ... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/profile.rs | 201 | 260 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile.rs:7 | }
}
// wrapper to generate nicer errors during test failure
fn check(test_case: ParserTest) {
let copy = test_case.clone();
let parsed = ProfileSet::parse(make_source(test_case.input));
let res = match (parsed.map(flatten), &test_case.output) {
(Ok(actual), ParserOutput:... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/profile.rs | 241 | 300 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile.rs:8 | #[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
struct ParserTest {
name: String,
input: ParserInput,
output: ParserOutput,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
enum ParserOutput {
Profiles(HashMap<Stri... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/profile.rs | 281 | 303 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile/normalize.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
use crate::profile::parse::{RawProfileSet, WHITESPACE};
use crate::profile::source::FileKind;
use crate::profile::{Profile, ProfileSet, Property};
use std::borrow::Cow;
use std::collections::HashMap;
c... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile/normalize.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/profile/normalize.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile/normalize.rs:2 | if validate_identifier(self.name).is_err() {
return Err(format!(
"profile `{}` ignored because `{}` was not a valid identifier",
&self.name, &self.name
));
}
match (self.name, kind, self.has_profile_prefix) {
(_, FileKind::Config, true)... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile/normalize.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/profile/normalize.rs | 41 | 100 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile/normalize.rs:3 | Ok(profile_name) => Some((profile_name, profile)),
Err(e) => {
tracing::warn!("{}", e);
None
}
})
.collect::<Vec<_>>();
// if a `[profile default]` exists then we should ignore `[default]`
let ignore_unprefixed_default = valid_profiles
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile/normalize.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/profile/normalize.rs | 81 | 140 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile/normalize.rs:4 | Err(_) => {
tracing::warn!(profile = %&target.name, key = ?k, "key ignored because `{}` was not a valid identifier", k);
}
}
}
}
/// Validate that a string is a valid identifier
///
/// Identifiers must match `[A-Za-z0-9\-_]+`
fn validate_identifier(input: &str) -> Result<&str, ... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile/normalize.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/profile/normalize.rs | 121 | 180 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile/normalize.rs:5 | has_profile_prefix: false
}
);
assert_eq!(
ProfileName::parse("profile\tname"),
ProfileName {
name: "name",
has_profile_prefix: true
}
);
assert_eq!(
ProfileName::parse("profile name "),
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile/normalize.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/profile/normalize.rs | 161 | 220 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile/normalize.rs:6 | out
});
let mut base = ProfileSet::empty();
merge_in(&mut base, profile, FileKind::Config);
assert!(base
.get_profile("default")
.expect("contains default profile")
.properties
.is_empty());
assert!(logs_contain(
"key ig... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile/normalize.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/profile/normalize.rs | 201 | 223 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile/parse.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
//! Profile file parsing
//!
//! This file implements profile file parsing at a very literal level. Prior to actually being used,
//! profiles must be normalized into a canonical form. Constructions tha... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile/parse.rs | Apache-2.0 | ce01df45f381f8c211cf6e3f90524295c43e164d | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/ce01df45f381f8c211cf6e3f90524295c43e164d/sdk/aws-types/src/profile/parse.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile/parse.rs:7 | location,
message: format!("Expected an '=' sign defining a {}", ctx),
},
}
}
}
/// Parse a property line into a key-value pair
fn parse_property_line(line: &str) -> Result<(&str, &str), PropertyError> {
let line = prepare_line(line, true);
let (k, v) = line.split_once('... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile/parse.rs | Apache-2.0 | ce01df45f381f8c211cf6e3f90524295c43e164d | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/ce01df45f381f8c211cf6e3f90524295c43e164d/sdk/aws-types/src/profile/parse.rs | 241 | 300 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile/parse.rs:8 | comment_idx
.map(|idx| &line[..idx])
.unwrap_or(&line)
// trimming the comment might result in more whitespace that needs to be handled
.trim_matches(WHITESPACE)
}
#[cfg(test)]
mod test {
use super::{parse_profile_file, prepare_line, Location};
use crate::profile::parse::{parse_... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile/parse.rs | Apache-2.0 | ce01df45f381f8c211cf6e3f90524295c43e164d | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/ce01df45f381f8c211cf6e3f90524295c43e164d/sdk/aws-types/src/profile/parse.rs | 281 | 340 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile/parse.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
//! Profile file parsing
//!
//! This file implements profile file parsing at a very literal level. Prior to actually being used,
//! profiles must be normalized into a canonical form. Constructions tha... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile/parse.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/profile/parse.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile/parse.rs:2 | /// Error message
message: String,
}
impl Display for ProfileParseError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(
f,
"error parsing {} on line {}:\n {}",
self.location.path, self.location.line_number, self.message
)
}
}
/// Validat... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile/parse.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/profile/parse.rs | 41 | 100 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile/parse.rs:3 | /// In-progress profile representation
data: RawProfileSet<'a>,
/// Parser state
state: State<'a>,
/// Parser source location
///
/// Location is tracked to facilitate error reporting
location: Location,
}
enum State<'a> {
Starting,
ReadingProfile {
profile: &'a str,
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile/parse.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/profile/parse.rs | 81 | 140 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile/parse.rs:4 | if is_empty_line(line) || is_comment_line(line) {
continue;
}
if line.starts_with('[') {
self.read_profile_line(line)?;
} else if line.starts_with(WHITESPACE) {
self.read_property_continuation(line)?;
} else {
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile/parse.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/profile/parse.rs | 121 | 180 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile/parse.rs:5 | location: self.location.clone(),
message: message.into(),
}
}
/// Parse the lines of a property after the first line.
///
/// This is triggered by lines that start with whitespace.
fn read_property_continuation(&mut self, line: &'a str) -> Result<(), ProfileParseError> {
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile/parse.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/profile/parse.rs | 161 | 220 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile/parse.rs:6 | let profile_name = line
.strip_prefix('[')
.ok_or_else(|| self.make_error("Profile definition must start with ]"))?
.strip_suffix(']')
.ok_or_else(|| self.make_error("Profile definition must end with ']'"))?;
if !self.data.contains_key(profile_name) {
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile/parse.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/profile/parse.rs | 201 | 260 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile/parse.rs:7 | }
}
/// Parse a property line into a key-value pair
fn parse_property_line(line: &str) -> Result<(&str, &str), PropertyError> {
let line = prepare_line(line, true);
let (k, v) = line.split_once('=').ok_or(PropertyError::NoEquals)?;
let k = k.trim_matches(WHITESPACE);
let v = v.trim_matches(WHITESPACE);... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile/parse.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/profile/parse.rs | 241 | 300 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile/parse.rs:8 | .trim_matches(WHITESPACE)
}
#[cfg(test)]
mod test {
use super::{parse_profile_file, prepare_line, Location};
use crate::profile::parse::{parse_property_line, PropertyError};
use crate::profile::source::File;
// most test cases covered by the JSON test suite
#[test]
fn property_parsing() {
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile/parse.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/profile/parse.rs | 281 | 340 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile/parse.rs:9 | prepare_line("name = value#Comment # sign", false),
"name = value"
);
}
#[test]
fn error_line_numbers() {
let file = File {
path: "~/.aws/config".into(),
contents: "[default\nk=v".into(),
};
let err = parse_profile_file(&file).expect_err("... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile/parse.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/profile/parse.rs | 321 | 342 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile/source.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
use crate::os_shim_internal;
use std::borrow::Cow;
use std::io::ErrorKind;
use std::path::{Component, Path, PathBuf};
use tracing::Instrument;
/// In-memory source of profile data
pub struct Source {
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile/source.rs | Apache-2.0 | dab3b0a97d8213105549f35914670dd7bd91d619 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/dab3b0a97d8213105549f35914670dd7bd91d619/sdk/aws-types/src/profile/source.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile/source.rs:5 | }
// Finally, handle the case where it doesn't begin with some version of `~/`:
// NOTE: in this case we aren't performing path rewriting. This is correct because
// this path comes from an environment variable on the target
// platform, so in that case, the separators should already be ... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile/source.rs | Apache-2.0 | dab3b0a97d8213105549f35914670dd7bd91d619 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/dab3b0a97d8213105549f35914670dd7bd91d619/sdk/aws-types/src/profile/source.rs | 161 | 220 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile/source.rs:6 | if let (Ok(mut drive), Ok(path)) = (home_drive, home_path) {
drive.push_str(&path);
return Some(drive);
}
}
None
}
#[cfg(test)]
mod tests {
use crate::os_shim_internal::{Env, Fs};
use crate::profile::source::{expand_home, home_dir, load, Os};
use serde::Deserialize;
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile/source.rs | Apache-2.0 | dab3b0a97d8213105549f35914670dd7bd91d619 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/dab3b0a97d8213105549f35914670dd7bd91d619/sdk/aws-types/src/profile/source.rs | 201 | 260 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile/source.rs:7 | /// Run all tests from file-location-tests.json
#[test]
fn run_tests() -> Result<(), Box<dyn Error>> {
let tests = fs::read_to_string("test-data/file-location-tests.json")?;
let tests: SourceTests = serde_json::from_str(&tests)?;
for (i, test) in tests.tests.into_iter().enumerate() {
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile/source.rs | Apache-2.0 | dab3b0a97d8213105549f35914670dd7bd91d619 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/dab3b0a97d8213105549f35914670dd7bd91d619/sdk/aws-types/src/profile/source.rs | 241 | 300 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile/source.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
use crate::os_shim_internal;
use std::borrow::Cow;
use std::io::ErrorKind;
use std::path::{Component, Path, PathBuf};
/// In-memory source of profile data
pub struct Source {
/// Contents and path ... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile/source.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/profile/source.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile/source.rs:2 | FileKind::Config => "~/.aws/config",
}
}
fn override_environment_variable(&self) -> &'static str {
match &self {
FileKind::Config => "AWS_CONFIG_FILE",
FileKind::Credentials => "AWS_SHARED_CREDENTIALS_FILE",
}
}
}
/// Load a [Source](Source) from a given env... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile/source.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/profile/source.rs | 41 | 100 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile/source.rs:3 | kind: FileKind,
home_directory: &Option<String>,
fs: &os_shim_internal::Fs,
environment: &os_shim_internal::Env,
) -> File {
let path = environment
.get(kind.override_environment_variable())
.map(Cow::Owned)
.ok()
.unwrap_or_else(|| kind.default_path().into());
let ex... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile/source.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/profile/source.rs | 81 | 140 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile/source.rs:4 | };
tracing::info!(path = %path, size = ?data.len(), "config file loaded");
File {
// lossy is OK here, the name of this file is just for debugging purposes
path: expanded.to_string_lossy().into(),
contents: data,
}
}
fn expand_home(path: impl AsRef<Path>, home_dir: &Option<String>) ... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile/source.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/profile/source.rs | 121 | 180 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile/source.rs:5 | // platform, so in that case, the separators should already be correct.
_other => path.into(),
}
}
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
enum Os {
Windows,
NotWindows,
}
impl Os {
pub fn real() -> Self {
match std::env::consts::OS {
"windows" => Os::Windows,
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile/source.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/profile/source.rs | 161 | 220 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile/source.rs:6 | }
None
}
#[cfg(test)]
mod tests {
use crate::os_shim_internal::{Env, Fs};
use crate::profile::source::{expand_home, home_dir, load, Os};
use serde::Deserialize;
use std::collections::HashMap;
use std::error::Error;
use std::fs;
#[test]
fn only_expand_home_prefix() {
// ~ is... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile/source.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/profile/source.rs | 201 | 260 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile/source.rs:7 | let tests = fs::read_to_string("test-data/file-location-tests.json")?;
let tests: SourceTests = serde_json::from_str(&tests)?;
for (i, test) in tests.tests.into_iter().enumerate() {
eprintln!("test: {}", i);
check(test);
}
Ok(())
}
use tracing_test::trace... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile/source.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/profile/source.rs | 241 | 300 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile/source.rs:8 | "{}",
&test_case.name
);
assert_eq!(
source.credentials_file.path, test_case.credentials_location,
"{}",
&test_case.name
)
} else {
println!(
"NOTE: ignoring test case for {} which doe... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile/source.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/profile/source.rs | 281 | 340 |
awslabs/aws-sdk-rust:sdk/aws-types/src/profile/source.rs:9 | fn expand_home_no_home() {
// there is an edge case around expansion when no home directory exists
// if no home directory can be determined, leave the path as is
if !cfg!(windows) {
assert_eq!(expand_home("~/config", &None).to_str().unwrap(), "~/config")
} else {
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/profile/source.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/profile/source.rs | 321 | 346 |
awslabs/aws-sdk-rust:sdk/aws-types/src/region.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
//! Region type for determining the endpoint to send requests to.
use aws_smithy_types::config_bag::{Storable, StoreReplace};
use std::borrow::Cow;
use std::fmt::{Display, Formatter};
/// The region to... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/region.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-types/src/region.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-types/src/region.rs:2 | }
impl Region {
/// Creates a new `Region` from the given string.
pub fn new(region: impl Into<Cow<'static, str>>) -> Self {
Self(region.into())
}
/// Const function that creates a new `Region` from a static str.
pub const fn from_static(region: &'static str) -> Self {
Self(Cow::Bo... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/region.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-types/src/region.rs | 41 | 100 |
awslabs/aws-sdk-rust:sdk/aws-types/src/region.rs:3 | pub const fn from_static(region: &'static str) -> Self {
SigningRegion(Cow::Borrowed(region))
}
}
impl Storable for SigningRegion {
type Storer = StoreReplace<Self>;
}
// The region set to use when signing Sigv4a requests
///
/// Generally, user code will not need to interact with `SigningRegionSet`. ... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/region.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-types/src/region.rs | 81 | 135 |
awslabs/aws-sdk-rust:sdk/aws-types/src/region.rs:4 | }
SigningRegionSet(Cow::Owned(s))
}
}
impl Storable for SigningRegionSet {
type Storer = StoreReplace<Self>;
}
impl AsRef<str> for SigningRegionSet {
fn as_ref(&self) -> &str {
self.0.as_ref()
}
} | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/region.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-types/src/region.rs | 121 | 135 |
awslabs/aws-sdk-rust:sdk/aws-types/src/region.rs:2 | }
impl Region {
/// Creates a new `Region` from the given string.
pub fn new(region: impl Into<Cow<'static, str>>) -> Self {
Self(region.into())
}
/// Const function that creates a new `Region` from a static str.
pub const fn from_static(region: &'static str) -> Self {
Self(Cow::Bo... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/region.rs | Apache-2.0 | 253a15511a6a5f2940e1c914cc11de3a55235259 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/253a15511a6a5f2940e1c914cc11de3a55235259/sdk/aws-types/src/region.rs | 41 | 88 |
awslabs/aws-sdk-rust:sdk/aws-types/src/region.rs:2 | }
impl Region {
/// Creates a new `Region` from the given string.
pub fn new(region: impl Into<Cow<'static, str>>) -> Self {
Self(region.into())
}
/// Const function that creates a new `Region` from a static str.
pub const fn from_static(region: &'static str) -> Self {
Self(Cow::Bo... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/region.rs | Apache-2.0 | 87ae71a59df475262b4ee85c3375b5e2d60d5eab | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/87ae71a59df475262b4ee85c3375b5e2d60d5eab/sdk/aws-types/src/region.rs | 41 | 84 |
awslabs/aws-sdk-rust:sdk/aws-types/src/region.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
//! Region type for determining the endpoint to send requests to.
use std::borrow::Cow;
use std::fmt::{Display, Formatter};
/// The region to send requests to.
///
/// The region MUST be specified on a... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/region.rs | Apache-2.0 | 8159cb8ff570e4dca718e354c31cecdfadfeb0b8 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/8159cb8ff570e4dca718e354c31cecdfadfeb0b8/sdk/aws-types/src/region.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-types/src/region.rs:2 | Self(region.into())
}
/// Const function that creates a new `Region` from a static str.
pub const fn from_static(region: &'static str) -> Self {
Self(Cow::Borrowed(region))
}
}
/// The region to use when signing requests
///
/// Generally, user code will not need to interact with `SigningRegio... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/region.rs | Apache-2.0 | 8159cb8ff570e4dca718e354c31cecdfadfeb0b8 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/8159cb8ff570e4dca718e354c31cecdfadfeb0b8/sdk/aws-types/src/region.rs | 41 | 79 |
awslabs/aws-sdk-rust:sdk/aws-types/src/region.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
//! Region type for determining the endpoint to send requests to.
use std::borrow::Cow;
use std::fmt::{Display, Formatter};
/// The region to send requests to.
///
/// The region MUST be specified on ... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/region.rs | Apache-2.0 | 8c469a72bcb1b9d35f2701e806ec88ba896283dd | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/8c469a72bcb1b9d35f2701e806ec88ba896283dd/sdk/aws-types/src/region.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-types/src/region.rs:2 | Self(region.into())
}
/// Const function that creates a new `Region` from a static str.
pub const fn from_static(region: &'static str) -> Self {
Self(Cow::Borrowed(region))
}
}
/// The region to use when signing requests
///
/// Generally, user code will not need to interact with `SigningRegio... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/region.rs | Apache-2.0 | 5f4378d3e820cebbb6b7e7413d4592c7d5441559 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5f4378d3e820cebbb6b7e7413d4592c7d5441559/sdk/aws-types/src/region.rs | 41 | 73 |
awslabs/aws-sdk-rust:sdk/aws-types/src/region.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
use std::borrow::Cow;
use std::fmt::{Display, Formatter};
/// The region to send requests to.
///
/// The region MUST be specified on a request. It may be configured globally or on a
/// per-client bas... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/region.rs | Apache-2.0 | acfa8b17206870802e0074a0869147cada5550b5 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/acfa8b17206870802e0074a0869147cada5550b5/sdk/aws-types/src/region.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-types/src/region.rs:2 | Self(Cow::Borrowed(region))
}
}
/// The region to use when signing requests
///
/// Generally, user code will not need to interact with `SigningRegion`. See `[Region](crate::Region)`.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SigningRegion(Cow<'static, str>);
impl AsRef<str> for SigningRegion {
fn as_... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/region.rs | Apache-2.0 | acfa8b17206870802e0074a0869147cada5550b5 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/acfa8b17206870802e0074a0869147cada5550b5/sdk/aws-types/src/region.rs | 41 | 67 |
awslabs/aws-sdk-rust:sdk/aws-types/src/region.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
use std::borrow::Cow;
use std::fmt::{Display, Formatter};
/// The region to send requests to.
///
/// The region MUST be specified on a request. It may be configured globally or on a
/// per-client bas... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/region.rs | Apache-2.0 | 74cd8a14231e1a005a2f554b072fc9782def5519 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/74cd8a14231e1a005a2f554b072fc9782def5519/sdk/aws-types/src/region.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-types/src/region.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
use crate::os_shim_internal::Env;
use std::borrow::Cow;
/// The region to send requests to.
///
/// The region MUST be specified on a request. It may be configured globally or on a
/// per-client basis... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/region.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/region.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-types/src/region.rs:2 | }
/// Implement a region provider based on a series of region providers
///
/// # Example
/// ```rust
/// use aws_types::region::{ChainProvider, Region};
/// use std::env;
/// // region provider that first checks the `CUSTOM_REGION` environment variable,
/// // then checks the default provider chain, then falls back t... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/region.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/region.rs | 41 | 100 |
awslabs/aws-sdk-rust:sdk/aws-types/src/region.rs:3 | if let Some(region) = provider.region() {
return Some(region);
}
}
None
}
}
/// Provide a [`Region`](Region) to use with AWS requests
///
/// For most cases [`default_provider`](default_provider) will be the best option, implementing
/// a standard provider chain.
pub tr... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/region.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/region.rs | 81 | 140 |
awslabs/aws-sdk-rust:sdk/aws-types/src/region.rs:4 | }
}
#[allow(clippy::redundant_closure)] // https://github.com/rust-lang/rust-clippy/issues/7218
impl EnvironmentProvider {
pub fn new() -> Self {
EnvironmentProvider { env: Env::real() }
}
}
impl ProvideRegion for EnvironmentProvider {
fn region(&self) -> Option<Region> {
self.env
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/region.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/region.rs | 121 | 180 |
awslabs/aws-sdk-rust:sdk/aws-types/src/region.rs:5 | SigningRegion(Cow::Borrowed(region))
}
}
#[cfg(test)]
mod test {
use crate::os_shim_internal::Env;
use crate::region::{EnvironmentProvider, ProvideRegion, Region};
fn test_provider(vars: &[(&str, &str)]) -> EnvironmentProvider {
EnvironmentProvider {
env: Env::from_slice(vars),
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/region.rs | Apache-2.0 | 7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7c5f3753b8fce99b43f7c1a4fe5f2dd8077b95e3/sdk/aws-types/src/region.rs | 161 | 197 |
awslabs/aws-sdk-rust:sdk/aws-types/src/region.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
use std::borrow::Cow;
use std::env::VarError;
/// The region to send requests to.
///
/// The region MUST be specified on a request. It may be configured globally or on a
/// per-client basis unless ot... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/region.rs | Apache-2.0 | abe0ae5798928b83547ab30ddd2687be899e45c3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/abe0ae5798928b83547ab30ddd2687be899e45c3/sdk/aws-types/src/region.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-types/src/region.rs:3 | if let Some(region) = provider.region() {
return Some(region);
}
}
None
}
}
/// Provide a [`Region`](Region) to use with AWS requests
///
/// For most cases [`default_provider`](default_provider) will be the best option, implementing
/// a standard provider chain.
pub tr... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-types/src/region.rs | Apache-2.0 | abe0ae5798928b83547ab30ddd2687be899e45c3 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/abe0ae5798928b83547ab30ddd2687be899e45c3/sdk/aws-types/src/region.rs | 81 | 140 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.