1 parent
9c305f2a4d
commit
21261db8ef
185 files changed
+52751
-217
No files matched your search
+26
@@ -0,0 +1,26 @@
|
||||
use schema_api::{
|
||||
tonic::transport::{Certificate, ClientTlsConfig, Identity},
|
||||
ApiClient,
|
||||
};
|
||||
use std::{env, error::Error, fs};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn Error>> {
|
||||
let mut tls = ClientTlsConfig::new()
|
||||
.ca_certificate(Certificate::from_pem(fs::read(env::var("API_CA_PEM")?)?));
|
||||
if let Ok(domain) = env::var("API_TLS_DOMAIN") {
|
||||
tls = tls.domain_name(domain);
|
||||
}
|
||||
if let Ok(cert_path) = env::var("API_CLIENT_CERT_PEM") {
|
||||
tls = tls.identity(Identity::from_pem(
|
||||
fs::read(cert_path)?,
|
||||
fs::read(env::var("API_CLIENT_KEY_PEM")?)?,
|
||||
));
|
||||
}
|
||||
let _client = ApiClient::builder(env::var("API_ENDPOINT")?)?
|
||||
.tls_config(tls)?
|
||||
.connect()
|
||||
.await?;
|
||||
println!("Connected with custom TLS configuration");
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
fn main() {
|
||||
let pool = schema_api::reflection::descriptor_pool();
|
||||
for service in pool.services() {
|
||||
println!("{}", service.full_name());
|
||||
for method in service.methods() {
|
||||
println!(
|
||||
" {}({}{}) -> {}{}",
|
||||
method.name(),
|
||||
if method.is_client_streaming() {
|
||||
"stream "
|
||||
} else {
|
||||
""
|
||||
},
|
||||
method.input().full_name(),
|
||||
if method.is_server_streaming() {
|
||||
"stream "
|
||||
} else {
|
||||
""
|
||||
},
|
||||
method.output().full_name(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
use schema_api::{api, ApiClient, SessionRequest, SessionToken};
|
||||
use std::{env, error::Error, time::Duration};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn Error>> {
|
||||
let client = ApiClient::builder(env::var("API_ENDPOINT")?)?
|
||||
.connect_timeout(Duration::from_secs(10))
|
||||
.request_timeout(Duration::from_secs(30))
|
||||
.connect()
|
||||
.await?;
|
||||
// Credential encoding is server-defined; this example passes the supplied values verbatim.
|
||||
let reply = client
|
||||
.login()
|
||||
.login(api::LoginData {
|
||||
email: env::var("API_EMAIL")?,
|
||||
password: env::var("API_PASSWORD")?,
|
||||
otp: env::var("API_OTP").unwrap_or_default(),
|
||||
device_id: env::var("API_DEVICE_ID").unwrap_or_default(),
|
||||
device_name: "Rust API client".into(),
|
||||
..Default::default()
|
||||
})
|
||||
.await?
|
||||
.into_inner();
|
||||
let session = SessionToken::try_from(&reply)?;
|
||||
println!("Login succeeded");
|
||||
let status = client
|
||||
.login()
|
||||
.session(api::Session::default().with_session(&session))
|
||||
.await?
|
||||
.into_inner();
|
||||
schema_api::session::validate_session_status(&status)?;
|
||||
println!("Session is valid");
|
||||
Ok(())
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
use schema_api::{
|
||||
tonic::metadata::{MetadataKey, MetadataMap, MetadataValue},
|
||||
ApiClient,
|
||||
};
|
||||
use std::{env, error::Error};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn Error>> {
|
||||
// The schemas do not specify push authentication. Supply your server's metadata contract.
|
||||
let mut headers = MetadataMap::new();
|
||||
if let Ok(name) = env::var("API_PUSH_HEADER") {
|
||||
let key: MetadataKey<_> = name.parse()?;
|
||||
let mut value: MetadataValue<_> = env::var("API_PUSH_VALUE")?.parse()?;
|
||||
value.set_sensitive(true);
|
||||
headers.insert(key, value);
|
||||
}
|
||||
let client = ApiClient::builder(env::var("API_ENDPOINT")?)?
|
||||
.metadata(headers)
|
||||
.connect()
|
||||
.await?;
|
||||
let mut stream = client.push().long_pull(()).await?.into_inner();
|
||||
while let Some(message) = stream.message().await? {
|
||||
println!("Received {} opaque payload bytes", message.payload.len());
|
||||
// If your server uses this envelope, explicitly decode it with:
|
||||
// let notification = schema_api::wire::decode_push_notification(&message)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Reference in new issue
Block a user