1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
// Copyright 2022 Rigetti Computing
//
// 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
//
// http://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.
//! This crate provides an autogenerated gRPC client for the QCS API, along with helper utilities for automatically loading
//! credentials from a user's QCS config and keeping authentication tokens refreshed.
//!
//! - [`get_channel`]: create a [`Channel`](tonic::transport::Channel) to the given gRPC endpoint with QCS authentication automatically set up.
//! - [`wrap_channel`]: wrap an existing [`Channel`](tonic::transport::Channel) with QCS authentication.
//!
//! ## Quick Start
//!
//! ```rust
//! use qcs_api_client_grpc::get_channel;
//! use qcs_api_client_grpc::services::controller::controller_client::ControllerClient;
//! use qcs_api_client_grpc::services::translation::translation_client::TranslationClient;
//!
//! async fn controller_request() {
//! let uri = "example.per-qpu.rigetti.com:50000".parse().unwrap();
//! let channel = get_channel(uri).unwrap();
//! let mut client = ControllerClient::new(channel);
//! // Use the client
//! }
//!
//! fn translation_request() {
//! let uri = "example.translation.rigetti.com:50000".parse().unwrap();
//! let channel = get_channel(uri).unwrap();
//! let mut client = TranslationClient::new(channel);
//! // Use the client
//! }
//! ```
//!
//! # Crate features
//!
//! * `server`: include the generated server code for both Controller Service
//! and Translation Service
//! * `regen`: regenerate the protobuf code and store it in `./src/gen`
//!
//! By default, both features are disabled.
/// Utilities for creating and working with [`Channel`]s.
///
/// This module contains helper code for wrapping a [`Channel`] so that QCS credentials are
/// automatically used and refreshed as necessary.
///
/// Most users will want to use [`get_channel`], [`get_wrapped_channel`], or [`wrap_channel`].
///
/// # Generics
///
/// The functions for wrapping channels use generics `C: GrpcService<BoxBody>` to accept not only
/// bare [`Channel`]s but also channels wrapped in middleware like [`RefreshService`] or
/// [`RetryService`]
///
/// # Example
///
/// To create a channel that automatically retries on certain errors and refreshes QCS credentials
/// when authentication fails:
///
/// ```no_run
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// use qcs_api_client_grpc::channel::parse_uri;
/// use qcs_api_client_grpc::channel::get_channel;
/// use qcs_api_client_grpc::channel::wrap_channel;
/// use qcs_api_client_grpc::channel::wrap_channel_with_retry;
///
/// let uri = parse_uri("https://api.qcs.rigetti.com")?;
/// let channel = get_channel(uri)?;
/// let with_creds = wrap_channel(channel).await?;
/// let with_creds_and_retry = wrap_channel_with_retry(with_creds);
/// // Use with_creds_and_retry as a gRPC client
/// # Ok(())
/// # }
/// ```
pub mod channel;
pub use channel::{
get_channel, get_channel_with_timeout, get_endpoint, get_endpoint_with_timeout,
get_wrapped_channel, wrap_channel,
};
pub use qcs_api_client_common::configuration as client_configuration;
#[allow(clippy::derive_partial_eq_without_eq)]
#[allow(clippy::needless_borrow)]
pub mod models {
pub mod controller {
include!("gen/models.controller.rs");
include!("gen/models.controller.serde.rs");
}
pub mod translation {
include!("gen/models.translation.rs");
include!("gen/models.translation.serde.rs");
}
}
#[allow(clippy::derive_partial_eq_without_eq)]
pub mod services {
pub mod controller {
include!("gen/services.controller.rs");
include!("gen/services.controller.serde.rs");
}
pub mod translation {
include!("gen/services.translation.rs");
include!("gen/services.translation.serde.rs");
}
}