| 138 | } |
| 139 | |
| 140 | async fn persist(&self) -> anyhow::Result<()> { |
| 141 | let Some(path) = self.filepath.as_ref() else { |
| 142 | return Ok(()); |
| 143 | }; |
| 144 | |
| 145 | if let Some(parent) = path.parent() { |
| 146 | tokio::fs::create_dir_all(parent).await?; |
| 147 | } |
| 148 | |
| 149 | let creds = self.credentials.read().await; |
| 150 | let json = serde_json::to_vec_pretty(&*creds)?; |
| 151 | tokio::fs::write(path, json).await?; |
| 152 | |
| 153 | #[cfg(unix)] |
| 154 | { |
| 155 | use std::os::unix::fs::PermissionsExt; |
| 156 | tokio::fs::set_permissions(path, std::fs::Permissions::from_mode(0o600)).await?; |
| 157 | } |
| 158 | |
| 159 | Ok(()) |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | impl Default for AuthManager { |