aws_sdk_cloudsearchdomain/operation/
search.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2/// Orchestration and serialization glue logic for `Search`.
3#[derive(::std::clone::Clone, ::std::default::Default, ::std::fmt::Debug)]
4#[non_exhaustive]
5pub struct Search;
6impl Search {
7    /// Creates a new `Search`
8    pub fn new() -> Self {
9        Self
10    }
11    pub(crate) async fn orchestrate(
12        runtime_plugins: &::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins,
13        input: crate::operation::search::SearchInput,
14    ) -> ::std::result::Result<
15        crate::operation::search::SearchOutput,
16        ::aws_smithy_runtime_api::client::result::SdkError<
17            crate::operation::search::SearchError,
18            ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
19        >,
20    > {
21        let map_err =
22            |err: ::aws_smithy_runtime_api::client::result::SdkError<
23                ::aws_smithy_runtime_api::client::interceptors::context::Error,
24                ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
25            >| { err.map_service_error(|err| err.downcast::<crate::operation::search::SearchError>().expect("correct error type")) };
26        let context = Self::orchestrate_with_stop_point(runtime_plugins, input, ::aws_smithy_runtime::client::orchestrator::StopPoint::None)
27            .await
28            .map_err(map_err)?;
29        let output = context.finalize().map_err(map_err)?;
30        ::std::result::Result::Ok(output.downcast::<crate::operation::search::SearchOutput>().expect("correct output type"))
31    }
32
33    pub(crate) async fn orchestrate_with_stop_point(
34        runtime_plugins: &::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins,
35        input: crate::operation::search::SearchInput,
36        stop_point: ::aws_smithy_runtime::client::orchestrator::StopPoint,
37    ) -> ::std::result::Result<
38        ::aws_smithy_runtime_api::client::interceptors::context::InterceptorContext,
39        ::aws_smithy_runtime_api::client::result::SdkError<
40            ::aws_smithy_runtime_api::client::interceptors::context::Error,
41            ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
42        >,
43    > {
44        let input = ::aws_smithy_runtime_api::client::interceptors::context::Input::erase(input);
45        use ::tracing::Instrument;
46        ::aws_smithy_runtime::client::orchestrator::invoke_with_stop_point("CloudSearch Domain", "Search", input, runtime_plugins, stop_point)
47            // Create a parent span for the entire operation. Includes a random, internal-only,
48            // seven-digit ID for the operation orchestration so that it can be correlated in the logs.
49            .instrument(::tracing::debug_span!(
50                "CloudSearch Domain.Search",
51                "rpc.service" = "CloudSearch Domain",
52                "rpc.method" = "Search",
53                "sdk_invocation_id" = ::fastrand::u32(1_000_000..10_000_000),
54                "rpc.system" = "aws-api",
55            ))
56            .await
57    }
58
59    pub(crate) fn operation_runtime_plugins(
60        client_runtime_plugins: ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins,
61        client_config: &crate::config::Config,
62        config_override: ::std::option::Option<crate::config::Builder>,
63    ) -> ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins {
64        let mut runtime_plugins = client_runtime_plugins.with_operation_plugin(Self::new());
65
66        if let ::std::option::Option::Some(config_override) = config_override {
67            for plugin in config_override.runtime_plugins.iter().cloned() {
68                runtime_plugins = runtime_plugins.with_operation_plugin(plugin);
69            }
70            runtime_plugins = runtime_plugins.with_operation_plugin(crate::config::ConfigOverrideRuntimePlugin::new(
71                config_override,
72                client_config.config.clone(),
73                &client_config.runtime_components,
74            ));
75        }
76        runtime_plugins
77    }
78}
79impl ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin for Search {
80    fn config(&self) -> ::std::option::Option<::aws_smithy_types::config_bag::FrozenLayer> {
81        let mut cfg = ::aws_smithy_types::config_bag::Layer::new("Search");
82
83        cfg.store_put(::aws_smithy_runtime_api::client::ser_de::SharedRequestSerializer::new(
84            SearchRequestSerializer,
85        ));
86        cfg.store_put(::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer::new(
87            SearchResponseDeserializer,
88        ));
89
90        cfg.store_put(::aws_smithy_runtime_api::client::auth::AuthSchemeOptionResolverParams::new(
91            crate::config::auth::Params::builder()
92                .operation_name("Search")
93                .build()
94                .expect("required fields set"),
95        ));
96
97        cfg.store_put(::aws_smithy_runtime_api::client::orchestrator::Metadata::new(
98            "Search",
99            "CloudSearch Domain",
100        ));
101        let mut signing_options = ::aws_runtime::auth::SigningOptions::default();
102        signing_options.double_uri_encode = true;
103        signing_options.content_sha256_header = false;
104        signing_options.normalize_uri_path = true;
105        signing_options.payload_override = None;
106
107        cfg.store_put(::aws_runtime::auth::SigV4OperationSigningConfig {
108            signing_options,
109            ..::std::default::Default::default()
110        });
111
112        ::std::option::Option::Some(cfg.freeze())
113    }
114
115    fn runtime_components(
116        &self,
117        _: &::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder,
118    ) -> ::std::borrow::Cow<'_, ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder> {
119        #[allow(unused_mut)]
120        let mut rcb = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("Search")
121            .with_interceptor(::aws_smithy_runtime::client::stalled_stream_protection::StalledStreamProtectionInterceptor::default())
122            .with_interceptor(SearchEndpointParamsInterceptor)
123            .with_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::TransientErrorClassifier::<
124                crate::operation::search::SearchError,
125            >::new())
126            .with_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::ModeledAsRetryableClassifier::<
127                crate::operation::search::SearchError,
128            >::new())
129            .with_retry_classifier(::aws_runtime::retries::classifiers::AwsErrorCodeClassifier::<
130                crate::operation::search::SearchError,
131            >::new());
132
133        ::std::borrow::Cow::Owned(rcb)
134    }
135}
136
137#[derive(Debug)]
138struct SearchResponseDeserializer;
139impl ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse for SearchResponseDeserializer {
140    fn deserialize_nonstreaming(
141        &self,
142        response: &::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
143    ) -> ::aws_smithy_runtime_api::client::interceptors::context::OutputOrError {
144        let (success, status) = (response.status().is_success(), response.status().as_u16());
145        let headers = response.headers();
146        let body = response.body().bytes().expect("body loaded");
147        #[allow(unused_mut)]
148        let mut force_error = false;
149        ::tracing::debug!(request_id = ?::aws_types::request_id::RequestId::request_id(response));
150        let parse_result = if !success && status != 200 || force_error {
151            crate::protocol_serde::shape_search::de_search_http_error(status, headers, body)
152        } else {
153            crate::protocol_serde::shape_search::de_search_http_response(status, headers, body)
154        };
155        crate::protocol_serde::type_erase_result(parse_result)
156    }
157}
158#[derive(Debug)]
159struct SearchRequestSerializer;
160impl ::aws_smithy_runtime_api::client::ser_de::SerializeRequest for SearchRequestSerializer {
161    #[allow(unused_mut, clippy::let_and_return, clippy::needless_borrow, clippy::useless_conversion)]
162    fn serialize_input(
163        &self,
164        input: ::aws_smithy_runtime_api::client::interceptors::context::Input,
165        _cfg: &mut ::aws_smithy_types::config_bag::ConfigBag,
166    ) -> ::std::result::Result<::aws_smithy_runtime_api::client::orchestrator::HttpRequest, ::aws_smithy_runtime_api::box_error::BoxError> {
167        let input = input.downcast::<crate::operation::search::SearchInput>().expect("correct type");
168        let _header_serialization_settings = _cfg
169            .load::<crate::serialization_settings::HeaderSerializationSettings>()
170            .cloned()
171            .unwrap_or_default();
172        let mut request_builder = {
173            #[allow(clippy::uninlined_format_args)]
174            fn uri_base(
175                _input: &crate::operation::search::SearchInput,
176                output: &mut ::std::string::String,
177            ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::BuildError> {
178                use ::std::fmt::Write as _;
179                ::std::write!(output, "/2013-01-01/search").expect("formatting should succeed");
180                ::std::result::Result::Ok(())
181            }
182            fn uri_query(
183                _input: &crate::operation::search::SearchInput,
184                mut output: &mut ::std::string::String,
185            ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::BuildError> {
186                let mut query = ::aws_smithy_http::query::Writer::new(output);
187                query.push_kv("format", "sdk");
188                query.push_kv("pretty", "true");
189                if let ::std::option::Option::Some(inner_1) = &_input.cursor {
190                    {
191                        query.push_kv("cursor", &::aws_smithy_http::query::fmt_string(inner_1));
192                    }
193                }
194                if let ::std::option::Option::Some(inner_2) = &_input.expr {
195                    {
196                        query.push_kv("expr", &::aws_smithy_http::query::fmt_string(inner_2));
197                    }
198                }
199                if let ::std::option::Option::Some(inner_3) = &_input.facet {
200                    {
201                        query.push_kv("facet", &::aws_smithy_http::query::fmt_string(inner_3));
202                    }
203                }
204                if let ::std::option::Option::Some(inner_4) = &_input.filter_query {
205                    {
206                        query.push_kv("fq", &::aws_smithy_http::query::fmt_string(inner_4));
207                    }
208                }
209                if let ::std::option::Option::Some(inner_5) = &_input.highlight {
210                    {
211                        query.push_kv("highlight", &::aws_smithy_http::query::fmt_string(inner_5));
212                    }
213                }
214                if let ::std::option::Option::Some(inner_6) = &_input.partial {
215                    {
216                        query.push_kv("partial", ::aws_smithy_types::primitive::Encoder::from(*inner_6).encode());
217                    }
218                }
219                let inner_7 = &_input.query;
220                let inner_7 = inner_7
221                    .as_ref()
222                    .ok_or_else(|| ::aws_smithy_types::error::operation::BuildError::missing_field("query", "cannot be empty or unset"))?;
223                if inner_7.is_empty() {
224                    return ::std::result::Result::Err(::aws_smithy_types::error::operation::BuildError::missing_field(
225                        "query",
226                        "cannot be empty or unset",
227                    ));
228                }
229                query.push_kv("q", &::aws_smithy_http::query::fmt_string(inner_7));
230                if let ::std::option::Option::Some(inner_8) = &_input.query_options {
231                    {
232                        query.push_kv("q.options", &::aws_smithy_http::query::fmt_string(inner_8));
233                    }
234                }
235                if let ::std::option::Option::Some(inner_9) = &_input.query_parser {
236                    {
237                        query.push_kv("q.parser", &::aws_smithy_http::query::fmt_string(inner_9));
238                    }
239                }
240                if let ::std::option::Option::Some(inner_10) = &_input.r#return {
241                    {
242                        query.push_kv("return", &::aws_smithy_http::query::fmt_string(inner_10));
243                    }
244                }
245                if let ::std::option::Option::Some(inner_11) = &_input.size {
246                    {
247                        query.push_kv("size", ::aws_smithy_types::primitive::Encoder::from(*inner_11).encode());
248                    }
249                }
250                if let ::std::option::Option::Some(inner_12) = &_input.sort {
251                    {
252                        query.push_kv("sort", &::aws_smithy_http::query::fmt_string(inner_12));
253                    }
254                }
255                if let ::std::option::Option::Some(inner_13) = &_input.start {
256                    {
257                        query.push_kv("start", ::aws_smithy_types::primitive::Encoder::from(*inner_13).encode());
258                    }
259                }
260                if let ::std::option::Option::Some(inner_14) = &_input.stats {
261                    {
262                        query.push_kv("stats", &::aws_smithy_http::query::fmt_string(inner_14));
263                    }
264                }
265                ::std::result::Result::Ok(())
266            }
267            #[allow(clippy::unnecessary_wraps)]
268            fn update_http_builder(
269                input: &crate::operation::search::SearchInput,
270                builder: ::http::request::Builder,
271            ) -> ::std::result::Result<::http::request::Builder, ::aws_smithy_types::error::operation::BuildError> {
272                let mut uri = ::std::string::String::new();
273                uri_base(input, &mut uri)?;
274                uri_query(input, &mut uri)?;
275                ::std::result::Result::Ok(builder.method("GET").uri(uri))
276            }
277            let mut builder = update_http_builder(&input, ::http::request::Builder::new())?;
278            builder
279        };
280        let body = ::aws_smithy_types::body::SdkBody::from("");
281
282        ::std::result::Result::Ok(request_builder.body(body).expect("valid request").try_into().unwrap())
283    }
284}
285#[derive(Debug)]
286struct SearchEndpointParamsInterceptor;
287
288impl ::aws_smithy_runtime_api::client::interceptors::Intercept for SearchEndpointParamsInterceptor {
289    fn name(&self) -> &'static str {
290        "SearchEndpointParamsInterceptor"
291    }
292
293    fn read_before_execution(
294        &self,
295        context: &::aws_smithy_runtime_api::client::interceptors::context::BeforeSerializationInterceptorContextRef<
296            '_,
297            ::aws_smithy_runtime_api::client::interceptors::context::Input,
298            ::aws_smithy_runtime_api::client::interceptors::context::Output,
299            ::aws_smithy_runtime_api::client::interceptors::context::Error,
300        >,
301        cfg: &mut ::aws_smithy_types::config_bag::ConfigBag,
302    ) -> ::std::result::Result<(), ::aws_smithy_runtime_api::box_error::BoxError> {
303        let _input = context.input().downcast_ref::<SearchInput>().ok_or("failed to downcast to SearchInput")?;
304
305        let params = crate::config::endpoint::Params::builder()
306            .set_region(cfg.load::<::aws_types::region::Region>().map(|r| r.as_ref().to_owned()))
307            .set_use_dual_stack(cfg.load::<::aws_types::endpoint_config::UseDualStack>().map(|ty| ty.0))
308            .set_use_fips(cfg.load::<::aws_types::endpoint_config::UseFips>().map(|ty| ty.0))
309            .set_endpoint(cfg.load::<::aws_types::endpoint_config::EndpointUrl>().map(|ty| ty.0.clone()))
310            .build()
311            .map_err(|err| {
312                ::aws_smithy_runtime_api::client::interceptors::error::ContextAttachedError::new("endpoint params could not be built", err)
313            })?;
314        cfg.interceptor_state()
315            .store_put(::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams::new(params));
316        ::std::result::Result::Ok(())
317    }
318}
319
320// The get_* functions below are generated from JMESPath expressions in the
321// operationContextParams trait. They target the operation's input shape.
322
323/// Error type for the `SearchError` operation.
324#[non_exhaustive]
325#[derive(::std::fmt::Debug)]
326pub enum SearchError {
327    /// <p>Information about any problems encountered while processing a search request.</p>
328    SearchException(crate::types::error::SearchException),
329    /// An unexpected error occurred (e.g., invalid JSON returned by the service or an unknown error code).
330    #[deprecated(note = "Matching `Unhandled` directly is not forwards compatible. Instead, match using a \
331    variable wildcard pattern and check `.code()`:
332     \
333    &nbsp;&nbsp;&nbsp;`err if err.code() == Some(\"SpecificExceptionCode\") => { /* handle the error */ }`
334     \
335    See [`ProvideErrorMetadata`](#impl-ProvideErrorMetadata-for-SearchError) for what information is available for the error.")]
336    Unhandled(crate::error::sealed_unhandled::Unhandled),
337}
338impl SearchError {
339    /// Creates the `SearchError::Unhandled` variant from any error type.
340    pub fn unhandled(
341        err: impl ::std::convert::Into<::std::boxed::Box<dyn ::std::error::Error + ::std::marker::Send + ::std::marker::Sync + 'static>>,
342    ) -> Self {
343        Self::Unhandled(crate::error::sealed_unhandled::Unhandled {
344            source: err.into(),
345            meta: ::std::default::Default::default(),
346        })
347    }
348
349    /// Creates the `SearchError::Unhandled` variant from an [`ErrorMetadata`](::aws_smithy_types::error::ErrorMetadata).
350    pub fn generic(err: ::aws_smithy_types::error::ErrorMetadata) -> Self {
351        Self::Unhandled(crate::error::sealed_unhandled::Unhandled {
352            source: err.clone().into(),
353            meta: err,
354        })
355    }
356    ///
357    /// Returns error metadata, which includes the error code, message,
358    /// request ID, and potentially additional information.
359    ///
360    pub fn meta(&self) -> &::aws_smithy_types::error::ErrorMetadata {
361        match self {
362            Self::SearchException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
363            Self::Unhandled(e) => &e.meta,
364        }
365    }
366    /// Returns `true` if the error kind is `SearchError::SearchException`.
367    pub fn is_search_exception(&self) -> bool {
368        matches!(self, Self::SearchException(_))
369    }
370}
371impl ::std::error::Error for SearchError {
372    fn source(&self) -> ::std::option::Option<&(dyn ::std::error::Error + 'static)> {
373        match self {
374            Self::SearchException(_inner) => ::std::option::Option::Some(_inner),
375            Self::Unhandled(_inner) => ::std::option::Option::Some(&*_inner.source),
376        }
377    }
378}
379impl ::std::fmt::Display for SearchError {
380    fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
381        match self {
382            Self::SearchException(_inner) => _inner.fmt(f),
383            Self::Unhandled(_inner) => {
384                if let ::std::option::Option::Some(code) = ::aws_smithy_types::error::metadata::ProvideErrorMetadata::code(self) {
385                    write!(f, "unhandled error ({code})")
386                } else {
387                    f.write_str("unhandled error")
388                }
389            }
390        }
391    }
392}
393impl ::aws_smithy_types::retry::ProvideErrorKind for SearchError {
394    fn code(&self) -> ::std::option::Option<&str> {
395        ::aws_smithy_types::error::metadata::ProvideErrorMetadata::code(self)
396    }
397    fn retryable_error_kind(&self) -> ::std::option::Option<::aws_smithy_types::retry::ErrorKind> {
398        ::std::option::Option::None
399    }
400}
401impl ::aws_smithy_types::error::metadata::ProvideErrorMetadata for SearchError {
402    fn meta(&self) -> &::aws_smithy_types::error::ErrorMetadata {
403        match self {
404            Self::SearchException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
405            Self::Unhandled(_inner) => &_inner.meta,
406        }
407    }
408}
409impl ::aws_smithy_runtime_api::client::result::CreateUnhandledError for SearchError {
410    fn create_unhandled_error(
411        source: ::std::boxed::Box<dyn ::std::error::Error + ::std::marker::Send + ::std::marker::Sync + 'static>,
412        meta: ::std::option::Option<::aws_smithy_types::error::ErrorMetadata>,
413    ) -> Self {
414        Self::Unhandled(crate::error::sealed_unhandled::Unhandled {
415            source,
416            meta: meta.unwrap_or_default(),
417        })
418    }
419}
420impl ::aws_types::request_id::RequestId for crate::operation::search::SearchError {
421    fn request_id(&self) -> Option<&str> {
422        self.meta().request_id()
423    }
424}
425
426pub use crate::operation::search::_search_output::SearchOutput;
427
428pub use crate::operation::search::_search_input::SearchInput;
429
430mod _search_input;
431
432mod _search_output;
433
434/// Builders
435pub mod builders;