1use std::future::Future;
2use std::pin::Pin;
3
4use anyhow::Result;
5use gpui::AsyncApp;
6
7/// A provider for credentials.
8///
9/// Used to abstract over reading and writing credentials to some form of
10/// persistence (like the system keychain).
11pub trait CredentialsProvider: Send + Sync {
12 /// Reads the credentials from the provider.
13 fn read_credentials<'a>(
14 &'a self,
15 url: &'a str,
16 cx: &'a AsyncApp,
17 ) -> Pin<Box<dyn Future<Output = Result<Option<(String, Vec<u8>)>>> + 'a>>;
18
19 /// Writes the credentials to the provider.
20 fn write_credentials<'a>(
21 &'a self,
22 url: &'a str,
23 username: &'a str,
24 password: &'a [u8],
25 cx: &'a AsyncApp,
26 ) -> Pin<Box<dyn Future<Output = Result<()>> + 'a>>;
27
28 /// Deletes the credentials from the provider.
29 fn delete_credentials<'a>(
30 &'a self,
31 url: &'a str,
32 cx: &'a AsyncApp,
33 ) -> Pin<Box<dyn Future<Output = Result<()>> + 'a>>;
34}