Skip to content

Commit bc1dd82

Browse files
committed
feat(dns/v1): add LRO helpers
Cloud DNS has a couple of LRO-type functions. Enabling the LRO wrappers requires a few lines of hand-crafted code. Note that the `librarian.yaml` file refers to the symbols without a package name. That is needed because discovery-based services do not have a package name. If you think: "But what about the Compute package further up in the file?": for Compute we "infer" a package name from the service config yaml file, but we have no such file for Cloud DNS. With these changes I think the client library is ready to publish.
1 parent 3d2943d commit bc1dd82

14 files changed

Lines changed: 423 additions & 1 deletion

File tree

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

librarian.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,13 +645,24 @@ libraries:
645645
rust:
646646
per_service_features: true
647647
- name: google-cloud-dns-v1
648+
version: 1.0.0
648649
copyright_year: "2026"
649-
skip_publish: true
650+
keep:
651+
- src/operation.rs
650652
specification_format: discovery
651653
rust:
654+
package_dependencies:
655+
- name: lro
656+
package: google-cloud-lro
657+
force_used: true
652658
roots:
653659
- discovery
654660
- googleapis
661+
discovery:
662+
operation_id: ..Operation
663+
pollers:
664+
- prefix: dns/v1/projects/{project}/managedZones/{managedZone}
665+
method_id: ..managedZoneOperations.get
655666
- name: google-cloud-documentai-v1
656667
version: 1.5.0
657668
copyright_year: "2025"

src/generated/cloud/dns/v1/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ bytes.workspace = true
4444
gax.workspace = true
4545
gaxi = { workspace = true, features = ["_internal-http-client"] }
4646
lazy_static.workspace = true
47+
lro.workspace = true
4748
reqwest.workspace = true
4849
serde.workspace = true
4950
serde_json.workspace = true

src/generated/cloud/dns/v1/src/builder.rs

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,6 +1641,42 @@ pub mod managed_zones {
16411641
.map(gax::response::Response::into_body)
16421642
}
16431643

1644+
/// Creates a [Poller][lro::Poller] to work with `patch`.
1645+
pub fn poller(self) -> impl lro::Poller<crate::model::Operation, crate::model::Operation> {
1646+
let polling_error_policy = self.0.stub.get_polling_error_policy(&self.0.options);
1647+
let polling_backoff_policy = self.0.stub.get_polling_backoff_policy(&self.0.options);
1648+
1649+
let stub = self.0.stub.clone();
1650+
let mut options = self.0.options.clone();
1651+
options.set_retry_policy(gax::retry_policy::NeverRetry);
1652+
let project = self.0.request.project.clone();
1653+
let managed_zone = self.0.request.managed_zone.clone();
1654+
let query = move |name| {
1655+
let stub = stub.clone();
1656+
let options = options.clone();
1657+
let project = project.clone();
1658+
let managed_zone = managed_zone.clone();
1659+
async {
1660+
GetOperation::new(stub)
1661+
.set_project(project)
1662+
.set_managed_zone(managed_zone)
1663+
.set_operation(name)
1664+
.with_options(options)
1665+
.send()
1666+
.await
1667+
}
1668+
};
1669+
1670+
let start = move || async { self.send().await };
1671+
1672+
lro::internal::new_discovery_poller(
1673+
polling_error_policy,
1674+
polling_backoff_policy,
1675+
start,
1676+
query,
1677+
)
1678+
}
1679+
16441680
/// Sets the value of [client_operation_id][crate::model::managed_zones::PatchRequest::client_operation_id].
16451681
pub fn set_client_operation_id<T>(mut self, v: T) -> Self
16461682
where
@@ -1910,6 +1946,42 @@ pub mod managed_zones {
19101946
.map(gax::response::Response::into_body)
19111947
}
19121948

1949+
/// Creates a [Poller][lro::Poller] to work with `update`.
1950+
pub fn poller(self) -> impl lro::Poller<crate::model::Operation, crate::model::Operation> {
1951+
let polling_error_policy = self.0.stub.get_polling_error_policy(&self.0.options);
1952+
let polling_backoff_policy = self.0.stub.get_polling_backoff_policy(&self.0.options);
1953+
1954+
let stub = self.0.stub.clone();
1955+
let mut options = self.0.options.clone();
1956+
options.set_retry_policy(gax::retry_policy::NeverRetry);
1957+
let project = self.0.request.project.clone();
1958+
let managed_zone = self.0.request.managed_zone.clone();
1959+
let query = move |name| {
1960+
let stub = stub.clone();
1961+
let options = options.clone();
1962+
let project = project.clone();
1963+
let managed_zone = managed_zone.clone();
1964+
async {
1965+
GetOperation::new(stub)
1966+
.set_project(project)
1967+
.set_managed_zone(managed_zone)
1968+
.set_operation(name)
1969+
.with_options(options)
1970+
.send()
1971+
.await
1972+
}
1973+
};
1974+
1975+
let start = move || async { self.send().await };
1976+
1977+
lro::internal::new_discovery_poller(
1978+
polling_error_policy,
1979+
polling_backoff_policy,
1980+
start,
1981+
query,
1982+
)
1983+
}
1984+
19131985
/// Sets the value of [client_operation_id][crate::model::managed_zones::UpdateRequest::client_operation_id].
19141986
pub fn set_client_operation_id<T>(mut self, v: T) -> Self
19151987
where
@@ -1965,6 +2037,99 @@ pub mod managed_zones {
19652037
&mut self.0.options
19662038
}
19672039
}
2040+
2041+
/// The request builder for [ManagedZones::get_operation][crate::client::ManagedZones::get_operation] calls.
2042+
///
2043+
/// # Example
2044+
/// ```
2045+
/// # use google_cloud_dns_v1::builder::managed_zones::GetOperation;
2046+
/// # async fn sample() -> gax::Result<()> {
2047+
///
2048+
/// let builder = prepare_request_builder();
2049+
/// let response = builder.send().await?;
2050+
/// # Ok(()) }
2051+
///
2052+
/// fn prepare_request_builder() -> GetOperation {
2053+
/// # panic!();
2054+
/// // ... details omitted ...
2055+
/// }
2056+
/// ```
2057+
#[derive(Clone, Debug)]
2058+
pub struct GetOperation(RequestBuilder<crate::model::managed_zone_operations::GetRequest>);
2059+
2060+
impl GetOperation {
2061+
pub(crate) fn new(
2062+
stub: std::sync::Arc<dyn super::super::stub::dynamic::ManagedZones>,
2063+
) -> Self {
2064+
Self(RequestBuilder::new(stub))
2065+
}
2066+
2067+
/// Sets the full request, replacing any prior values.
2068+
pub fn with_request<V: Into<crate::model::managed_zone_operations::GetRequest>>(
2069+
mut self,
2070+
v: V,
2071+
) -> Self {
2072+
self.0.request = v.into();
2073+
self
2074+
}
2075+
2076+
/// Sets all the options, replacing any prior values.
2077+
pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
2078+
self.0.options = v.into();
2079+
self
2080+
}
2081+
2082+
/// Sends the request.
2083+
pub async fn send(self) -> Result<crate::model::Operation> {
2084+
(*self.0.stub)
2085+
.get_operation(self.0.request, self.0.options)
2086+
.await
2087+
.map(gax::response::Response::into_body)
2088+
}
2089+
2090+
/// Sets the value of [client_operation_id][crate::model::managed_zone_operations::GetRequest::client_operation_id].
2091+
pub fn set_client_operation_id<T>(mut self, v: T) -> Self
2092+
where
2093+
T: std::convert::Into<std::string::String>,
2094+
{
2095+
self.0.request.client_operation_id = std::option::Option::Some(v.into());
2096+
self
2097+
}
2098+
2099+
/// Sets or clears the value of [client_operation_id][crate::model::managed_zone_operations::GetRequest::client_operation_id].
2100+
pub fn set_or_clear_client_operation_id<T>(mut self, v: std::option::Option<T>) -> Self
2101+
where
2102+
T: std::convert::Into<std::string::String>,
2103+
{
2104+
self.0.request.client_operation_id = v.map(|x| x.into());
2105+
self
2106+
}
2107+
2108+
/// Sets the value of [managed_zone][crate::model::managed_zone_operations::GetRequest::managed_zone].
2109+
pub fn set_managed_zone<T: Into<std::string::String>>(mut self, v: T) -> Self {
2110+
self.0.request.managed_zone = v.into();
2111+
self
2112+
}
2113+
2114+
/// Sets the value of [operation][crate::model::managed_zone_operations::GetRequest::operation].
2115+
pub fn set_operation<T: Into<std::string::String>>(mut self, v: T) -> Self {
2116+
self.0.request.operation = v.into();
2117+
self
2118+
}
2119+
2120+
/// Sets the value of [project][crate::model::managed_zone_operations::GetRequest::project].
2121+
pub fn set_project<T: Into<std::string::String>>(mut self, v: T) -> Self {
2122+
self.0.request.project = v.into();
2123+
self
2124+
}
2125+
}
2126+
2127+
#[doc(hidden)]
2128+
impl gax::options::internal::RequestBuilder for GetOperation {
2129+
fn request_options(&mut self) -> &mut gax::options::RequestOptions {
2130+
&mut self.0.options
2131+
}
2132+
}
19682133
}
19692134

19702135
pub mod policies {

src/generated/cloud/dns/v1/src/client.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,11 @@ impl ManagedZones {
509509
pub fn update(&self) -> super::builder::managed_zones::Update {
510510
super::builder::managed_zones::Update::new(self.inner.clone())
511511
}
512+
513+
/// Fetches the representation of an existing Operation.
514+
pub fn get_operation(&self) -> super::builder::managed_zones::GetOperation {
515+
super::builder::managed_zones::GetOperation::new(self.inner.clone())
516+
}
512517
}
513518

514519
/// Implements a client for the Cloud DNS API.

src/generated/cloud/dns/v1/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,5 @@ pub(crate) mod info {
9090
};
9191
}
9292
}
93+
94+
pub mod operation;

src/generated/cloud/dns/v1/src/model.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ extern crate bytes;
2222
extern crate gax;
2323
extern crate gaxi;
2424
extern crate lazy_static;
25+
extern crate lro;
2526
extern crate reqwest;
2627
extern crate serde;
2728
extern crate serde_json;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2026 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+
use crate::model::Operation;
16+
17+
impl lro::internal::DiscoveryOperation for Operation {
18+
fn name(&self) -> Option<&String> {
19+
self.id.as_ref()
20+
}
21+
fn done(&self) -> bool {
22+
self.status == Some(crate::model::operation::Status::Done)
23+
}
24+
}

src/generated/cloud/dns/v1/src/stub.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,39 @@ pub trait ManagedZones: std::fmt::Debug + Send + Sync {
254254
> + Send {
255255
gaxi::unimplemented::unimplemented_stub()
256256
}
257+
258+
/// Implements [super::client::ManagedZones::get_operation].
259+
fn get_operation(
260+
&self,
261+
_req: crate::model::managed_zone_operations::GetRequest,
262+
_options: gax::options::RequestOptions,
263+
) -> impl std::future::Future<
264+
Output = crate::Result<gax::response::Response<crate::model::Operation>>,
265+
> + Send {
266+
gaxi::unimplemented::unimplemented_stub()
267+
}
268+
269+
/// Returns the polling error policy.
270+
///
271+
/// When mocking, this method is typically irrelevant. Do not try to verify
272+
/// it is called by your mocks.
273+
fn get_polling_error_policy(
274+
&self,
275+
_options: &gax::options::RequestOptions,
276+
) -> std::sync::Arc<dyn gax::polling_error_policy::PollingErrorPolicy> {
277+
std::sync::Arc::new(gax::polling_error_policy::Aip194Strict)
278+
}
279+
280+
/// Returns the polling backoff policy.
281+
///
282+
/// When mocking, this method is typically irrelevant. Do not try to verify
283+
/// it is called by your mocks.
284+
fn get_polling_backoff_policy(
285+
&self,
286+
_options: &gax::options::RequestOptions,
287+
) -> std::sync::Arc<dyn gax::polling_backoff_policy::PollingBackoffPolicy> {
288+
std::sync::Arc::new(gax::exponential_backoff::ExponentialBackoff::default())
289+
}
257290
}
258291

259292
/// Defines the trait used to implement [super::client::Policies].

src/generated/cloud/dns/v1/src/stub/dynamic.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,22 @@ pub trait ManagedZones: std::fmt::Debug + Send + Sync {
200200
req: crate::model::managed_zones::UpdateRequest,
201201
options: gax::options::RequestOptions,
202202
) -> crate::Result<gax::response::Response<crate::model::Operation>>;
203+
204+
async fn get_operation(
205+
&self,
206+
req: crate::model::managed_zone_operations::GetRequest,
207+
options: gax::options::RequestOptions,
208+
) -> crate::Result<gax::response::Response<crate::model::Operation>>;
209+
210+
fn get_polling_error_policy(
211+
&self,
212+
options: &gax::options::RequestOptions,
213+
) -> std::sync::Arc<dyn gax::polling_error_policy::PollingErrorPolicy>;
214+
215+
fn get_polling_backoff_policy(
216+
&self,
217+
options: &gax::options::RequestOptions,
218+
) -> std::sync::Arc<dyn gax::polling_backoff_policy::PollingBackoffPolicy>;
203219
}
204220

205221
/// All implementations of [super::ManagedZones] also implement [ManagedZones].
@@ -286,6 +302,29 @@ impl<T: super::ManagedZones> ManagedZones for T {
286302
) -> crate::Result<gax::response::Response<crate::model::Operation>> {
287303
T::update(self, req, options).await
288304
}
305+
306+
/// Forwards the call to the implementation provided by `T`.
307+
async fn get_operation(
308+
&self,
309+
req: crate::model::managed_zone_operations::GetRequest,
310+
options: gax::options::RequestOptions,
311+
) -> crate::Result<gax::response::Response<crate::model::Operation>> {
312+
T::get_operation(self, req, options).await
313+
}
314+
315+
fn get_polling_error_policy(
316+
&self,
317+
options: &gax::options::RequestOptions,
318+
) -> std::sync::Arc<dyn gax::polling_error_policy::PollingErrorPolicy> {
319+
T::get_polling_error_policy(self, options)
320+
}
321+
322+
fn get_polling_backoff_policy(
323+
&self,
324+
options: &gax::options::RequestOptions,
325+
) -> std::sync::Arc<dyn gax::polling_backoff_policy::PollingBackoffPolicy> {
326+
T::get_polling_backoff_policy(self, options)
327+
}
289328
}
290329

291330
/// A dyn-compatible, crate-private version of [super::Policies].

0 commit comments

Comments
 (0)