objectstore_client/client.rs
1use std::io;
2use std::path::{Path, PathBuf};
3use std::sync::Arc;
4use std::time::Duration;
5
6use bytes::Bytes;
7use futures_util::stream::BoxStream;
8use objectstore_types::metadata::{Compression, ExpirationPolicy};
9use objectstore_types::scope;
10use objectstore_types::usecase::{InvalidUsecaseName, Usecase as UsecaseName};
11use reqwest::RequestBuilder;
12use url::Url;
13
14use crate::IntoTokenProvider;
15use crate::auth::{TokenProvider, TokenRequest};
16
17const USER_AGENT: &str = concat!("objectstore-client/", env!("CARGO_PKG_VERSION"));
18
19#[derive(Debug)]
20struct ClientBuilderInner {
21 service_url: Url,
22 propagate_traces: bool,
23 reqwest_builder: reqwest::ClientBuilder,
24 token: Option<TokenProvider>,
25 spool_dir: Option<PathBuf>,
26}
27
28impl ClientBuilderInner {
29 /// Applies defaults that cannot be overridden by the caller.
30 fn apply_defaults(mut self) -> Self {
31 self.reqwest_builder = self
32 .reqwest_builder
33 // hickory-dns: Controlled by the `reqwest/hickory-dns` feature flag
34 // we are dealing with de/compression ourselves:
35 .no_brotli()
36 .no_deflate()
37 .no_gzip()
38 .no_zstd();
39 self
40 }
41}
42
43/// Builder to create a [`Client`].
44#[must_use = "call .build() on this ClientBuilder to create a Client"]
45#[derive(Debug)]
46pub struct ClientBuilder(crate::Result<ClientBuilderInner>);
47
48impl ClientBuilder {
49 /// Creates a new [`ClientBuilder`], configured with the given `service_url`.
50 ///
51 /// To perform CRUD operations, one has to create a [`Client`], and then scope it to a [`Usecase`]
52 /// and Scope in order to create a [`Session`].
53 pub fn new(service_url: impl reqwest::IntoUrl) -> Self {
54 let service_url = match service_url.into_url() {
55 Ok(url) => url,
56 Err(err) => return Self(Err(err.into())),
57 };
58 if service_url.cannot_be_a_base() {
59 return ClientBuilder(Err(crate::Error::InvalidUrl {
60 message: "service_url cannot be a base".to_owned(),
61 }));
62 }
63
64 let reqwest_builder = reqwest::Client::builder()
65 // We define just a connection timeout by default but do not limit reads. A connect
66 // timeout of 100ms is still very conservative, but should provide a sensible upper
67 // bound to expected request latencies.
68 .connect_timeout(Duration::from_millis(100))
69 .user_agent(USER_AGENT);
70
71 Self(Ok(ClientBuilderInner {
72 service_url,
73 propagate_traces: false,
74 reqwest_builder,
75 token: None,
76 spool_dir: None,
77 }))
78 }
79
80 /// Changes whether the `sentry-trace` header will be sent to Objectstore
81 /// to take advantage of Sentry's distributed tracing.
82 ///
83 /// By default, tracing headers will not be propagated.
84 pub fn propagate_traces(mut self, propagate_traces: bool) -> Self {
85 if let Ok(ref mut inner) = self.0 {
86 inner.propagate_traces = propagate_traces;
87 }
88 self
89 }
90
91 /// Defines a read timeout for the [`reqwest::Client`].
92 ///
93 /// The read timeout is defined to be "between consecutive read operations", for example between
94 /// chunks of a streaming response. For more fine-grained configuration of this and other
95 /// timeouts, use [`Self::configure_reqwest`].
96 ///
97 /// By default, no read timeout and a connect timeout of 100ms is set.
98 pub fn timeout(self, timeout: Duration) -> Self {
99 let Ok(mut inner) = self.0 else { return self };
100 inner.reqwest_builder = inner.reqwest_builder.read_timeout(timeout);
101 Self(Ok(inner))
102 }
103
104 /// Calls the closure with the underlying [`reqwest::ClientBuilder`].
105 ///
106 /// By default, the ClientBuilder is configured to create a reqwest Client with a connect and read timeout of 500ms and a user agent identifying this library.
107 pub fn configure_reqwest<F>(self, closure: F) -> Self
108 where
109 F: FnOnce(reqwest::ClientBuilder) -> reqwest::ClientBuilder,
110 {
111 let Ok(mut inner) = self.0 else { return self };
112 inner.reqwest_builder = closure(inner.reqwest_builder);
113 Self(Ok(inner))
114 }
115
116 /// Sets the authentication token to use for requests to Objectstore.
117 ///
118 /// Accepts anything that implements [`IntoTokenProvider`]:
119 /// - A [`TokenGenerator`](crate::TokenGenerator) — for internal services that have access to
120 /// an EdDSA keypair. The generator signs a fresh JWT for each request.
121 /// - A `String` or `&str` — a pre-signed JWT, used as-is for every request.
122 /// - An `Option` of any of the above — a `None` leaves the client unauthenticated, which is
123 /// convenient when authentication is configured conditionally.
124 pub fn token(self, token: impl IntoTokenProvider) -> Self {
125 let Ok(mut inner) = self.0 else { return self };
126 inner.token = token.into_token_provider();
127 Self(Ok(inner))
128 }
129
130 /// Sets the directory for temporary files used to prepare compressed resumable uploads.
131 ///
132 /// By default, the system temporary directory is used. The directory must already exist.
133 /// If a temporary file cannot be created, uploads fall back to direct streaming.
134 /// Temporary storage may outlive the upload while HTTP readers remain open.
135 pub fn spool_dir(self, path: impl Into<PathBuf>) -> Self {
136 let Ok(mut inner) = self.0 else { return self };
137 inner.spool_dir = Some(path.into());
138 Self(Ok(inner))
139 }
140
141 /// Returns a [`Client`] that uses this [`ClientBuilder`] configuration.
142 ///
143 /// # Errors
144 ///
145 /// This method fails if:
146 /// - the given `service_url` is invalid or cannot be used as a base URL
147 /// - the [`reqwest::Client`] fails to build. Refer to [`reqwest::ClientBuilder::build`] for
148 /// more information on when this can happen.
149 pub fn build(self) -> crate::Result<Client> {
150 let inner = self.0?.apply_defaults();
151
152 Ok(Client {
153 inner: Arc::new(ClientInner {
154 reqwest: inner.reqwest_builder.build()?,
155 service_url: inner.service_url,
156 propagate_traces: inner.propagate_traces,
157 token: inner.token,
158 spool_dir: inner.spool_dir,
159 }),
160 })
161 }
162}
163
164/// An identifier for a workload in Objectstore, along with defaults to use for all
165/// operations within that Usecase.
166///
167/// Usecases need to be statically defined in Objectstore's configuration server-side.
168/// Objectstore can make decisions based on the Usecase. For example, choosing the most
169/// suitable storage backend.
170///
171/// Names must be 3–64 ASCII characters from `[A-Za-z0-9_-]`. Any permitted
172/// character may appear in any position. Names are case-sensitive and are never
173/// normalized.
174#[derive(Debug, Clone)]
175pub struct Usecase {
176 name: UsecaseName,
177 compression: Option<Compression>,
178 expiration_policy: ExpirationPolicy,
179 resumable_threshold_bytes: Option<u64>,
180}
181
182impl Usecase {
183 /// Creates a Usecase, returning an error if the name is invalid.
184 ///
185 /// Use [`Self::from_static`] for statically defined names.
186 ///
187 /// # Errors
188 ///
189 /// Returns [`InvalidUsecaseName`] if the name violates the naming rules on
190 /// [`Usecase`].
191 pub fn new(name: &str) -> Result<Self, InvalidUsecaseName> {
192 Ok(Self::with_name(UsecaseName::new(name)?))
193 }
194
195 /// Creates a Usecase for a statically defined name.
196 ///
197 /// Use [`Self::new`] for dynamic names. The result can initialize a `static`:
198 ///
199 /// ```
200 /// use objectstore_client::Usecase;
201 ///
202 /// static ATTACHMENTS: Usecase = Usecase::from_static("attachments");
203 /// assert_eq!(ATTACHMENTS.name(), "attachments");
204 /// ```
205 ///
206 /// # Panics
207 ///
208 /// Panics if the name violates the naming rules on [`Usecase`]. In a const
209 /// context, this panic is reported as a compile error.
210 #[track_caller]
211 pub const fn from_static(name: &'static str) -> Self {
212 Self::with_name(UsecaseName::from_static(name))
213 }
214
215 /// Creates a Usecase with the default compression and expiration policy.
216 const fn with_name(name: UsecaseName) -> Self {
217 Self {
218 name,
219 compression: Some(Compression::Zstd),
220 // `ExpirationPolicy::default()` isn't callable in a const fn.
221 expiration_policy: ExpirationPolicy::Manual,
222 resumable_threshold_bytes: Some(256 * 1024 * 1024),
223 }
224 }
225
226 /// Returns the name of this usecase.
227 #[inline]
228 pub fn name(&self) -> &str {
229 self.name.as_str()
230 }
231
232 /// Returns the compression algorithm to use for operations within this usecase.
233 #[inline]
234 pub fn compression(&self) -> Option<Compression> {
235 self.compression
236 }
237
238 /// Sets the compression algorithm to use for operations within this usecase.
239 ///
240 /// It's still possible to override this default on each operation's builder.
241 ///
242 /// By default, [`Compression::Zstd`] is used. Pass [`None`] to disable compression.
243 pub fn with_compression(self, compression: impl Into<Option<Compression>>) -> Self {
244 Self {
245 compression: compression.into(),
246 ..self
247 }
248 }
249
250 /// Returns the expiration policy to use by default for operations within this usecase.
251 #[inline]
252 pub fn expiration_policy(&self) -> ExpirationPolicy {
253 self.expiration_policy
254 }
255
256 /// Sets the expiration policy to use for operations within this usecase.
257 ///
258 /// It's still possible to override this default on each operation's builder.
259 ///
260 /// By default, [`ExpirationPolicy::Manual`] is used, meaning that objects won't automatically
261 /// expire.
262 pub fn with_expiration_policy(self, expiration_policy: ExpirationPolicy) -> Self {
263 Self {
264 expiration_policy,
265 ..self
266 }
267 }
268
269 /// Returns the automatic resumable upload threshold, or [`None`] if disabled.
270 pub fn resumable_threshold_bytes(&self) -> Option<u64> {
271 self.resumable_threshold_bytes
272 }
273
274 /// Sets the minimum remaining input size for automatic resumable uploads.
275 ///
276 /// Defaults to 256 MiB, measured before client compression. Pass [`None`] to disable or
277 /// zero to include every supported payload. Individual uploads can override this using
278 /// [`crate::PutBuilder::resumable_threshold_bytes`]. See [`crate::PutBuilder`] for eligibility.
279 pub fn with_resumable_threshold_bytes(mut self, threshold: impl Into<Option<u64>>) -> Self {
280 self.resumable_threshold_bytes = threshold.into();
281 self
282 }
283
284 /// Creates a new custom [`Scope`].
285 ///
286 /// Add parts to it using [`Scope::push`].
287 ///
288 /// Generally, [`Usecase::for_organization`] and [`Usecase::for_project`] should fit most usecases,
289 /// so prefer using those methods rather than creating your own custom [`Scope`].
290 pub fn scope(&self) -> Scope {
291 Scope::new(self.clone())
292 }
293
294 /// Creates a new [`Scope`] tied to the given organization.
295 pub fn for_organization(&self, organization: u64) -> Scope {
296 Scope::for_organization(self.clone(), organization)
297 }
298
299 /// Creates a new [`Scope`] tied to the given organization and project.
300 pub fn for_project(&self, organization: u64, project: u64) -> Scope {
301 Scope::for_project(self.clone(), organization, project)
302 }
303}
304
305#[derive(Debug)]
306pub(crate) struct ScopeInner {
307 usecase: Usecase,
308 scopes: scope::Scopes,
309}
310
311impl ScopeInner {
312 #[inline]
313 pub(crate) fn usecase(&self) -> &Usecase {
314 &self.usecase
315 }
316
317 #[inline]
318 pub(crate) fn scopes(&self) -> &scope::Scopes {
319 &self.scopes
320 }
321}
322
323/// A [`Scope`] is a sequence of key-value pairs that defines a (possibly nested) namespace within a
324/// [`Usecase`].
325///
326/// To construct a [`Scope`], use [`Usecase::for_organization`], [`Usecase::for_project`], or
327/// [`Usecase::scope`] for custom scopes.
328#[derive(Debug)]
329pub struct Scope(pub(crate) crate::Result<ScopeInner>);
330
331impl Scope {
332 /// Creates a new root-level Scope for the given usecase.
333 ///
334 /// Using a custom Scope is discouraged, prefer using [`Usecase::for_organization`] or [`Usecase::for_project`] instead.
335 pub fn new(usecase: Usecase) -> Self {
336 Self(Ok(ScopeInner {
337 usecase,
338 scopes: scope::Scopes::empty(),
339 }))
340 }
341
342 fn for_organization(usecase: Usecase, organization: u64) -> Self {
343 Self::new(usecase).push("org", organization)
344 }
345
346 fn for_project(usecase: Usecase, organization: u64, project: u64) -> Self {
347 Self::for_organization(usecase, organization).push("project", project)
348 }
349
350 /// Extends this Scope by creating a new sub-scope nested within it.
351 pub fn push<V>(self, key: &str, value: V) -> Self
352 where
353 V: std::fmt::Display,
354 {
355 let result = self.0.and_then(|mut inner| {
356 inner.scopes.push(key, value)?;
357 Ok(inner)
358 });
359
360 Self(result)
361 }
362
363 /// Creates a session for this scope using the given client.
364 ///
365 /// # Errors
366 ///
367 /// Returns an error if the scope is invalid (e.g. it contains invalid characters).
368 pub fn session(self, client: &Client) -> crate::Result<Session> {
369 client.session(self)
370 }
371}
372
373#[derive(Debug)]
374pub(crate) struct ClientInner {
375 spool_dir: Option<PathBuf>,
376 reqwest: reqwest::Client,
377 service_url: Url,
378 propagate_traces: bool,
379 token: Option<TokenProvider>,
380}
381
382impl ClientInner {
383 pub fn spool_dir(&self) -> Option<&Path> {
384 self.spool_dir.as_deref()
385 }
386}
387
388/// A client for Objectstore. Use [`Client::builder`] to configure and construct a Client.
389///
390/// To perform CRUD operations, one has to create a Client, and then scope it to a [`Usecase`]
391/// and Scope in order to create a [`Session`].
392///
393/// If your Objectstore instance enforces authorization checks, you must provide
394/// authentication via [`ClientBuilder::token`]. It accepts anything that converts
395/// into a [`TokenProvider`]:
396///
397/// - **[`TokenGenerator`](crate::TokenGenerator)** — for internal services that have access to
398/// an EdDSA keypair. The generator signs a fresh JWT for each request, scoped to the
399/// specific usecase and scope being accessed.
400/// - **`String` / `&str`** — a pre-signed JWT, used as-is for every request.
401/// Use this for external services that receive a token from another source.
402///
403/// # Examples
404///
405/// Internal service with a keypair:
406///
407/// ```no_run
408/// use std::time::Duration;
409/// use objectstore_client::{Client, SecretKey, TokenGenerator, Usecase};
410/// use objectstore_types::auth::Permission;
411///
412/// # async fn example() -> objectstore_client::Result<()> {
413/// let token_generator = TokenGenerator::new(SecretKey {
414/// secret_key: "<safely inject secret key>".into(),
415/// kid: "my-service".into(),
416/// })?
417/// .expiry_seconds(30)
418/// .permissions(&[Permission::ObjectRead]);
419///
420/// let client = Client::builder("http://localhost:8888/")
421/// .timeout(Duration::from_secs(1))
422/// .propagate_traces(true)
423/// .token(token_generator)
424/// .build()?;
425/// # Ok(())
426/// # }
427/// ```
428///
429/// External service with a pre-signed JWT (obtained via
430/// [`TokenGenerator::create_token`](crate::TokenGenerator::create_token)):
431///
432/// ```no_run
433/// use objectstore_client::{Client, SecretKey, TokenGenerator, Usecase};
434///
435/// # fn example() -> objectstore_client::Result<()> {
436/// let scope = Usecase::from_static("my_app").for_project(42, 1337);
437/// let token = TokenGenerator::new(SecretKey {
438/// secret_key: "<private key>".into(),
439/// kid: "my-service".into(),
440/// })?.create_token(&scope).sign()?;
441///
442/// let client = Client::builder("http://localhost:8888/")
443/// .token(token)
444/// .build()?;
445/// # Ok(())
446/// # }
447/// ```
448///
449/// Optional authentication — pass an `Option` straight through, leaving the client
450/// unauthenticated when it is `None`:
451///
452/// ```no_run
453/// use objectstore_client::Client;
454///
455/// # fn example() -> objectstore_client::Result<()> {
456/// // Authenticate only if a token is present in the environment.
457/// let token_opt = std::env::var("OBJECTSTORE_TOKEN").ok();
458///
459/// let client = Client::builder("http://localhost:8888/")
460/// .token(token_opt)
461/// .build()?;
462/// # Ok(())
463/// # }
464/// ```
465#[derive(Debug, Clone)]
466pub struct Client {
467 inner: Arc<ClientInner>,
468}
469
470impl Client {
471 /// Creates a new [`Client`], configured with the given `service_url` and default
472 /// configuration.
473 ///
474 /// Use [`Client::builder`] for more fine-grained configuration.
475 ///
476 /// # Errors
477 ///
478 /// This method fails if [`ClientBuilder::build`] fails.
479 pub fn new(service_url: impl reqwest::IntoUrl) -> crate::Result<Client> {
480 ClientBuilder::new(service_url).build()
481 }
482
483 /// Convenience function to create a [`ClientBuilder`].
484 pub fn builder(service_url: impl reqwest::IntoUrl) -> ClientBuilder {
485 ClientBuilder::new(service_url)
486 }
487
488 /// Returns the configured spool directory.
489 ///
490 /// `None` means the system temporary directory is used.
491 pub fn spool_dir(&self) -> Option<&Path> {
492 self.inner.spool_dir()
493 }
494
495 /// Creates a session for the given scope using this client.
496 ///
497 /// # Errors
498 ///
499 /// Returns an error if the scope is invalid (e.g. it contains invalid characters).
500 pub fn session(&self, scope: Scope) -> crate::Result<Session> {
501 scope.0.map(|inner| Session {
502 scope: inner.into(),
503 client: self.inner.clone(),
504 })
505 }
506}
507
508/// Represents a session with Objectstore, tied to a specific Usecase and Scope within it.
509///
510/// Create a Session using [`Client::session`] or [`Scope::session`].
511#[derive(Debug, Clone)]
512pub struct Session {
513 pub(crate) scope: Arc<ScopeInner>,
514 pub(crate) client: Arc<ClientInner>,
515}
516
517/// The type of [`Stream`](futures_util::Stream) to be used for a PUT request.
518pub type ClientStream = BoxStream<'static, io::Result<Bytes>>;
519
520impl Session {
521 /// Generates a GET url to the object with the given `key`.
522 ///
523 /// This can then be used by downstream services to fetch the given object.
524 /// NOTE however that the service does not strictly follow HTTP semantics,
525 /// in particular in relation to `Accept-Encoding`.
526 pub fn object_url(&self, object_key: &str) -> Url {
527 let mut url = self.client.service_url.clone();
528
529 // `path_segments_mut` can only error if the url is cannot-be-a-base,
530 // and we check that in `ClientBuilder::new`, therefore this will never panic.
531 let mut segments = url.path_segments_mut().unwrap();
532 segments
533 .push("v1")
534 .push("objects")
535 .push(self.scope.usecase.name())
536 .push(&self.scope.scopes.as_api_path().to_string())
537 .extend(object_key.split('/'));
538 drop(segments);
539
540 url
541 }
542
543 /// Returns a token authorizing access to this session's scope.
544 ///
545 /// With a [`TokenGenerator`](crate::TokenGenerator), each call signs a fresh token whose expiry
546 /// starts now, using the configured permissions; use [`create_token`](Self::create_token) to
547 /// narrow either.
548 ///
549 /// If a pre-signed token was used to construct the client, it is returned verbatim, including
550 /// its original expiry.
551 ///
552 /// Returns `None` if the client was constructed without authentication.
553 ///
554 /// # Errors
555 ///
556 /// Returns an error if a new token cannot be signed with the configured key. Retrieving a
557 /// pre-signed token never fails.
558 pub fn get_token(&self) -> crate::Result<Option<String>> {
559 match self.client.token {
560 Some(TokenProvider::Generator(ref generator)) => {
561 generator.request_inner(&self.scope).sign().map(Some)
562 }
563 Some(TokenProvider::Static(ref token)) => Ok(Some(token.clone())),
564 None => Ok(None),
565 }
566 }
567
568 /// Creates a new token with configurable permissions and expiry.
569 ///
570 /// Use this to produce a static token that can be handed to an external service
571 /// with lower permissions than the current session.
572 ///
573 /// # Errors
574 ///
575 /// This requires a [`TokenGenerator`](crate::TokenGenerator) to sign a new token.
576 /// If not available, this will result in an error. To retrieve a token with the current
577 /// session's default permissions and expiry, use [`get_token`](Self::get_token) instead.
578 pub fn create_token(&self) -> crate::Result<Option<TokenRequest<'_>>> {
579 match self.client.token {
580 Some(TokenProvider::Generator(ref generator)) => {
581 Ok(Some(generator.request_inner(&self.scope)))
582 }
583 Some(TokenProvider::Static(_)) => Err(crate::Error::StaticTokenOverride),
584 None => Ok(None),
585 }
586 }
587
588 fn batch_url(&self) -> Url {
589 let mut url = self.client.service_url.clone();
590
591 // `path_segments_mut` can only error if the url is cannot-be-a-base,
592 // and we check that in `ClientBuilder::new`, therefore this will never panic.
593 let mut segments = url.path_segments_mut().unwrap();
594 segments
595 .push("v1")
596 .push("objects:batch")
597 .push(self.scope.usecase().name())
598 .push(&self.scope.scopes.as_api_path().to_string())
599 .push(""); // trailing slash
600 drop(segments);
601
602 url
603 }
604
605 fn prepare_builder(&self, mut builder: RequestBuilder) -> crate::Result<RequestBuilder> {
606 if let Some(token) = self.get_token()? {
607 builder = builder.header("x-os-auth", format!("Bearer {token}"));
608 }
609 if self.client.propagate_traces {
610 let trace_headers =
611 sentry_core::configure_scope(|scope| Some(scope.iter_trace_propagation_headers()));
612 for (header_name, value) in trace_headers.into_iter().flatten() {
613 builder = builder.header(header_name, value);
614 }
615 }
616 Ok(builder)
617 }
618
619 pub(crate) fn request(
620 &self,
621 method: reqwest::Method,
622 object_key: &str,
623 ) -> crate::Result<RequestBuilder> {
624 let url = self.object_url(object_key);
625 let builder = self.client.reqwest.request(method, url);
626 self.prepare_builder(builder)
627 }
628
629 pub(crate) fn batch_request(&self) -> crate::Result<RequestBuilder> {
630 let url = self.batch_url();
631 let builder = self.client.reqwest.post(url);
632 self.prepare_builder(builder)
633 }
634}
635
636#[cfg(test)]
637mod tests {
638 use super::*;
639
640 #[test]
641 fn test_usecase_construction() {
642 let name = "Debug_Files-123";
643 assert_eq!(Usecase::from_static(name).name(), name);
644 assert_eq!(Usecase::new(name).unwrap().name(), name);
645 assert!(matches!(
646 Usecase::new("_"),
647 Err(InvalidUsecaseName::InvalidLength)
648 ));
649 assert!(matches!(
650 Usecase::new("testing/org=999/injected"),
651 Err(InvalidUsecaseName::InvalidChar(7))
652 ));
653 }
654
655 #[test]
656 fn test_usecase_from_static_const() {
657 const USECASE: Usecase = Usecase::from_static("testing");
658 assert_eq!(USECASE.name(), "testing");
659 assert_eq!(USECASE.compression(), Some(Compression::Zstd));
660 assert_eq!(USECASE.expiration_policy(), ExpirationPolicy::default());
661 }
662
663 #[test]
664 #[should_panic(expected = "invalid usecase name")]
665 fn test_invalid_usecase_panics() {
666 Usecase::from_static("testing/org=999/injected");
667 }
668
669 #[test]
670 fn test_object_url() {
671 let client = Client::new("http://127.0.0.1:8888/").unwrap();
672 let usecase = Usecase::from_static("testing");
673 let scope = usecase
674 .for_project(12345, 1337)
675 .push("app_slug", "email_app");
676 let session = client.session(scope).unwrap();
677
678 assert_eq!(
679 session.object_url("foo/bar").to_string(),
680 "http://127.0.0.1:8888/v1/objects/testing/org=12345;project=1337;app_slug=email_app/foo/bar"
681 )
682 }
683
684 #[test]
685 fn test_object_url_with_base_path() {
686 let client = Client::new("http://127.0.0.1:8888/api/prefix").unwrap();
687 let usecase = Usecase::from_static("testing");
688 let scope = usecase.for_project(12345, 1337);
689 let session = client.session(scope).unwrap();
690
691 assert_eq!(
692 session.object_url("foo/bar").to_string(),
693 "http://127.0.0.1:8888/api/prefix/v1/objects/testing/org=12345;project=1337/foo/bar"
694 )
695 }
696}