Skip to content

Commit

Permalink
feat(aws-types): add api key to configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardomourar committed Dec 26, 2022
1 parent b2b8e7e commit cf7cf0e
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions aws/rust-runtime/aws-types/src/sdk_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct SdkConfig {
credentials_provider: Option<SharedCredentialsProvider>,
region: Option<Region>,
endpoint_resolver: Option<Arc<dyn ResolveAwsEndpoint>>,
api_key: Option<String>,
retry_config: Option<RetryConfig>,
sleep_impl: Option<Arc<dyn AsyncSleep>>,
timeout_config: Option<TimeoutConfig>,
Expand All @@ -45,6 +46,7 @@ pub struct Builder {
credentials_provider: Option<SharedCredentialsProvider>,
region: Option<Region>,
endpoint_resolver: Option<Arc<dyn ResolveAwsEndpoint>>,
api_key: Option<String>,
retry_config: Option<RetryConfig>,
sleep_impl: Option<Arc<dyn AsyncSleep>>,
timeout_config: Option<TimeoutConfig>,
Expand Down Expand Up @@ -131,6 +133,23 @@ impl Builder {
self
}

/// Set the api key to use when making requests.
/// # Examples
/// ```
/// use aws_types::SdkConfig;
/// let config = SdkConfig::builder().api_key("some-api-key").build();
/// ```
pub fn api_key(mut self, api_key: impl Into<String>) -> Self {
self.set_api_key(Some(api_key.into()));
self
}

/// Set the api key to use when making requests.
pub fn set_api_key(&mut self, api_key: Option<String>) -> &mut Self {
self.api_key = api_key;
self
}

/// Set the retry_config for the builder
///
/// _Note:_ Retries require a sleep implementation in order to work. When enabling retry, make
Expand Down Expand Up @@ -446,6 +465,7 @@ impl Builder {
credentials_provider: self.credentials_provider,
region: self.region,
endpoint_resolver: self.endpoint_resolver,
api_key: self.api_key,
retry_config: self.retry_config,
sleep_impl: self.sleep_impl,
timeout_config: self.timeout_config,
Expand All @@ -465,6 +485,11 @@ impl SdkConfig {
self.endpoint_resolver.clone()
}

/// Configured API key
pub fn api_key(&self) -> Option<&String> {
self.api_key.as_ref()
}

/// Configured retry config
pub fn retry_config(&self) -> Option<&RetryConfig> {
self.retry_config.as_ref()
Expand Down

0 comments on commit cf7cf0e

Please sign in to comment.