You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-11-20 12:02:22 +03:00
Remove dependency on mas-email and lettre in mas-config
This commit is contained in:
@@ -12,8 +12,12 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use mas_config::PasswordsConfig;
|
||||
use anyhow::Context;
|
||||
use mas_config::{EmailConfig, EmailSmtpMode, EmailTransportConfig, PasswordsConfig, PolicyConfig};
|
||||
use mas_email::{MailTransport, Mailer};
|
||||
use mas_handlers::passwords::PasswordManager;
|
||||
use mas_policy::PolicyFactory;
|
||||
use mas_templates::Templates;
|
||||
|
||||
pub async fn password_manager_from_config(
|
||||
config: &PasswordsConfig,
|
||||
@@ -35,3 +39,55 @@ pub async fn password_manager_from_config(
|
||||
|
||||
PasswordManager::new(schemes)
|
||||
}
|
||||
|
||||
pub async fn mailer_from_config(
|
||||
config: &EmailConfig,
|
||||
templates: &Templates,
|
||||
) -> Result<Mailer, anyhow::Error> {
|
||||
let from = config.from.parse()?;
|
||||
let reply_to = config.reply_to.parse()?;
|
||||
let transport = match &config.transport {
|
||||
EmailTransportConfig::Blackhole => MailTransport::blackhole(),
|
||||
EmailTransportConfig::Smtp {
|
||||
mode,
|
||||
hostname,
|
||||
credentials,
|
||||
port,
|
||||
} => {
|
||||
let credentials = credentials
|
||||
.clone()
|
||||
.map(|c| mas_email::SmtpCredentials::new(c.username, c.password));
|
||||
|
||||
let mode = match mode {
|
||||
EmailSmtpMode::Plain => mas_email::SmtpMode::Plain,
|
||||
EmailSmtpMode::StartTls => mas_email::SmtpMode::StartTls,
|
||||
EmailSmtpMode::Tls => mas_email::SmtpMode::Tls,
|
||||
};
|
||||
|
||||
MailTransport::smtp(mode, hostname, port.as_ref().copied(), credentials)
|
||||
.context("failed to build SMTP transport")?
|
||||
}
|
||||
EmailTransportConfig::Sendmail { command } => MailTransport::sendmail(command),
|
||||
EmailTransportConfig::AwsSes => MailTransport::aws_ses().await?,
|
||||
};
|
||||
|
||||
Ok(Mailer::new(templates.clone(), transport, from, reply_to))
|
||||
}
|
||||
|
||||
pub async fn policy_factory_from_config(
|
||||
config: &PolicyConfig,
|
||||
) -> Result<PolicyFactory, anyhow::Error> {
|
||||
let policy_file = tokio::fs::File::open(&config.wasm_module)
|
||||
.await
|
||||
.context("failed to open OPA WASM policy file")?;
|
||||
|
||||
PolicyFactory::load(
|
||||
policy_file,
|
||||
config.data.clone().unwrap_or_default(),
|
||||
config.register_entrypoint.clone(),
|
||||
config.client_registration_entrypoint.clone(),
|
||||
config.authorization_grant_entrypoint.clone(),
|
||||
)
|
||||
.await
|
||||
.context("failed to load the policy")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user