Skip to content

Commit 88d0a55

Browse files
committed
fix: remove mutable references from login and set_token interfaces in RustyVault
1 parent ad84cf8 commit 88d0a55

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub const VERSION: &str = env!("CARGO_PKG_VERSION");
8585

8686
pub struct RustyVault {
8787
pub core: ArcSwap<Core>,
88-
pub token: String,
88+
pub token: ArcSwap<String>,
8989
}
9090

9191
#[maybe_async::maybe_async]
@@ -141,7 +141,7 @@ impl RustyVault {
141141
}
142142
}
143143

144-
Ok(Self { core: ArcSwap::new(core), token: String::new() })
144+
Ok(Self { core: ArcSwap::new(core), token: ArcSwap::new(Arc::new(String::new())) })
145145
}
146146

147147
pub fn init(&self, seal_config: &core::SealConfig) -> Result<core::InitResult, RvError> {
@@ -156,8 +156,8 @@ impl RustyVault {
156156
self.core.load().seal()
157157
}
158158

159-
pub fn set_token<S: Into<String>>(&mut self, token: S) {
160-
self.token = token.into();
159+
pub fn set_token<S: Into<String>>(&self, token: S) {
160+
self.token.store(Arc::new(token.into()));
161161
}
162162

163163
pub async fn mount(&self, path: &str, mount_type: &str) -> Result<Option<Response>, RvError> {
@@ -200,7 +200,7 @@ impl RustyVault {
200200
}
201201

202202
pub async fn login(
203-
&mut self,
203+
&self,
204204
path: &str,
205205
data: Option<Map<String, Value>>,
206206
) -> Result<(Option<Response>, bool), RvError> {
@@ -209,7 +209,7 @@ impl RustyVault {
209209
let resp = self.core.load().handle_request(&mut req).await?;
210210
if let Some(response) = resp.as_ref() {
211211
if let Some(auth) = response.auth.as_ref() {
212-
self.token = auth.client_token.clone();
212+
self.token.store(Arc::new(auth.client_token.clone()));
213213
login_success = true;
214214
}
215215
}
@@ -218,7 +218,7 @@ impl RustyVault {
218218
}
219219

220220
pub async fn request(&self, req: &mut Request) -> Result<Option<Response>, RvError> {
221-
req.client_token = self.token.to_string();
221+
req.client_token = self.token.load().as_ref().clone();
222222
self.core.load().handle_request(req).await
223223
}
224224

0 commit comments

Comments
 (0)