MCPcopy Create free account
hub / github.com/clawshell/clawshell / save

Method save

src/oauth/storage.rs:33–49  ·  view source on GitHub ↗

Save tokens for a provider, creating the directory if needed.

(&self, provider_id: &str, tokens: &OAuthTokens)

Source from the content-addressed store, hash-verified

31
32 /// Save tokens for a provider, creating the directory if needed.
33 pub fn save(&self, provider_id: &str, tokens: &OAuthTokens) -> Result<(), std::io::Error> {
34 std::fs::create_dir_all(&self.dir)?;
35 let path = self.token_path(provider_id);
36 let content = serde_json::to_string_pretty(tokens)
37 .map_err(|e| std::io::Error::other(format!("failed to serialize tokens: {e}")))?;
38 std::fs::write(&path, content)?;
39
40 // Set file permissions to 0600 (owner read/write only)
41 #[cfg(unix)]
42 {
43 use std::os::unix::fs::PermissionsExt;
44 std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o600))?;
45 }
46
47 debug!(provider = %provider_id, path = %path.display(), "OAuth tokens saved");
48 Ok(())
49 }
50
51 /// Load tokens for a provider, returning None if the file doesn't exist.
52 pub fn load(&self, provider_id: &str) -> Result<Option<OAuthTokens>, std::io::Error> {

Callers 11

prepare_request_bodyMethod · 0.80
refreshMethod · 0.80
store_tokensMethod · 0.80
spawn_refresh_tasksMethod · 0.80
test_save_and_loadFunction · 0.80
test_removeFunction · 0.80
test_creates_directoryFunction · 0.80
test_file_permissionsFunction · 0.80
run_oauth_loginFunction · 0.80

Calls 1

token_pathMethod · 0.80

Tested by 6

test_save_and_loadFunction · 0.64
test_removeFunction · 0.64
test_creates_directoryFunction · 0.64
test_file_permissionsFunction · 0.64