Skip to content

Commit f78f97b

Browse files
committed
feat(auth): rust client support for bearer auth
1 parent c75860f commit f78f97b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

clients/rust/src/client.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const USER_AGENT: &str = concat!("objectstore-client/", env!("CARGO_PKG_VERSION"
1515
struct ClientBuilderInner {
1616
service_url: Url,
1717
propagate_traces: bool,
18+
auth_token: Option<String>,
1819
reqwest_builder: reqwest::ClientBuilder,
1920
}
2021

@@ -67,10 +68,19 @@ impl ClientBuilder {
6768
Self(Ok(ClientBuilderInner {
6869
service_url,
6970
propagate_traces: false,
71+
auth_token: None,
7072
reqwest_builder,
7173
}))
7274
}
7375

76+
/// Sets the authorization token that will be used on each request to Objectstore.
77+
pub fn auth_token(mut self, auth_token: String) -> Self {
78+
if let Ok(ref mut inner) = self.0 {
79+
inner.auth_token = Some(auth_token);
80+
}
81+
self
82+
}
83+
7484
/// Changes whether the `sentry-trace` header will be sent to Objectstore
7585
/// to take advantage of Sentry's distributed tracing.
7686
///
@@ -123,6 +133,7 @@ impl ClientBuilder {
123133
reqwest: inner.reqwest_builder.build()?,
124134
service_url: inner.service_url,
125135
propagate_traces: inner.propagate_traces,
136+
auth_token: inner.auth_token,
126137
}),
127138
})
128139
}
@@ -340,6 +351,7 @@ pub(crate) struct ClientInner {
340351
reqwest: reqwest::Client,
341352
service_url: Url,
342353
propagate_traces: bool,
354+
auth_token: Option<String>,
343355
}
344356

345357
/// A client for Objectstore. Use [`Client::builder`] to configure and construct a Client.
@@ -448,6 +460,10 @@ impl Session {
448460

449461
let mut builder = self.client.reqwest.request(method, url);
450462

463+
if let Some(auth_token) = &self.client.auth_token {
464+
builder = builder.bearer_auth(auth_token);
465+
}
466+
451467
if self.client.propagate_traces {
452468
let trace_headers =
453469
sentry_core::configure_scope(|scope| Some(scope.iter_trace_propagation_headers()));

0 commit comments

Comments
 (0)