couchbase_core/
authenticator.rs1use std::fmt::Debug;
20
21use crate::error::Result;
22use crate::service_type::ServiceType;
23
24#[derive(Debug, Clone, PartialEq, Hash)]
25#[non_exhaustive]
26pub enum Authenticator {
27 PasswordAuthenticator(PasswordAuthenticator),
28 CertificateAuthenticator(CertificateAuthenticator),
29}
30
31#[derive(Debug, Clone, PartialEq, Eq, Hash)]
32pub struct UserPassPair {
33 pub username: String,
34 pub password: String,
35}
36
37#[derive(Debug, Clone, PartialEq, Eq, Hash)]
38pub struct PasswordAuthenticator {
39 pub username: String,
40 pub password: String,
41}
42
43impl PasswordAuthenticator {
44 pub fn get_credentials(
45 &self,
46 _service_type: &ServiceType,
47 _host_port: String,
48 ) -> Result<UserPassPair> {
49 Ok(UserPassPair {
50 username: self.username.clone(),
51 password: self.password.clone(),
52 })
53 }
54}
55
56impl From<PasswordAuthenticator> for Authenticator {
57 fn from(value: PasswordAuthenticator) -> Self {
58 Authenticator::PasswordAuthenticator(value)
59 }
60}
61
62#[derive(Debug, Clone, PartialEq, Eq, Hash)]
64pub struct CertificateAuthenticator {}
65
66impl CertificateAuthenticator {
67 pub fn get_credentials(
68 &self,
69 _service_type: &ServiceType,
70 _host_port: String,
71 ) -> Result<UserPassPair> {
72 Ok(UserPassPair {
73 username: String::new(), password: String::new(), })
76 }
77}
78
79impl From<CertificateAuthenticator> for Authenticator {
80 fn from(value: CertificateAuthenticator) -> Self {
81 Authenticator::CertificateAuthenticator(value)
82 }
83}