pub struct Client { /* private fields */ }Expand description
A client for Objectstore. Use Client::builder to configure and construct a Client.
To perform CRUD operations, one has to create a Client, and then scope it to a Usecase
and Scope in order to create a Session.
If your Objectstore instance enforces authorization checks, you must provide
authentication via ClientBuilder::token. It accepts anything that converts
into a TokenProvider:
TokenGenerator— for internal services that have access to an EdDSA keypair. The generator signs a fresh JWT for each request, scoped to the specific usecase and scope being accessed.String/&str— a pre-signed JWT, used as-is for every request. Use this for external services that receive a token from another source.
§Examples
Internal service with a keypair:
use std::time::Duration;
use objectstore_client::{Client, SecretKey, TokenGenerator, Usecase};
use objectstore_types::auth::Permission;
let token_generator = TokenGenerator::new(SecretKey {
secret_key: "<safely inject secret key>".into(),
kid: "my-service".into(),
})?
.expiry_seconds(30)
.permissions(&[Permission::ObjectRead]);
let client = Client::builder("http://localhost:8888/")
.timeout(Duration::from_secs(1))
.propagate_traces(true)
.token(token_generator)
.build()?;External service with a pre-signed JWT (obtained via
TokenGenerator::sign):
use objectstore_client::{Client, SecretKey, TokenGenerator, Usecase};
let scope = Usecase::new("my_app").for_project(42, 1337);
let token = TokenGenerator::new(SecretKey {
secret_key: "<private key>".into(),
kid: "my-service".into(),
})?.sign(&scope)?;
let client = Client::builder("http://localhost:8888/")
.token(token)
.build()?;Implementations§
Source§impl Client
impl Client
Sourcepub fn new(service_url: impl IntoUrl) -> Result<Client>
pub fn new(service_url: impl IntoUrl) -> Result<Client>
Creates a new Client, configured with the given service_url and default
configuration.
Use Client::builder for more fine-grained configuration.
§Errors
This method fails if ClientBuilder::build fails.
Sourcepub fn builder(service_url: impl IntoUrl) -> ClientBuilder
pub fn builder(service_url: impl IntoUrl) -> ClientBuilder
Convenience function to create a ClientBuilder.
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
Mutably borrows from an owned value. Read more