pub struct Client {
pub client: Arc<Mutex<ClientEnum>>,
pub inner: Arc<Mutex<ClientInner>>,
pub config: Arc<Mutex<Option<Config>>>,
pub auto_reconnect: Arc<Mutex<bool>>,
pub url: Arc<Mutex<String>>,
pub username: Arc<Mutex<String>>,
pub password: Arc<Mutex<String>>,
pub jwt: Arc<Mutex<String>>,
pub state: Arc<Mutex<ClientState>>,
pub msgcount: Arc<Mutex<i32>>,
pub reconnect_ms: Arc<Mutex<i32>>,
pub default_timeout: Arc<Mutex<Duration>>,
/* private fields */
}
Expand description
The Client
struct provides the client for the OpenIAP service.
Initialize a new client, by calling the Client::new_connect method.
Fields§
§client: Arc<Mutex<ClientEnum>>
The inner client object
inner: Arc<Mutex<ClientInner>>
The inner client.
config: Arc<Mutex<Option<Config>>>
The Config
struct provides the configuration for the OpenIAP service we are connecting to.
auto_reconnect: Arc<Mutex<bool>>
Should client automatically reconnect, if disconnected?
url: Arc<Mutex<String>>
URL used to connect to server, processed and without credentials
username: Arc<Mutex<String>>
Username used to connect to server
password: Arc<Mutex<String>>
Password used to connect to server
jwt: Arc<Mutex<String>>
JWT token used to connect to server
state: Arc<Mutex<ClientState>>
The client connection state.
msgcount: Arc<Mutex<i32>>
Inceasing message count, used as unique id for messages.
reconnect_ms: Arc<Mutex<i32>>
Reconnect interval in milliseconds, this will slowly increase if we keep getting disconnected.
default_timeout: Arc<Mutex<Duration>>
The default timeout for requests
Implementations§
Source§impl Client
impl Client
Sourcepub async fn connect_grpc(
url: String,
) -> Result<FlowServiceClient<Channel>, Box<dyn Error>>
pub async fn connect_grpc( url: String, ) -> Result<FlowServiceClient<Channel>, Box<dyn Error>>
Connect to the server using gRPC protocol.
Sourcepub async fn setup_grpc_stream(&self) -> Result<(), OpenIAPError>
pub async fn setup_grpc_stream(&self) -> Result<(), OpenIAPError>
internal function, used to setup gRPC stream used for communication with the server. This function is called by [connect] and should not be called directly. It will “pre” process stream, watch and queue events, and call future promises, when a response is received.
Source§impl Client
impl Client
Sourcepub fn connect(&self, dst: &str) -> Result<(), OpenIAPError>
pub fn connect(&self, dst: &str) -> Result<(), OpenIAPError>
Connect the client to the OpenIAP server.
Sourcepub async fn load_config(&self, strurl: &str, url: &Url) -> Option<Config>
pub async fn load_config(&self, strurl: &str, url: &Url) -> Option<Config>
Load the configuration from the server.
Sourcepub async fn connect_async(&self, dst: &str) -> Result<(), OpenIAPError>
pub async fn connect_async(&self, dst: &str) -> Result<(), OpenIAPError>
Connect the client to the OpenIAP server.
Sourcepub async fn new_connect(dst: &str) -> Result<Self, OpenIAPError>
pub async fn new_connect(dst: &str) -> Result<Self, OpenIAPError>
Connect will initializes a new client and starts a connection to an OpenIAP server.
Use “” to autodetect the server from the environment variables (apiurl or grpcapiurl), or provide a URL.
You can add username and password, to login using local provider, or set them using OPENIAP_USERNAME and OPENIAP_PASSWORD environment variables.
It is highly recommended to not user username and password, but instead use a JWT token, set using the OPENIAP_JWT (or jwt) environment variable.
You can use the openiap vs.code extension to manage this, if you need to generate one your self, login to the OpenIAP server and then open the /jwtlong page.
If credentials are not provided, the client will run as guest.
If credentials are found, it will call Client::signin after successfully connecting to the server.
To troubleshoot issues, call enable_tracing.
use openiap_client::{OpenIAPError, Client, QueryRequest};
#[tokio::main]
async fn main() -> Result<(), OpenIAPError> {
let client = Client::new_connect("").await?;
let q = client.query( QueryRequest::with_projection(
"entities",
"{}",
"{\"name\":1}"
)).await?;
let items: serde_json::Value = serde_json::from_str(&q.results).unwrap();
let items: &Vec<serde_json::Value> = items.as_array().unwrap();
for item in items {
println!("Item: {:?}", item);
}
Ok(())
}
Sourcepub async fn post_connected(&self) -> Result<(), OpenIAPError>
pub async fn post_connected(&self) -> Result<(), OpenIAPError>
Handle auto-signin after a connection has been established.
Sourcepub async fn reconnect(&self) -> Result<(), OpenIAPError>
pub async fn reconnect(&self) -> Result<(), OpenIAPError>
Reconnect will attempt to reconnect to the OpenIAP server.
Sourcepub fn disconnect(&self)
pub fn disconnect(&self)
Disconnect the client from the OpenIAP server.
Sourcepub fn set_connected(&self, state: ClientState, message: Option<&str>)
pub fn set_connected(&self, state: ClientState, message: Option<&str>)
Set the connected flag to true or false
Sourcepub fn get_state(&self) -> ClientState
pub fn get_state(&self) -> ClientState
Get client state
Sourcepub fn set_state(&self, state: ClientState)
pub fn set_state(&self, state: ClientState)
Set client state
Sourcepub fn set_msgcount(&self, msgcount: i32)
pub fn set_msgcount(&self, msgcount: i32)
Set the msgcount value
Sourcepub fn inc_msgcount(&self) -> i32
pub fn inc_msgcount(&self) -> i32
Increment the msgcount value
Sourcepub fn get_reconnect_ms(&self) -> i32
pub fn get_reconnect_ms(&self) -> i32
Return value of reconnect_ms
Sourcepub fn reset_reconnect_ms(&self)
pub fn reset_reconnect_ms(&self)
Increment the reconnect_ms value
Sourcepub fn inc_reconnect_ms(&self) -> i32
pub fn inc_reconnect_ms(&self) -> i32
Increment the reconnect_ms value
Sourcepub fn push_handle(&self, handle: JoinHandle<()>)
pub fn push_handle(&self, handle: JoinHandle<()>)
Push tokio task handle to the task_handles vector
Sourcepub fn kill_handles(&self)
pub fn kill_handles(&self)
Kill all tokio task handles in the task_handles vector
Sourcepub fn set_default_timeout(&self, timeout: Duration)
pub fn set_default_timeout(&self, timeout: Duration)
Set the default timeout for the client commands
Sourcepub fn get_default_timeout(&self) -> Duration
pub fn get_default_timeout(&self) -> Duration
Return the default timeout for the client commands
Sourcepub fn set_connect_called(&self, connect_called: bool)
pub fn set_connect_called(&self, connect_called: bool)
Set the connect_called flag to true or false
Sourcepub fn set_auto_reconnect(&self, auto_reconnect: bool)
pub fn set_auto_reconnect(&self, auto_reconnect: bool)
Set the auto_reconnect flag to true or false
Sourcepub fn set_username(&self, username: &str)
pub fn set_username(&self, username: &str)
Set the username flag to true or false
Sourcepub fn set_password(&self, password: &str)
pub fn set_password(&self, password: &str)
Set the password value
Sourcepub fn set_service_name(&self, service_name: &str)
pub fn set_service_name(&self, service_name: &str)
Set the service name
Sourcepub fn get_service_name(&self) -> String
pub fn get_service_name(&self) -> String
Return value of the service name string
Sourcepub fn set_agent_name(&self, agent: &str)
pub fn set_agent_name(&self, agent: &str)
Set the agent name
Sourcepub fn get_agent_name(&self) -> String
pub fn get_agent_name(&self) -> String
Return value of the agent string
Sourcepub fn set_agent_version(&self, version: &str)
pub fn set_agent_version(&self, version: &str)
Set the agent version number
Sourcepub fn get_agent_version(&self) -> String
pub fn get_agent_version(&self) -> String
Return value of the agent version string
Sourcepub fn set_config(&self, config: Option<Config>)
pub fn set_config(&self, config: Option<Config>)
Set the config flag to true or false
Sourcepub fn get_config(&self) -> Option<Config>
pub fn get_config(&self) -> Option<Config>
Return value of the config
Sourcepub fn set_client(&self, client: ClientEnum)
pub fn set_client(&self, client: ClientEnum)
Set the client flag to true or false
Sourcepub fn set_runtime(&self, runtime: Option<Runtime>)
pub fn set_runtime(&self, runtime: Option<Runtime>)
Set the runtime flag to true or false
Sourcepub fn get_runtime(&self) -> &Mutex<Option<Runtime>>
pub fn get_runtime(&self) -> &Mutex<Option<Runtime>>
Return value of the runtime
Sourcepub fn get_runtime_handle(&self) -> Handle
pub fn get_runtime_handle(&self) -> Handle
Return value of the runtime handle
Sourcepub async fn on_event(&self, callback: Box<dyn Fn(ClientEvent) + Send + Sync>)
pub async fn on_event(&self, callback: Box<dyn Fn(ClientEvent) + Send + Sync>)
Method to allow the user to subscribe with a callback function
Sourcepub fn get_uniqueid() -> String
pub fn get_uniqueid() -> String
Internal function, used to generate a unique id for each message sent to the server.
Sourcepub async fn signin(
&self,
config: SigninRequest,
) -> Result<SigninResponse, OpenIAPError>
pub async fn signin( &self, config: SigninRequest, ) -> Result<SigninResponse, OpenIAPError>
Sign in to the OpenIAP service.
If no username and password is provided, it will attempt to use environment variables.
if config is set to validateonly, it will only validate the credentials, but not sign in.
If no jwt, username and password is provided, it will attempt to use environment variables.
will prefere OPENIAP_JWT (or jwt) over OPENIAP_USERNAME and OPENIAP_PASSWORD.
Sourcepub async fn list_collections(
&self,
includehist: bool,
) -> Result<String, OpenIAPError>
pub async fn list_collections( &self, includehist: bool, ) -> Result<String, OpenIAPError>
Return a list of collections in the database
- includehist: include historical collections, default is false. please see create_collection for examples on how to create collections.
Sourcepub async fn create_collection(
&self,
config: CreateCollectionRequest,
) -> Result<(), OpenIAPError>
pub async fn create_collection( &self, config: CreateCollectionRequest, ) -> Result<(), OpenIAPError>
Create a new collection in the database. You can create a collection by simply adding a new document to it using Client::insert_one. Or you can create a collecting using the following example:
use openiap_client::{Client, CreateCollectionRequest, DropCollectionRequest, OpenIAPError};
#[tokio::main]
async fn main() -> Result<(), OpenIAPError> {
let client = Client::new_connect("").await?;
//let collections = client.list_collections(false).await?;
//println!("Collections: {}", collections);
let config = CreateCollectionRequest::byname("rusttestcollection");
client.create_collection(config).await?;
let config = DropCollectionRequest::byname("rusttestcollection");
client.drop_collection(config).await?;
Ok(())
}
You can create a normal collection with a TTL index on the _created field, using the following example:
use openiap_client::{Client, CreateCollectionRequest, DropCollectionRequest, OpenIAPError};
#[tokio::main]
async fn main() -> Result<(), OpenIAPError> {
let client = Client::new_connect("").await?;
let config = CreateCollectionRequest::with_ttl(
"rusttestttlcollection",
60
);
client.create_collection(config).await?;
let config = DropCollectionRequest::byname("rusttestttlcollection");
client.drop_collection(config).await?;
Ok(())
}
You can create a time series collection using the following example: granularity can be one of: seconds, minutes, hours
use openiap_client::{Client, CreateCollectionRequest, DropCollectionRequest, OpenIAPError};
#[tokio::main]
async fn main() -> Result<(), OpenIAPError> {
let client = Client::new_connect("").await?;
let config = CreateCollectionRequest::timeseries(
"rusttesttscollection2",
"_created",
"minutes"
);
client.create_collection(config).await?;
let config = DropCollectionRequest::byname("rusttesttscollection2");
client.drop_collection(config).await?;
Ok(())
}
Sourcepub async fn drop_collection(
&self,
config: DropCollectionRequest,
) -> Result<(), OpenIAPError>
pub async fn drop_collection( &self, config: DropCollectionRequest, ) -> Result<(), OpenIAPError>
Drop a collection from the database, this will delete all data and indexes for the collection. See Client::create_collection for examples on how to create a collection.
Sourcepub async fn get_indexes(
&self,
config: GetIndexesRequest,
) -> Result<String, OpenIAPError>
pub async fn get_indexes( &self, config: GetIndexesRequest, ) -> Result<String, OpenIAPError>
Return all indexes for a collection in the database
use openiap_client::{Client, GetIndexesRequest, OpenIAPError};
#[tokio::main]
async fn main() -> Result<(), OpenIAPError> {
let client = Client::new_connect("").await?;
let config = GetIndexesRequest::bycollectionname("rustindextestcollection");
let indexes = client.get_indexes(config).await?;
println!("Indexes: {}", indexes);
Ok(())
}
Sourcepub async fn create_index(
&self,
config: CreateIndexRequest,
) -> Result<(), OpenIAPError>
pub async fn create_index( &self, config: CreateIndexRequest, ) -> Result<(), OpenIAPError>
Create an index in the database. Example of creating an index on the name field in the rustindextestcollection collection, and then dropping it again:
use openiap_client::{Client, DropIndexRequest, CreateIndexRequest, OpenIAPError};
#[tokio::main]
async fn main() -> Result<(), OpenIAPError> {
let client = Client::new_connect("").await?;
let config = CreateIndexRequest::bycollectionname(
"rustindextestcollection",
"{\"name\": 1}"
);
client.create_index(config).await?;
let config = DropIndexRequest::bycollectionname(
"rustindextestcollection",
"name_1"
);
client.drop_index(config).await?;
Ok(())
}
Example of creating an unique index on the address field in the rustindextestcollection collection, and then dropping it again:
use openiap_client::{Client, DropIndexRequest, CreateIndexRequest, OpenIAPError};
#[tokio::main]
async fn main() -> Result<(), OpenIAPError> {
let client = Client::new_connect("").await?;
let mut config = CreateIndexRequest::bycollectionname(
"rustindextestcollection",
"{\"address\": 1}"
);
config.options = "{\"unique\": true}".to_string();
client.create_index(config).await?;
let config = DropIndexRequest::bycollectionname(
"rustindextestcollection",
"address_1"
);
client.drop_index(config).await?;
Ok(())
}
Sourcepub async fn drop_index(
&self,
config: DropIndexRequest,
) -> Result<(), OpenIAPError>
pub async fn drop_index( &self, config: DropIndexRequest, ) -> Result<(), OpenIAPError>
Drop an index from the database See Client::create_index for an example on how to create and drop an index.
Sourcepub async fn query(
&self,
config: QueryRequest,
) -> Result<QueryResponse, OpenIAPError>
pub async fn query( &self, config: QueryRequest, ) -> Result<QueryResponse, OpenIAPError>
To query all documents in the entities collection where _type is test, you can use the following example:
use openiap_client::{OpenIAPError, Client, QueryRequest};
#[tokio::main]
async fn main() -> Result<(), OpenIAPError> {
let client = Client::new_connect("").await?;
let q = client.query( QueryRequest::with_query(
"entities",
"{\"_type\":\"test\"}"
)).await?;
let items: serde_json::Value = serde_json::from_str(&q.results).unwrap();
let items: &Vec<serde_json::Value> = items.as_array().unwrap();
for item in items {
println!("Item: {:?}", item);
}
Ok(())
}
To query all documents in the entities collection, and only return the name and _id field for all documents, you can use the following example:
use openiap_client::{OpenIAPError, Client, QueryRequest};
#[tokio::main]
async fn main() -> Result<(), OpenIAPError> {
let client = Client::new_connect("").await?;
let q = client.query( QueryRequest::with_projection(
"entities",
"{}",
"{\"name\":1}"
)).await?;
let items: serde_json::Value = serde_json::from_str(&q.results).unwrap();
let items: &Vec<serde_json::Value> = items.as_array().unwrap();
for item in items {
println!("Item: {:?}", item);
}
Ok(())
}
Sourcepub async fn get_one(&self, config: QueryRequest) -> Option<Value>
pub async fn get_one(&self, config: QueryRequest) -> Option<Value>
Try and get a single document from the database.
If no document is found, it will return None.
use openiap_client::{OpenIAPError, Client, QueryRequest};
#[tokio::main]
async fn main() -> Result<(), OpenIAPError> {
let client = Client::new_connect("").await?;
let config = QueryRequest::with_query(
"users",
"{\"username\":\"guest\"}"
);
let item = client.get_one(config).await;
match item {
Some(item) => {
assert_eq!(item["username"], "guest");
println!("Item: {:?}", item);
}
None => {
println!("No item found");
assert!(false, "No item found");
}
}
Ok(())
}
Sourcepub async fn get_document_version(
&self,
config: GetDocumentVersionRequest,
) -> Result<String, OpenIAPError>
pub async fn get_document_version( &self, config: GetDocumentVersionRequest, ) -> Result<String, OpenIAPError>
Try and get a specefic version of a document from the database, reconstructing it from the history collection
use openiap_client::{OpenIAPError, Client, GetDocumentVersionRequest, InsertOneRequest, UpdateOneRequest};
#[tokio::main]
async fn main() -> Result<(), OpenIAPError> {
let client = Client::new_connect("").await?;
let item = "{\"name\": \"test from rust\", \"_type\": \"test\"}";
let query = InsertOneRequest {
collectionname: "entities".to_string(),
item: item.to_string(),
j: true,
w: 2,
..Default::default()
};
let response = client.insert_one(query).await;
let response = match response {
Ok(r) => r,
Err(e) => {
println!("Error: {:?}", e);
assert!(false, "insert_one failed with {:?}", e);
return Ok(());
}
};
let _obj: serde_json::Value = serde_json::from_str(&response.result).unwrap();
let _id = _obj["_id"].as_str().unwrap();
let item = format!("{{\"name\":\"updated from rust\", \"_id\": \"{}\"}}", _id);
let query = UpdateOneRequest {
collectionname: "entities".to_string(),
item: item.to_string(),
..Default::default()
};
let response = client.update_one(query).await;
_ = match response {
Ok(r) => r,
Err(e) => {
println!("Error: {:?}", e);
assert!(false, "update_one failed with {:?}", e);
return Ok(());
}
};
let query = GetDocumentVersionRequest {
collectionname: "entities".to_string(),
id: _id.to_string(),
version: 0,
..Default::default()
};
let response = client.get_document_version(query).await;
let response = match response {
Ok(r) => r,
Err(e) => {
println!("Error: {:?}", e);
assert!(false, "get_document_version failed with {:?}", e);
return Ok(());
}
};
let _obj = serde_json::from_str(&response);
let _obj: serde_json::Value = match _obj {
Ok(r) => r,
Err(e) => {
println!("Error: {:?}", e);
assert!(
false,
"parse get_document_version result failed with {:?}",
e
);
return Ok(());
}
};
let name = _obj["name"].as_str().unwrap();
let version = _obj["_version"].as_i64().unwrap();
println!("version 0 Name: {}, Version: {}", name, version);
assert_eq!(name, "test from rust");
let query = GetDocumentVersionRequest {
collectionname: "entities".to_string(),
id: _id.to_string(),
version: 1,
..Default::default()
};
let response = client.get_document_version(query).await;
assert!(
response.is_ok(),
"test_get_document_version failed with {:?}",
response.err().unwrap()
);
let _obj: serde_json::Value = serde_json::from_str(&response.unwrap()).unwrap();
let name = _obj["name"].as_str().unwrap();
let version = _obj["_version"].as_i64().unwrap();
println!("version 1 Name: {}, Version: {}", name, version);
assert_eq!(name, "updated from rust");
let query = GetDocumentVersionRequest {
collectionname: "entities".to_string(),
id: _id.to_string(),
version: -1,
..Default::default()
};
let response = client.get_document_version(query).await;
assert!(
response.is_ok(),
"test_get_document_version failed with {:?}",
response.err().unwrap()
);
let _obj: serde_json::Value = serde_json::from_str(&response.unwrap()).unwrap();
let name = _obj["name"].as_str().unwrap();
let version = _obj["_version"].as_i64().unwrap();
println!("version -1 Name: {}, Version: {}", name, version);
assert_eq!(name, "updated from rust");
Ok(())
}
Sourcepub async fn aggregate(
&self,
config: AggregateRequest,
) -> Result<AggregateResponse, OpenIAPError>
pub async fn aggregate( &self, config: AggregateRequest, ) -> Result<AggregateResponse, OpenIAPError>
Run an aggregate pipeline towards the database Example of running an aggregate pipeline on the entities collection, counting the number of documents with _type=test, and grouping them by name:
use openiap_client::{OpenIAPError, Client, AggregateRequest};
#[tokio::main]
async fn main() -> Result<(), OpenIAPError> {
let client = Client::new_connect("").await?;
let config = AggregateRequest {
collectionname: "entities".to_string(),
aggregates: "[{\"$match\": {\"_type\": \"test\"}}, {\"$group\": {\"_id\": \"$name\", \"count\": {\"$sum\": 1}}}]".to_string(),
..Default::default()
};
let response = client.aggregate(config).await?;
println!("Response: {:?}", response);
Ok(())
}
Sourcepub async fn count(
&self,
config: CountRequest,
) -> Result<CountResponse, OpenIAPError>
pub async fn count( &self, config: CountRequest, ) -> Result<CountResponse, OpenIAPError>
Count the number of documents in a collection, with an optional query
Sourcepub async fn distinct(
&self,
config: DistinctRequest,
) -> Result<DistinctResponse, OpenIAPError>
pub async fn distinct( &self, config: DistinctRequest, ) -> Result<DistinctResponse, OpenIAPError>
Get distinct values for a field in a collection, with an optional query
Sourcepub async fn insert_one(
&self,
config: InsertOneRequest,
) -> Result<InsertOneResponse, OpenIAPError>
pub async fn insert_one( &self, config: InsertOneRequest, ) -> Result<InsertOneResponse, OpenIAPError>
Insert a document into a collection
Sourcepub async fn insert_many(
&self,
config: InsertManyRequest,
) -> Result<InsertManyResponse, OpenIAPError>
pub async fn insert_many( &self, config: InsertManyRequest, ) -> Result<InsertManyResponse, OpenIAPError>
Insert many documents into a collection
Sourcepub async fn update_one(
&self,
config: UpdateOneRequest,
) -> Result<UpdateOneResponse, OpenIAPError>
pub async fn update_one( &self, config: UpdateOneRequest, ) -> Result<UpdateOneResponse, OpenIAPError>
Update ( replace ) a document in a collection
Sourcepub async fn insert_or_update_one(
&self,
config: InsertOrUpdateOneRequest,
) -> Result<String, OpenIAPError>
pub async fn insert_or_update_one( &self, config: InsertOrUpdateOneRequest, ) -> Result<String, OpenIAPError>
Using a unique key, insert a document or update it if it already exists ( upsert on steroids )
Sourcepub async fn insert_or_update_many(
&self,
config: InsertOrUpdateManyRequest,
) -> Result<InsertOrUpdateManyResponse, OpenIAPError>
pub async fn insert_or_update_many( &self, config: InsertOrUpdateManyRequest, ) -> Result<InsertOrUpdateManyResponse, OpenIAPError>
Using a unique key, insert many documents or update them if they already exist ( upsert on steroids )
Sourcepub async fn update_document(
&self,
config: UpdateDocumentRequest,
) -> Result<UpdateDocumentResponse, OpenIAPError>
pub async fn update_document( &self, config: UpdateDocumentRequest, ) -> Result<UpdateDocumentResponse, OpenIAPError>
Update one or more documents in a collection using a update document
Sourcepub async fn delete_one(
&self,
config: DeleteOneRequest,
) -> Result<i32, OpenIAPError>
pub async fn delete_one( &self, config: DeleteOneRequest, ) -> Result<i32, OpenIAPError>
Delete a document from a collection using a unique key
Sourcepub async fn delete_many(
&self,
config: DeleteManyRequest,
) -> Result<i32, OpenIAPError>
pub async fn delete_many( &self, config: DeleteManyRequest, ) -> Result<i32, OpenIAPError>
Delete many documents from a collection using a query or list of unique keys
Sourcepub async fn download(
&self,
config: DownloadRequest,
folder: Option<&str>,
filename: Option<&str>,
) -> Result<DownloadResponse, OpenIAPError>
pub async fn download( &self, config: DownloadRequest, folder: Option<&str>, filename: Option<&str>, ) -> Result<DownloadResponse, OpenIAPError>
Download a file from the database
Sourcepub async fn upload(
&self,
config: UploadRequest,
filepath: &str,
) -> Result<UploadResponse, OpenIAPError>
pub async fn upload( &self, config: UploadRequest, filepath: &str, ) -> Result<UploadResponse, OpenIAPError>
Upload a file to the database
Sourcepub async fn watch(
&self,
config: WatchRequest,
callback: Box<dyn Fn(WatchEvent) + Send + Sync>,
) -> Result<String, OpenIAPError>
pub async fn watch( &self, config: WatchRequest, callback: Box<dyn Fn(WatchEvent) + Send + Sync>, ) -> Result<String, OpenIAPError>
Watch for changes in a collection ( change stream )
Sourcepub async fn unwatch(&self, id: &str) -> Result<(), OpenIAPError>
pub async fn unwatch(&self, id: &str) -> Result<(), OpenIAPError>
Cancel a watch ( change stream )
Sourcepub async fn register_queue(
&self,
config: RegisterQueueRequest,
callback: Arc<dyn Fn(Arc<Client>, QueueEvent) -> BoxFuture<'static, Option<String>> + Send + Sync>,
) -> Result<String, OpenIAPError>
pub async fn register_queue( &self, config: RegisterQueueRequest, callback: Arc<dyn Fn(Arc<Client>, QueueEvent) -> BoxFuture<'static, Option<String>> + Send + Sync>, ) -> Result<String, OpenIAPError>
Register a queue for messaging ( amqp ) in the OpenIAP service
Sourcepub async fn unregister_queue(
&self,
queuename: &str,
) -> Result<(), OpenIAPError>
pub async fn unregister_queue( &self, queuename: &str, ) -> Result<(), OpenIAPError>
Unregister a queue or exchange for messaging ( amqp ) in the OpenIAP service
Sourcepub async fn register_exchange(
&self,
config: RegisterExchangeRequest,
callback: Arc<dyn Fn(Arc<Client>, QueueEvent) -> BoxFuture<'static, Option<String>> + Send + Sync>,
) -> Result<String, OpenIAPError>
pub async fn register_exchange( &self, config: RegisterExchangeRequest, callback: Arc<dyn Fn(Arc<Client>, QueueEvent) -> BoxFuture<'static, Option<String>> + Send + Sync>, ) -> Result<String, OpenIAPError>
Register a exchange for messaging ( amqp ) in the OpenIAP service
Sourcepub async fn queue_message(
&self,
config: QueueMessageRequest,
) -> Result<QueueMessageResponse, OpenIAPError>
pub async fn queue_message( &self, config: QueueMessageRequest, ) -> Result<QueueMessageResponse, OpenIAPError>
Send a message to a queue or exchange in the OpenIAP service
Sourcepub async fn rpc(
&self,
config: QueueMessageRequest,
timeout: Duration,
) -> Result<String, OpenIAPError>
pub async fn rpc( &self, config: QueueMessageRequest, timeout: Duration, ) -> Result<String, OpenIAPError>
Send message to a queue or exchange in the OpenIAP service, and wait for a reply
Sourcepub async fn push_workitem(
&self,
config: PushWorkitemRequest,
) -> Result<PushWorkitemResponse, OpenIAPError>
pub async fn push_workitem( &self, config: PushWorkitemRequest, ) -> Result<PushWorkitemResponse, OpenIAPError>
Push a new workitem to a workitem queue If the file is less than 5 megabytes it will be attached to the workitem If the file is larger than 5 megabytes it will be uploaded to the database and attached to the workitem
Sourcepub async fn push_workitems(
&self,
config: PushWorkitemsRequest,
) -> Result<PushWorkitemsResponse, OpenIAPError>
pub async fn push_workitems( &self, config: PushWorkitemsRequest, ) -> Result<PushWorkitemsResponse, OpenIAPError>
Push multiple workitems to a workitem queue If the file is less than 5 megabytes it will be attached to the workitem If the file is larger than 5 megabytes it will be uploaded to the database and attached to the workitem
Sourcepub async fn pop_workitem(
&self,
config: PopWorkitemRequest,
downloadfolder: Option<&str>,
) -> Result<PopWorkitemResponse, OpenIAPError>
pub async fn pop_workitem( &self, config: PopWorkitemRequest, downloadfolder: Option<&str>, ) -> Result<PopWorkitemResponse, OpenIAPError>
Pop a workitem from a workitem queue, return None if no workitem is available Any files attached to the workitem will be downloaded to the downloadfolder ( default “.” )
Sourcepub async fn update_workitem(
&self,
config: UpdateWorkitemRequest,
) -> Result<UpdateWorkitemResponse, OpenIAPError>
pub async fn update_workitem( &self, config: UpdateWorkitemRequest, ) -> Result<UpdateWorkitemResponse, OpenIAPError>
Update a workitem in a workitem queue If the file is less than 5 megabytes it will be attached to the workitem If the file is larger than 5 megabytes it will be uploaded to the database and attached to the workitem If a fileid is provided it will be used to update the file if a filename is provided without the id, it will be deleted
Sourcepub async fn delete_workitem(
&self,
config: DeleteWorkitemRequest,
) -> Result<DeleteWorkitemResponse, OpenIAPError>
pub async fn delete_workitem( &self, config: DeleteWorkitemRequest, ) -> Result<DeleteWorkitemResponse, OpenIAPError>
Delete a workitem from a workitem queue
Sourcepub async fn add_workitem_queue(
&self,
config: AddWorkItemQueueRequest,
) -> Result<WorkItemQueue, OpenIAPError>
pub async fn add_workitem_queue( &self, config: AddWorkItemQueueRequest, ) -> Result<WorkItemQueue, OpenIAPError>
Add a workitem queue to openiap instance
Sourcepub async fn update_workitem_queue(
&self,
config: UpdateWorkItemQueueRequest,
) -> Result<WorkItemQueue, OpenIAPError>
pub async fn update_workitem_queue( &self, config: UpdateWorkItemQueueRequest, ) -> Result<WorkItemQueue, OpenIAPError>
Update a workitem queue in openiap instance
Sourcepub async fn delete_workitem_queue(
&self,
config: DeleteWorkItemQueueRequest,
) -> Result<(), OpenIAPError>
pub async fn delete_workitem_queue( &self, config: DeleteWorkItemQueueRequest, ) -> Result<(), OpenIAPError>
Delete a workitem queue from openiap instance
Sourcepub async fn custom_command(
&self,
config: CustomCommandRequest,
timeout: Option<Duration>,
) -> Result<String, OpenIAPError>
pub async fn custom_command( &self, config: CustomCommandRequest, timeout: Option<Duration>, ) -> Result<String, OpenIAPError>
Run custom command on server. Custom commands are commands who is “on trail”, they may change and are not ready to be moved to the fixed protobuf format yet
Sourcepub async fn delete_package(&self, packageid: &str) -> Result<(), OpenIAPError>
pub async fn delete_package(&self, packageid: &str) -> Result<(), OpenIAPError>
Delete a package from the database, cleaning up all all files and data
Sourcepub async fn start_agent(&self, agentid: &str) -> Result<(), OpenIAPError>
pub async fn start_agent(&self, agentid: &str) -> Result<(), OpenIAPError>
Start Agent
Sourcepub async fn stop_agent(&self, agentid: &str) -> Result<(), OpenIAPError>
pub async fn stop_agent(&self, agentid: &str) -> Result<(), OpenIAPError>
Stop an agent, this will cleanup all resources and stop the agent
Sourcepub async fn delete_agent_pod(
&self,
agentid: &str,
podname: &str,
) -> Result<(), OpenIAPError>
pub async fn delete_agent_pod( &self, agentid: &str, podname: &str, ) -> Result<(), OpenIAPError>
Delete a pod from an agent, on kubernetes this will remove the pod and kubernetes will re-create it, on docker this will remove the pod. Then use start_agent to start the agent again
Sourcepub async fn delete_agent(&self, agentid: &str) -> Result<(), OpenIAPError>
pub async fn delete_agent(&self, agentid: &str) -> Result<(), OpenIAPError>
Delete an agent, this will cleanup all resources and delete the agent
Sourcepub async fn get_agent_pods(
&self,
agentid: &str,
stats: bool,
) -> Result<String, OpenIAPError>
pub async fn get_agent_pods( &self, agentid: &str, stats: bool, ) -> Result<String, OpenIAPError>
Get all pods associated with an agent, if stats is true, it will return memory and cpu usage for each pod
Sourcepub async fn get_agent_pod_logs(
&self,
agentid: &str,
podname: &str,
) -> Result<String, OpenIAPError>
pub async fn get_agent_pod_logs( &self, agentid: &str, podname: &str, ) -> Result<String, OpenIAPError>
Get logs from a pod associated with an agent, leave podname empty to get logs from all pods
Sourcepub async fn ensure_customer(
&self,
config: EnsureCustomerRequest,
) -> Result<EnsureCustomerResponse, OpenIAPError>
pub async fn ensure_customer( &self, config: EnsureCustomerRequest, ) -> Result<EnsureCustomerResponse, OpenIAPError>
Create/update a customer in the OpenIAP service. If stripe has been configured, it will create or update a customer in stripe as well A customer is a customer object that can only be updated using this function, and 2 roles ( customername admins and customername users )
Sourcepub async fn create_workflow_instance(
&self,
config: CreateWorkflowInstanceRequest,
) -> Result<String, OpenIAPError>
pub async fn create_workflow_instance( &self, config: CreateWorkflowInstanceRequest, ) -> Result<String, OpenIAPError>
Create a new workflow instance, to be used to workflow in/out nodes in NodeRED
Sourcepub async fn invoke_openrpa(
&self,
config: InvokeOpenRpaRequest,
timeout: Option<Duration>,
) -> Result<String, OpenIAPError>
pub async fn invoke_openrpa( &self, config: InvokeOpenRpaRequest, timeout: Option<Duration>, ) -> Result<String, OpenIAPError>
Invoke a workflow in the OpenRPA robot where robotid is the userid of the user the robot is running as, or a roleid with RPA enabled
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl !Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request