google-cloud-api-serviceusage-v1 1.9.0

Google Cloud Client Libraries for Rust - Service Usage API
Documentation
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by sidekick. DO NOT EDIT.
#![allow(rustdoc::redundant_explicit_links)]
#![allow(rustdoc::broken_intra_doc_links)]

/// Implements a client for the Service Usage API.
///
/// # Example
/// ```
/// # use google_cloud_api_serviceusage_v1::client::ServiceUsage;
/// use google_cloud_gax::paginator::ItemPaginator as _;
/// # async fn sample() -> Result<(), Box<dyn std::error::Error>> {
///     let client = ServiceUsage::builder().build().await?;
///     let parent = "parent_value";
///     let mut list = client.list_services()
///         .set_parent(parent)
///         .by_item();
///     while let Some(item) = list.next().await.transpose()? {
///         println!("{:?}", item);
///     }
/// # Ok(()) }
/// ```
///
/// # Service Description
///
/// Enables services that service consumers want to use on Google Cloud Platform,
/// lists the available or enabled services, or disables services that service
/// consumers no longer use.
///
/// See [Service Usage API](https://cloud.google.com/service-usage/docs/overview)
///
/// # Configuration
///
/// To configure `ServiceUsage` use the `with_*` methods in the type returned
/// by [builder()][ServiceUsage::builder]. The default configuration should
/// work for most applications. Common configuration changes include
///
/// * [with_endpoint()]: by default this client uses the global default endpoint
///   (`https://serviceusage.googleapis.com`). Applications using regional
///   endpoints or running in restricted networks (e.g. a network configured
//    with [Private Google Access with VPC Service Controls]) may want to
///   override this default.
/// * [with_credentials()]: by default this client uses
///   [Application Default Credentials]. Applications using custom
///   authentication may need to override this default.
///
/// [with_endpoint()]: super::builder::service_usage::ClientBuilder::with_endpoint
/// [with_credentials()]: super::builder::service_usage::ClientBuilder::with_credentials
/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
///
/// # Pooling and Cloning
///
/// `ServiceUsage` holds a connection pool internally, it is advised to
/// create one and reuse it. You do not need to wrap `ServiceUsage` in
/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
/// already uses an `Arc` internally.
#[derive(Clone, Debug)]
pub struct ServiceUsage {
    inner: std::sync::Arc<dyn super::stub::dynamic::ServiceUsage>,
}

impl ServiceUsage {
    /// Returns a builder for [ServiceUsage].
    ///
    /// ```
    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
    /// # use google_cloud_api_serviceusage_v1::client::ServiceUsage;
    /// let client = ServiceUsage::builder().build().await?;
    /// # Ok(()) }
    /// ```
    pub fn builder() -> super::builder::service_usage::ClientBuilder {
        crate::new_client_builder(super::builder::service_usage::client::Factory)
    }

    /// Creates a new client from the provided stub.
    ///
    /// The most common case for calling this function is in tests mocking the
    /// client's behavior.
    pub fn from_stub<T>(stub: T) -> Self
    where
        T: super::stub::ServiceUsage + 'static,
    {
        Self {
            inner: std::sync::Arc::new(stub),
        }
    }

    pub(crate) async fn new(
        config: gaxi::options::ClientConfig,
    ) -> crate::ClientBuilderResult<Self> {
        let inner = Self::build_inner(config).await?;
        Ok(Self { inner })
    }

    async fn build_inner(
        conf: gaxi::options::ClientConfig,
    ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::ServiceUsage>> {
        if gaxi::options::tracing_enabled(&conf) {
            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
        }
        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
    }

    async fn build_transport(
        conf: gaxi::options::ClientConfig,
    ) -> crate::ClientBuilderResult<impl super::stub::ServiceUsage> {
        super::transport::ServiceUsage::new(conf).await
    }

    async fn build_with_tracing(
        conf: gaxi::options::ClientConfig,
    ) -> crate::ClientBuilderResult<impl super::stub::ServiceUsage> {
        Self::build_transport(conf)
            .await
            .map(super::tracing::ServiceUsage::new)
    }

    /// Enable a service so that it can be used with a project.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    ///
    /// # Example
    /// ```
    /// # use google_cloud_api_serviceusage_v1::client::ServiceUsage;
    /// use google_cloud_lro::Poller;
    /// use google_cloud_api_serviceusage_v1::Result;
    /// async fn sample(
    ///    client: &ServiceUsage
    /// ) -> Result<()> {
    ///     let response = client.enable_service()
    ///         /* set fields */
    ///         .poller().until_done().await?;
    ///     println!("response {:?}", response);
    ///     Ok(())
    /// }
    /// ```
    pub fn enable_service(&self) -> super::builder::service_usage::EnableService {
        super::builder::service_usage::EnableService::new(self.inner.clone())
    }

    /// Disable a service so that it can no longer be used with a project.
    /// This prevents unintended usage that may cause unexpected billing
    /// charges or security leaks.
    ///
    /// It is not valid to call the disable method on a service that is not
    /// currently enabled. Callers will receive a `FAILED_PRECONDITION` status if
    /// the target service is not currently enabled.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    ///
    /// # Example
    /// ```
    /// # use google_cloud_api_serviceusage_v1::client::ServiceUsage;
    /// use google_cloud_lro::Poller;
    /// use google_cloud_api_serviceusage_v1::Result;
    /// async fn sample(
    ///    client: &ServiceUsage
    /// ) -> Result<()> {
    ///     let response = client.disable_service()
    ///         /* set fields */
    ///         .poller().until_done().await?;
    ///     println!("response {:?}", response);
    ///     Ok(())
    /// }
    /// ```
    pub fn disable_service(&self) -> super::builder::service_usage::DisableService {
        super::builder::service_usage::DisableService::new(self.inner.clone())
    }

    /// Returns the service configuration and enabled state for a given service.
    ///
    /// # Example
    /// ```
    /// # use google_cloud_api_serviceusage_v1::client::ServiceUsage;
    /// use google_cloud_api_serviceusage_v1::Result;
    /// async fn sample(
    ///    client: &ServiceUsage
    /// ) -> Result<()> {
    ///     let response = client.get_service()
    ///         /* set fields */
    ///         .send().await?;
    ///     println!("response {:?}", response);
    ///     Ok(())
    /// }
    /// ```
    pub fn get_service(&self) -> super::builder::service_usage::GetService {
        super::builder::service_usage::GetService::new(self.inner.clone())
    }

    /// List all services available to the specified project, and the current
    /// state of those services with respect to the project. The list includes
    /// all public services, all services for which the calling user has the
    /// `servicemanagement.services.bind` permission, and all services that have
    /// already been enabled on the project. The list can be filtered to
    /// only include services in a specific state, for example to only include
    /// services enabled on the project.
    ///
    /// WARNING: If you need to query enabled services frequently or across
    /// an organization, you should use
    /// [Cloud Asset Inventory
    /// API](https://cloud.google.com/asset-inventory/docs/apis), which provides
    /// higher throughput and richer filtering capability.
    ///
    /// # Example
    /// ```
    /// # use google_cloud_api_serviceusage_v1::client::ServiceUsage;
    /// use google_cloud_gax::paginator::ItemPaginator as _;
    /// use google_cloud_api_serviceusage_v1::Result;
    /// async fn sample(
    ///    client: &ServiceUsage, parent: &str
    /// ) -> Result<()> {
    ///     let mut list = client.list_services()
    ///         .set_parent(parent)
    ///         .by_item();
    ///     while let Some(item) = list.next().await.transpose()? {
    ///         println!("{:?}", item);
    ///     }
    ///     Ok(())
    /// }
    /// ```
    pub fn list_services(&self) -> super::builder::service_usage::ListServices {
        super::builder::service_usage::ListServices::new(self.inner.clone())
    }

    /// Enable multiple services on a project. The operation is atomic: if enabling
    /// any service fails, then the entire batch fails, and no state changes occur.
    /// To enable a single service, use the `EnableService` method instead.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    ///
    /// # Example
    /// ```
    /// # use google_cloud_api_serviceusage_v1::client::ServiceUsage;
    /// use google_cloud_lro::Poller;
    /// use google_cloud_api_serviceusage_v1::Result;
    /// async fn sample(
    ///    client: &ServiceUsage
    /// ) -> Result<()> {
    ///     let response = client.batch_enable_services()
    ///         /* set fields */
    ///         .poller().until_done().await?;
    ///     println!("response {:?}", response);
    ///     Ok(())
    /// }
    /// ```
    pub fn batch_enable_services(&self) -> super::builder::service_usage::BatchEnableServices {
        super::builder::service_usage::BatchEnableServices::new(self.inner.clone())
    }

    /// Returns the service configurations and enabled states for a given list of
    /// services.
    ///
    /// # Example
    /// ```
    /// # use google_cloud_api_serviceusage_v1::client::ServiceUsage;
    /// use google_cloud_api_serviceusage_v1::Result;
    /// async fn sample(
    ///    client: &ServiceUsage
    /// ) -> Result<()> {
    ///     let response = client.batch_get_services()
    ///         /* set fields */
    ///         .send().await?;
    ///     println!("response {:?}", response);
    ///     Ok(())
    /// }
    /// ```
    pub fn batch_get_services(&self) -> super::builder::service_usage::BatchGetServices {
        super::builder::service_usage::BatchGetServices::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
    ///
    /// # Example
    /// ```
    /// # use google_cloud_api_serviceusage_v1::client::ServiceUsage;
    /// use google_cloud_gax::paginator::ItemPaginator as _;
    /// use google_cloud_api_serviceusage_v1::Result;
    /// async fn sample(
    ///    client: &ServiceUsage
    /// ) -> Result<()> {
    ///     let mut list = client.list_operations()
    ///         /* set fields */
    ///         .by_item();
    ///     while let Some(item) = list.next().await.transpose()? {
    ///         println!("{:?}", item);
    ///     }
    ///     Ok(())
    /// }
    /// ```
    pub fn list_operations(&self) -> super::builder::service_usage::ListOperations {
        super::builder::service_usage::ListOperations::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
    ///
    /// # Example
    /// ```
    /// # use google_cloud_api_serviceusage_v1::client::ServiceUsage;
    /// use google_cloud_api_serviceusage_v1::Result;
    /// async fn sample(
    ///    client: &ServiceUsage
    /// ) -> Result<()> {
    ///     let response = client.get_operation()
    ///         /* set fields */
    ///         .send().await?;
    ///     println!("response {:?}", response);
    ///     Ok(())
    /// }
    /// ```
    pub fn get_operation(&self) -> super::builder::service_usage::GetOperation {
        super::builder::service_usage::GetOperation::new(self.inner.clone())
    }
}