235 235 | /// # mod tests {
|
236 236 | /// # #[test]
|
237 237 | /// # fn example() {
|
238 238 | /// use std::time::Duration;
|
239 239 | /// use aws_sdk_bedrockruntime::config::{Builder, Config};
|
240 240 | /// use aws_smithy_runtime::client::http::hyper_014::HyperClientBuilder;
|
241 241 | ///
|
242 242 | /// fn override_http_client(builder: &mut Builder) {
|
243 243 | /// let https_connector = hyper_rustls::HttpsConnectorBuilder::new()
|
244 244 | /// .with_webpki_roots()
|
245 245 | /// .https_only()
|
246 246 | /// .enable_http1()
|
247 247 | /// .enable_http2()
|
248 248 | /// .build();
|
249 249 | /// let hyper_client = HyperClientBuilder::new().build(https_connector);
|
250 250 | /// builder.set_http_client(Some(hyper_client));
|
251 251 | /// }
|
252 252 | ///
|
253 253 | /// let mut builder = aws_sdk_bedrockruntime::Config::builder();
|
254 254 | /// override_http_client(&mut builder);
|
255 255 | /// let config = builder.build();
|
256 256 | /// # }
|
257 257 | /// # }
|
258 258 | /// ```
|
259 259 | pub fn set_http_client(&mut self, http_client: Option<crate::config::SharedHttpClient>) -> &mut Self {
|
260 260 | self.runtime_components.set_http_client(http_client);
|
261 261 | self
|
262 262 | }
|
263 263 | /// Sets the endpoint resolver to use when making requests.
|
264 264 | ///
|
265 - |
|
265 + | ///
|
266 266 | /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution
|
267 267 | /// rules for `aws_sdk_bedrockruntime`.
|
268 - |
|
268 + | ///
|
269 269 | ///
|
270 270 | /// Note: setting an endpoint resolver will replace any endpoint URL that has been set.
|
271 271 | /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to
|
272 272 | /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`].
|
273 273 | ///
|
274 274 | /// # Examples
|
275 275 | /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production.
|
276 276 | /// ```no_run
|
277 277 | /// use aws_sdk_bedrockruntime::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint};
|
278 278 | /// #[derive(Debug)]
|
279 279 | /// struct StageResolver { stage: String }
|
280 280 | /// impl ResolveEndpoint for StageResolver {
|
281 281 | /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> {
|
282 282 | /// let stage = &self.stage;
|
283 283 | /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build()))
|
284 284 | /// }
|
285 285 | /// }
|
286 286 | /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() };
|
287 287 | /// let config = aws_sdk_bedrockruntime::Config::builder().endpoint_resolver(resolver).build();
|
288 288 | /// let client = aws_sdk_bedrockruntime::Client::from_conf(config);
|
289 289 | /// ```
|
290 290 | pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self {
|
291 291 | self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver()));
|
292 292 | self
|
293 293 | }
|
294 294 |
|
295 295 | /// Sets the endpoint resolver to use when making requests.
|
296 296 | ///
|
297 - |
|
297 + | ///
|
298 298 | /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution
|
299 299 | /// rules for `aws_sdk_bedrockruntime`.
|
300 + | ///
|
300 301 | pub fn set_endpoint_resolver(
|
301 302 | &mut self,
|
302 303 | endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>,
|
303 304 | ) -> &mut Self {
|
304 305 | self.runtime_components.set_endpoint_resolver(endpoint_resolver);
|
305 306 | self
|
306 307 | }
|
307 308 | /// Set the retry_config for the builder
|
308 309 | ///
|
309 310 | /// # Examples
|
310 311 | /// ```no_run
|
311 312 | /// use aws_sdk_bedrockruntime::config::Config;
|
312 313 | /// use aws_sdk_bedrockruntime::config::retry::RetryConfig;
|
313 314 | ///
|
314 315 | /// let retry_config = RetryConfig::standard().with_max_attempts(5);
|
315 316 | /// let config = Config::builder().retry_config(retry_config).build();
|
316 317 | /// ```
|
317 318 | pub fn retry_config(mut self, retry_config: ::aws_smithy_types::retry::RetryConfig) -> Self {
|
318 319 | self.set_retry_config(Some(retry_config));
|
319 320 | self
|
320 321 | }
|
321 322 |
|
322 323 | /// Set the retry_config for the builder
|
323 324 | ///
|
324 325 | /// # Examples
|
325 326 | /// ```no_run
|
326 327 | /// use aws_sdk_bedrockruntime::config::{Builder, Config};
|
327 328 | /// use aws_sdk_bedrockruntime::config::retry::RetryConfig;
|
328 329 | ///
|
329 330 | /// fn disable_retries(builder: &mut Builder) {
|
475 476 | ///
|
476 477 | /// # Examples
|
477 478 | ///
|
478 479 | /// Disabling identity caching:
|
479 480 | /// ```no_run
|
480 481 | /// use aws_sdk_bedrockruntime::config::IdentityCache;
|
481 482 | ///
|
482 483 | /// let config = aws_sdk_bedrockruntime::Config::builder()
|
483 484 | /// .identity_cache(IdentityCache::no_cache())
|
484 485 | /// // ...
|
485 486 | /// .build();
|
486 487 | /// let client = aws_sdk_bedrockruntime::Client::from_conf(config);
|
487 488 | /// ```
|
488 489 | ///
|
489 490 | /// Customizing lazy caching:
|
490 491 | /// ```no_run
|
491 492 | /// use aws_sdk_bedrockruntime::config::IdentityCache;
|
492 493 | /// use std::time::Duration;
|
493 494 | ///
|
494 495 | /// let config = aws_sdk_bedrockruntime::Config::builder()
|
495 496 | /// .identity_cache(
|
496 497 | /// IdentityCache::lazy()
|
497 498 | /// // change the load timeout to 10 seconds
|
498 499 | /// .load_timeout(Duration::from_secs(10))
|
499 500 | /// .build()
|
500 501 | /// )
|
501 502 | /// // ...
|
502 503 | /// .build();
|
503 504 | /// let client = aws_sdk_bedrockruntime::Client::from_conf(config);
|
504 505 | /// ```
|
505 - |
|
506 + | ///
|
506 507 | pub fn identity_cache(mut self, identity_cache: impl crate::config::ResolveCachedIdentity + 'static) -> Self {
|
507 508 | self.set_identity_cache(identity_cache);
|
508 509 | self
|
509 510 | }
|
510 511 |
|
511 512 | /// Set the identity cache for auth.
|
512 513 | ///
|
513 514 | /// The identity cache defaults to a lazy caching implementation that will resolve
|
514 515 | /// an identity when it is requested, and place it in the cache thereafter. Subsequent
|
515 516 | /// requests will take the value from the cache while it is still valid. Once it expires,
|
516 517 | /// the next request will result in refreshing the identity.
|
517 518 | ///
|
518 519 | /// This configuration allows you to disable or change the default caching mechanism.
|
519 520 | /// To use a custom caching mechanism, implement the [`ResolveCachedIdentity`](crate::config::ResolveCachedIdentity)
|
520 521 | /// trait and pass that implementation into this function.
|
521 522 | ///
|
522 523 | /// # Examples
|
523 524 | ///
|
524 525 | /// Disabling identity caching:
|
525 526 | /// ```no_run
|
526 527 | /// use aws_sdk_bedrockruntime::config::IdentityCache;
|
527 528 | ///
|
528 529 | /// let config = aws_sdk_bedrockruntime::Config::builder()
|
529 530 | /// .identity_cache(IdentityCache::no_cache())
|
530 531 | /// // ...
|
531 532 | /// .build();
|
532 533 | /// let client = aws_sdk_bedrockruntime::Client::from_conf(config);
|
533 534 | /// ```
|
534 535 | ///
|
535 536 | /// Customizing lazy caching:
|
536 537 | /// ```no_run
|
537 538 | /// use aws_sdk_bedrockruntime::config::IdentityCache;
|
538 539 | /// use std::time::Duration;
|
539 540 | ///
|
540 541 | /// let config = aws_sdk_bedrockruntime::Config::builder()
|
541 542 | /// .identity_cache(
|
542 543 | /// IdentityCache::lazy()
|
543 544 | /// // change the load timeout to 10 seconds
|
544 545 | /// .load_timeout(Duration::from_secs(10))
|
545 546 | /// .build()
|
546 547 | /// )
|
547 548 | /// // ...
|
548 549 | /// .build();
|
549 550 | /// let client = aws_sdk_bedrockruntime::Client::from_conf(config);
|
550 551 | /// ```
|
551 - |
|
552 + | ///
|
552 553 | pub fn set_identity_cache(&mut self, identity_cache: impl crate::config::ResolveCachedIdentity + 'static) -> &mut Self {
|
553 554 | self.runtime_components.set_identity_cache(::std::option::Option::Some(identity_cache));
|
554 555 | self
|
555 556 | }
|
556 557 | /// Add an [interceptor](crate::config::Intercept) that runs at specific stages of the request execution pipeline.
|
557 558 | ///
|
558 559 | /// Interceptors targeted at a certain stage are executed according to the pre-defined priority.
|
559 560 | /// The SDK provides a default set of interceptors. An interceptor configured by this method
|
560 561 | /// will run after those default interceptors.
|
561 562 | ///
|
562 563 | /// # Examples
|
563 564 | /// ```no_run
|
564 565 | /// # #[cfg(test)]
|
565 566 | /// # mod tests {
|
566 567 | /// # #[test]
|
567 568 | /// # fn example() {
|
568 569 | /// use aws_smithy_runtime_api::client::interceptors::context::phase::BeforeTransmit;
|
569 570 | /// use aws_smithy_runtime_api::client::interceptors::{Interceptor, InterceptorContext};
|
570 571 | /// use aws_smithy_types::config_bag::ConfigBag;
|
571 572 | /// use aws_sdk_bedrockruntime::config::Config;
|
572 573 | ///
|
573 574 | /// fn base_url() -> String {
|
574 575 | /// // ...
|
575 576 | /// # String::new()
|
576 577 | /// }
|
577 578 | ///
|
578 579 | /// #[derive(Debug)]
|
579 580 | /// pub struct UriModifierInterceptor;
|
580 581 | /// impl Intercept for UriModifierInterceptor {
|
581 582 | /// fn modify_before_signing(
|
975 976 | }
|
976 977 | /// Sets the [`behavior major version`](crate::config::BehaviorVersion).
|
977 978 | ///
|
978 979 | /// Over time, new best-practice behaviors are introduced. However, these behaviors might not be backwards
|
979 980 | /// compatible. For example, a change which introduces new default timeouts or a new retry-mode for
|
980 981 | /// all operations might be the ideal behavior but could break existing applications.
|
981 982 | ///
|
982 983 | /// # Examples
|
983 984 | ///
|
984 985 | /// Set the behavior major version to `latest`. This is equivalent to enabling the `behavior-version-latest` cargo feature.
|
985 986 | /// ```no_run
|
986 987 | /// use aws_sdk_bedrockruntime::config::BehaviorVersion;
|
987 988 | ///
|
988 989 | /// let config = aws_sdk_bedrockruntime::Config::builder()
|
989 990 | /// .behavior_version(BehaviorVersion::latest())
|
990 991 | /// // ...
|
991 992 | /// .build();
|
992 993 | /// let client = aws_sdk_bedrockruntime::Client::from_conf(config);
|
993 994 | /// ```
|
994 995 | ///
|
995 996 | /// Customizing behavior major version:
|
996 997 | /// ```no_run
|
997 998 | /// use aws_sdk_bedrockruntime::config::BehaviorVersion;
|
998 999 | ///
|
999 1000 | /// let config = aws_sdk_bedrockruntime::Config::builder()
|
1000 1001 | /// .behavior_version(BehaviorVersion::v2023_11_09())
|
1001 1002 | /// // ...
|
1002 1003 | /// .build();
|
1003 1004 | /// let client = aws_sdk_bedrockruntime::Client::from_conf(config);
|
1004 1005 | /// ```
|
1005 - |
|
1006 + | ///
|
1006 1007 | pub fn behavior_version(mut self, behavior_version: crate::config::BehaviorVersion) -> Self {
|
1007 1008 | self.set_behavior_version(Some(behavior_version));
|
1008 1009 | self
|
1009 1010 | }
|
1010 1011 |
|
1011 1012 | /// Sets the [`behavior major version`](crate::config::BehaviorVersion).
|
1012 1013 | ///
|
1013 1014 | /// Over time, new best-practice behaviors are introduced. However, these behaviors might not be backwards
|
1014 1015 | /// compatible. For example, a change which introduces new default timeouts or a new retry-mode for
|
1015 1016 | /// all operations might be the ideal behavior but could break existing applications.
|
1016 1017 | ///
|
1017 1018 | /// # Examples
|
1018 1019 | ///
|
1019 1020 | /// Set the behavior major version to `latest`. This is equivalent to enabling the `behavior-version-latest` cargo feature.
|
1020 1021 | /// ```no_run
|
1021 1022 | /// use aws_sdk_bedrockruntime::config::BehaviorVersion;
|
1022 1023 | ///
|
1023 1024 | /// let config = aws_sdk_bedrockruntime::Config::builder()
|
1024 1025 | /// .behavior_version(BehaviorVersion::latest())
|
1025 1026 | /// // ...
|
1026 1027 | /// .build();
|
1027 1028 | /// let client = aws_sdk_bedrockruntime::Client::from_conf(config);
|
1028 1029 | /// ```
|
1029 1030 | ///
|
1030 1031 | /// Customizing behavior major version:
|
1031 1032 | /// ```no_run
|
1032 1033 | /// use aws_sdk_bedrockruntime::config::BehaviorVersion;
|
1033 1034 | ///
|
1034 1035 | /// let config = aws_sdk_bedrockruntime::Config::builder()
|
1035 1036 | /// .behavior_version(BehaviorVersion::v2023_11_09())
|
1036 1037 | /// // ...
|
1037 1038 | /// .build();
|
1038 1039 | /// let client = aws_sdk_bedrockruntime::Client::from_conf(config);
|
1039 1040 | /// ```
|
1040 - |
|
1041 + | ///
|
1041 1042 | pub fn set_behavior_version(&mut self, behavior_version: Option<crate::config::BehaviorVersion>) -> &mut Self {
|
1042 1043 | self.behavior_version = behavior_version;
|
1043 1044 | self
|
1044 1045 | }
|
1045 1046 |
|
1046 1047 | /// Convenience method to set the latest behavior major version
|
1047 1048 | ///
|
1048 1049 | /// This is equivalent to enabling the `behavior-version-latest` Cargo feature
|
1049 1050 | pub fn behavior_version_latest(mut self) -> Self {
|
1050 1051 | self.set_behavior_version(Some(crate::config::BehaviorVersion::latest()));
|
1051 1052 | self
|
1052 1053 | }
|
1053 1054 | /// Adds a runtime plugin to the config.
|
1054 1055 | #[allow(unused)]
|
1055 1056 | pub(crate) fn runtime_plugin(mut self, plugin: impl crate::config::RuntimePlugin + 'static) -> Self {
|
1056 1057 | self.push_runtime_plugin(crate::config::SharedRuntimePlugin::new(plugin));
|
1057 1058 | self
|
1058 1059 | }
|
1059 1060 | /// Adds a runtime plugin to the config.
|
1060 1061 | #[allow(unused)]
|
1061 1062 | pub(crate) fn push_runtime_plugin(&mut self, plugin: crate::config::SharedRuntimePlugin) -> &mut Self {
|
1062 1063 | self.runtime_plugins.push(plugin);
|
1063 1064 | self
|
1064 1065 | }
|
1065 1066 | #[cfg(any(feature = "test-util", test))]
|
1066 1067 | #[allow(unused_mut)]
|
1067 1068 | /// Apply test defaults to the builder
|
1068 1069 | pub fn apply_test_defaults(&mut self) -> &mut Self {
|
1069 1070 | self.set_time_source(::std::option::Option::Some(::aws_smithy_async::time::SharedTimeSource::new(
|
1070 1071 | ::aws_smithy_async::time::StaticTimeSource::new(::std::time::UNIX_EPOCH + ::std::time::Duration::from_secs(1234567890)),
|
1131 1132 | runtime_components.push_interceptor(crate::sdk_feature_tracker::retry_mode::RetryModeFeatureTrackerInterceptor::new());
|
1132 1133 | runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new());
|
1133 1134 | runtime_components.push_interceptor(::aws_runtime::request_info::RequestInfoInterceptor::new());
|
1134 1135 | runtime_components.push_interceptor(::aws_runtime::user_agent::UserAgentInterceptor::new());
|
1135 1136 | runtime_components.push_interceptor(::aws_runtime::invocation_id::InvocationIdInterceptor::new());
|
1136 1137 | runtime_components.push_interceptor(::aws_runtime::recursion_detection::RecursionDetectionInterceptor::new());
|
1137 1138 | runtime_components.push_auth_scheme(::aws_smithy_runtime_api::client::auth::SharedAuthScheme::new(
|
1138 1139 | ::aws_runtime::auth::sigv4::SigV4AuthScheme::new(),
|
1139 1140 | ));
|
1140 1141 | Self { config, runtime_components }
|
1141 1142 | }
|
1142 1143 | }
|
1143 1144 |
|
1144 1145 | impl ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin for ServiceRuntimePlugin {
|
1145 1146 | fn config(&self) -> ::std::option::Option<::aws_smithy_types::config_bag::FrozenLayer> {
|
1146 1147 | self.config.clone()
|
1147 1148 | }
|
1148 1149 |
|
1149 1150 | fn order(&self) -> ::aws_smithy_runtime_api::client::runtime_plugin::Order {
|
1150 1151 | ::aws_smithy_runtime_api::client::runtime_plugin::Order::Defaults
|
1151 1152 | }
|
1152 1153 |
|
1153 1154 | fn runtime_components(
|
1154 1155 | &self,
|
1155 1156 | _: &::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder,
|
1156 1157 | ) -> ::std::borrow::Cow<'_, ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder> {
|
1157 1158 | ::std::borrow::Cow::Borrowed(&self.runtime_components)
|
1158 1159 | }
|
1159 1160 | }
|
1160 1161 |
|
1161 - | /// Cross-operation shared-state singletons
|
1162 + | // Cross-operation shared-state singletons
|
1162 1163 |
|
1163 1164 | /// A plugin that enables configuration for a single operation invocation
|
1164 1165 | ///
|
1165 1166 | /// The `config` method will return a `FrozenLayer` by storing values from `config_override`.
|
1166 1167 | /// In the case of default values requested, they will be obtained from `client_config`.
|
1167 1168 | #[derive(Debug)]
|
1168 1169 | pub(crate) struct ConfigOverrideRuntimePlugin {
|
1169 1170 | pub(crate) config: ::aws_smithy_types::config_bag::FrozenLayer,
|
1170 1171 | pub(crate) components: ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder,
|
1171 1172 | }
|
1172 1173 |
|
1173 1174 | impl ConfigOverrideRuntimePlugin {
|
1174 1175 | #[allow(dead_code)] // unused when a service does not provide any operations
|
1175 1176 | pub(crate) fn new(
|
1176 1177 | config_override: Builder,
|
1177 1178 | initial_config: ::aws_smithy_types::config_bag::FrozenLayer,
|
1178 1179 | initial_components: &::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder,
|
1179 1180 | ) -> Self {
|
1180 1181 | let mut layer = config_override.config;
|
1181 1182 | let mut components = config_override.runtime_components;
|
1182 1183 | #[allow(unused_mut)]
|
1183 1184 | let mut resolver =
|
1184 1185 | ::aws_smithy_runtime::client::config_override::Resolver::overrid(initial_config, initial_components, &mut layer, &mut components);
|
1185 1186 |
|
1186 1187 | resolver
|
1187 1188 | .config_mut()
|
1188 1189 | .load::<::aws_types::region::Region>()
|
1189 1190 | .cloned()
|
1190 1191 | .map(|r| resolver.config_mut().store_put(::aws_types::region::SigningRegion::from(r)));
|
1191 1192 |
|