Skip to content

Commit b2e0df3

Browse files
authored
Changed auth token in policies (#339)
1 parent cb5aba6 commit b2e0df3

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

sdk/core/src/pipeline.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ where
9595
self.http_client.as_ref()
9696
}
9797

98+
pub fn replace_policy(
99+
&mut self,
100+
policy: Arc<dyn Policy<C>>,
101+
position: usize,
102+
) -> Arc<dyn Policy<C>> {
103+
std::mem::replace(&mut self.pipeline[position], policy)
104+
}
105+
106+
pub fn policies(&self) -> &[Arc<dyn Policy<C>>] {
107+
&self.pipeline
108+
}
109+
98110
pub async fn send(
99111
&self,
100112
ctx: &mut PipelineContext<C>,

sdk/cosmos/src/clients/cosmos_client.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,16 @@ impl CosmosClient {
139139

140140
/// Set the auth token used
141141
pub fn auth_token(&mut self, auth_token: AuthorizationToken) {
142-
self.auth_token = auth_token;
142+
// TODO: To remove once everything uses the AutorizationPolicy
143+
self.auth_token = auth_token.clone();
144+
145+
// we replace the AuthorizationPolicy. This is
146+
// the last-1 policy by construction.
147+
let auth_policy: Arc<dyn azure_core::Policy<CosmosContext>> =
148+
Arc::new(crate::AuthorizationPolicy::new(auth_token));
149+
150+
self.pipeline
151+
.replace_policy(auth_policy, self.pipeline.policies().len() - 2);
143152
}
144153

145154
/// Create a database

0 commit comments

Comments
 (0)