google_cloud_recommender_v1/
client.rs

1// Copyright 2025 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Code generated by sidekick. DO NOT EDIT.
16#![allow(rustdoc::redundant_explicit_links)]
17#![allow(rustdoc::broken_intra_doc_links)]
18
19/// Implements a client for the Recommender API.
20///
21/// # Example
22/// ```
23/// # async fn sample() -> gax::client_builder::Result<()> {
24/// # use google_cloud_recommender_v1::client::Recommender;
25/// let client = Recommender::builder().build().await?;
26/// // use `client` to make requests to the Recommender API.
27/// # Ok(()) }
28/// ```
29///
30/// # Service Description
31///
32/// Provides insights and recommendations for cloud customers for various
33/// categories like performance optimization, cost savings, reliability, feature
34/// discovery, etc. Insights and recommendations are generated automatically
35/// based on analysis of user resources, configuration and monitoring metrics.
36///
37/// # Configuration
38///
39/// To configure `Recommender` use the `with_*` methods in the type returned
40/// by [builder()][Recommender::builder]. The default configuration should
41/// work for most applications. Common configuration changes include
42///
43/// * [with_endpoint()]: by default this client uses the global default endpoint
44///   (`https://recommender.googleapis.com`). Applications using regional
45///   endpoints or running in restricted networks (e.g. a network configured
46//    with [Private Google Access with VPC Service Controls]) may want to
47///   override this default.
48/// * [with_credentials()]: by default this client uses
49///   [Application Default Credentials]. Applications using custom
50///   authentication may need to override this default.
51///
52/// [with_endpoint()]: super::builder::recommender::ClientBuilder::with_endpoint
53/// [with_credentials()]: super::builder::recommender::ClientBuilder::credentials
54/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
55/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
56///
57/// # Pooling and Cloning
58///
59/// `Recommender` holds a connection pool internally, it is advised to
60/// create one and the reuse it.  You do not need to wrap `Recommender` in
61/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
62/// already uses an `Arc` internally.
63#[derive(Clone, Debug)]
64pub struct Recommender {
65    inner: std::sync::Arc<dyn super::stub::dynamic::Recommender>,
66}
67
68impl Recommender {
69    /// Returns a builder for [Recommender].
70    ///
71    /// ```
72    /// # async fn sample() -> gax::client_builder::Result<()> {
73    /// # use google_cloud_recommender_v1::client::Recommender;
74    /// let client = Recommender::builder().build().await?;
75    /// # Ok(()) }
76    /// ```
77    pub fn builder() -> super::builder::recommender::ClientBuilder {
78        gax::client_builder::internal::new_builder(super::builder::recommender::client::Factory)
79    }
80
81    /// Creates a new client from the provided stub.
82    ///
83    /// The most common case for calling this function is in tests mocking the
84    /// client's behavior.
85    pub fn from_stub<T>(stub: T) -> Self
86    where
87        T: super::stub::Recommender + 'static,
88    {
89        Self {
90            inner: std::sync::Arc::new(stub),
91        }
92    }
93
94    pub(crate) async fn new(
95        config: gaxi::options::ClientConfig,
96    ) -> gax::client_builder::Result<Self> {
97        let inner = Self::build_inner(config).await?;
98        Ok(Self { inner })
99    }
100
101    async fn build_inner(
102        conf: gaxi::options::ClientConfig,
103    ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::Recommender>> {
104        if gaxi::options::tracing_enabled(&conf) {
105            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
106        }
107        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
108    }
109
110    async fn build_transport(
111        conf: gaxi::options::ClientConfig,
112    ) -> gax::client_builder::Result<impl super::stub::Recommender> {
113        super::transport::Recommender::new(conf).await
114    }
115
116    async fn build_with_tracing(
117        conf: gaxi::options::ClientConfig,
118    ) -> gax::client_builder::Result<impl super::stub::Recommender> {
119        Self::build_transport(conf)
120            .await
121            .map(super::tracing::Recommender::new)
122    }
123
124    /// Lists insights for the specified Cloud Resource. Requires the
125    /// recommender.*.list IAM permission for the specified insight type.
126    pub fn list_insights(&self) -> super::builder::recommender::ListInsights {
127        super::builder::recommender::ListInsights::new(self.inner.clone())
128    }
129
130    /// Gets the requested insight. Requires the recommender.*.get IAM permission
131    /// for the specified insight type.
132    pub fn get_insight(&self) -> super::builder::recommender::GetInsight {
133        super::builder::recommender::GetInsight::new(self.inner.clone())
134    }
135
136    /// Marks the Insight State as Accepted. Users can use this method to
137    /// indicate to the Recommender API that they have applied some action based
138    /// on the insight. This stops the insight content from being updated.
139    ///
140    /// MarkInsightAccepted can be applied to insights in ACTIVE state. Requires
141    /// the recommender.*.update IAM permission for the specified insight.
142    pub fn mark_insight_accepted(&self) -> super::builder::recommender::MarkInsightAccepted {
143        super::builder::recommender::MarkInsightAccepted::new(self.inner.clone())
144    }
145
146    /// Lists recommendations for the specified Cloud Resource. Requires the
147    /// recommender.*.list IAM permission for the specified recommender.
148    pub fn list_recommendations(&self) -> super::builder::recommender::ListRecommendations {
149        super::builder::recommender::ListRecommendations::new(self.inner.clone())
150    }
151
152    /// Gets the requested recommendation. Requires the recommender.*.get
153    /// IAM permission for the specified recommender.
154    pub fn get_recommendation(&self) -> super::builder::recommender::GetRecommendation {
155        super::builder::recommender::GetRecommendation::new(self.inner.clone())
156    }
157
158    /// Mark the Recommendation State as Dismissed. Users can use this method to
159    /// indicate to the Recommender API that an ACTIVE recommendation has to
160    /// be marked back as DISMISSED.
161    ///
162    /// MarkRecommendationDismissed can be applied to recommendations in ACTIVE
163    /// state.
164    ///
165    /// Requires the recommender.*.update IAM permission for the specified
166    /// recommender.
167    pub fn mark_recommendation_dismissed(
168        &self,
169    ) -> super::builder::recommender::MarkRecommendationDismissed {
170        super::builder::recommender::MarkRecommendationDismissed::new(self.inner.clone())
171    }
172
173    /// Marks the Recommendation State as Claimed. Users can use this method to
174    /// indicate to the Recommender API that they are starting to apply the
175    /// recommendation themselves. This stops the recommendation content from being
176    /// updated. Associated insights are frozen and placed in the ACCEPTED state.
177    ///
178    /// MarkRecommendationClaimed can be applied to recommendations in CLAIMED,
179    /// SUCCEEDED, FAILED, or ACTIVE state.
180    ///
181    /// Requires the recommender.*.update IAM permission for the specified
182    /// recommender.
183    pub fn mark_recommendation_claimed(
184        &self,
185    ) -> super::builder::recommender::MarkRecommendationClaimed {
186        super::builder::recommender::MarkRecommendationClaimed::new(self.inner.clone())
187    }
188
189    /// Marks the Recommendation State as Succeeded. Users can use this method to
190    /// indicate to the Recommender API that they have applied the recommendation
191    /// themselves, and the operation was successful. This stops the recommendation
192    /// content from being updated. Associated insights are frozen and placed in
193    /// the ACCEPTED state.
194    ///
195    /// MarkRecommendationSucceeded can be applied to recommendations in ACTIVE,
196    /// CLAIMED, SUCCEEDED, or FAILED state.
197    ///
198    /// Requires the recommender.*.update IAM permission for the specified
199    /// recommender.
200    pub fn mark_recommendation_succeeded(
201        &self,
202    ) -> super::builder::recommender::MarkRecommendationSucceeded {
203        super::builder::recommender::MarkRecommendationSucceeded::new(self.inner.clone())
204    }
205
206    /// Marks the Recommendation State as Failed. Users can use this method to
207    /// indicate to the Recommender API that they have applied the recommendation
208    /// themselves, and the operation failed. This stops the recommendation content
209    /// from being updated. Associated insights are frozen and placed in the
210    /// ACCEPTED state.
211    ///
212    /// MarkRecommendationFailed can be applied to recommendations in ACTIVE,
213    /// CLAIMED, SUCCEEDED, or FAILED state.
214    ///
215    /// Requires the recommender.*.update IAM permission for the specified
216    /// recommender.
217    pub fn mark_recommendation_failed(
218        &self,
219    ) -> super::builder::recommender::MarkRecommendationFailed {
220        super::builder::recommender::MarkRecommendationFailed::new(self.inner.clone())
221    }
222
223    /// Gets the requested Recommender Config. There is only one instance of the
224    /// config for each Recommender.
225    pub fn get_recommender_config(&self) -> super::builder::recommender::GetRecommenderConfig {
226        super::builder::recommender::GetRecommenderConfig::new(self.inner.clone())
227    }
228
229    /// Updates a Recommender Config. This will create a new revision of the
230    /// config.
231    pub fn update_recommender_config(
232        &self,
233    ) -> super::builder::recommender::UpdateRecommenderConfig {
234        super::builder::recommender::UpdateRecommenderConfig::new(self.inner.clone())
235    }
236
237    /// Gets the requested InsightTypeConfig. There is only one instance of the
238    /// config for each InsightType.
239    pub fn get_insight_type_config(&self) -> super::builder::recommender::GetInsightTypeConfig {
240        super::builder::recommender::GetInsightTypeConfig::new(self.inner.clone())
241    }
242
243    /// Updates an InsightTypeConfig change. This will create a new revision of the
244    /// config.
245    pub fn update_insight_type_config(
246        &self,
247    ) -> super::builder::recommender::UpdateInsightTypeConfig {
248        super::builder::recommender::UpdateInsightTypeConfig::new(self.inner.clone())
249    }
250}