From ed44ea00f8981cf54691c717fa1da943fa8047ba Mon Sep 17 00:00:00 2001 From: Scott Trinh Date: Tue, 29 Oct 2024 20:31:36 -0400 Subject: [PATCH] Move EmailProvider into main cfg Providers need to be set up per-instance to allow instance-wide fallback to a configured provider. --- edb/lib/cfg.edgeql | 73 ++++++++++++++++++++++++++++++++++++++ edb/lib/ext/auth.edgeql | 78 ----------------------------------------- 2 files changed, 73 insertions(+), 78 deletions(-) diff --git a/edb/lib/cfg.edgeql b/edb/lib/cfg.edgeql index 939913da5107..0c8a7e29d672 100644 --- a/edb/lib/cfg.edgeql +++ b/edb/lib/cfg.edgeql @@ -102,6 +102,71 @@ CREATE TYPE cfg::Auth EXTENDING cfg::ConfigObject { }; }; +CREATE SCALAR TYPE cfg::SMTPSecurity EXTENDING enum< + PlainText, + TLS, + STARTTLS, + STARTTLSOrPlainText, +>; + +CREATE ABSTRACT TYPE cfg::EmailProviderConfig EXTENDING cfg::ConfigObject { + CREATE REQUIRED PROPERTY name -> std::str { + CREATE CONSTRAINT std::exclusive; + CREATE ANNOTATION std::description := + "The name of the email provider."; + }; +}; + +CREATE TYPE cfg::SMTPProviderConfig EXTENDING cfg::EmailProviderConfig { + CREATE PROPERTY sender -> std::str { + CREATE ANNOTATION std::description := + "\"From\" address of system emails sent for e.g. \ + password reset, etc."; + }; + CREATE PROPERTY host -> std::str { + CREATE ANNOTATION std::description := + "Host of SMTP server to use for sending emails. \ + If not set, \"localhost\" will be used."; + }; + CREATE PROPERTY port -> std::int32 { + CREATE ANNOTATION std::description := + "Port of SMTP server to use for sending emails. \ + If not set, common defaults will be used depending on security: \ + 465 for TLS, 587 for STARTTLS, 25 otherwise."; + }; + CREATE PROPERTY username -> std::str { + CREATE ANNOTATION std::description := + "Username to login as after connected to SMTP server."; + }; + CREATE PROPERTY password -> std::str { + SET secret := true; + CREATE ANNOTATION std::description := + "Password for login after connected to SMTP server."; + }; + CREATE REQUIRED PROPERTY security -> ext::auth::SMTPSecurity { + SET default := ext::auth::SMTPSecurity.STARTTLSOrPlainText; + CREATE ANNOTATION std::description := + "Security mode of the connection to SMTP server. \ + By default, initiate a STARTTLS upgrade if supported by the \ + server, or fallback to PlainText."; + }; + CREATE REQUIRED PROPERTY validate_certs -> std::bool { + SET default := true; + CREATE ANNOTATION std::description := + "Determines if SMTP server certificates are validated."; + }; + CREATE REQUIRED PROPERTY timeout_per_email -> std::duration { + SET default := '60 seconds'; + CREATE ANNOTATION std::description := + "Maximum time to send an email, including retry attempts."; + }; + CREATE REQUIRED PROPERTY timeout_per_attempt -> std::duration { + SET default := '15 seconds'; + CREATE ANNOTATION std::description := + "Maximum time for each SMTP request."; + }; +}; + CREATE ABSTRACT TYPE cfg::AbstractConfig extending cfg::ConfigObject; CREATE ABSTRACT TYPE cfg::ExtensionConfig EXTENDING cfg::ConfigObject { @@ -158,6 +223,14 @@ ALTER TYPE cfg::AbstractConfig { CREATE ANNOTATION cfg::system := 'true'; }; + CREATE MULTI LINK email_providers -> cfg::EmailProviderConfig { + CREATE ANNOTATION cfg::system := 'true'; + }; + + CREATE PROPERTY current_email_provider_name -> std::str { + CREATE ANNOTATION cfg::system := 'true'; + }; + CREATE PROPERTY allow_dml_in_functions -> std::bool { SET default := false; CREATE ANNOTATION cfg::affects_compilation := 'true'; diff --git a/edb/lib/ext/auth.edgeql b/edb/lib/ext/auth.edgeql index ff459f7c118c..15656b5676c9 100644 --- a/edb/lib/ext/auth.edgeql +++ b/edb/lib/ext/auth.edgeql @@ -403,74 +403,6 @@ CREATE EXTENSION PACKAGE auth VERSION '1.0' { ); }; - create scalar type ext::auth::SMTPSecurity extending enum< - PlainText, - TLS, - STARTTLS, - STARTTLSOrPlainText, - >; - - create abstract type ext::auth::EmailProviderConfig extending - cfg::ConfigObject { - create required property name: std::str { - create constraint exclusive; - create annotation std::description := - "The name of the email provider."; - }; - - }; - - create type ext::auth::SMTPProviderConfig extending - ext::auth::EmailProviderConfig { - create property sender: std::str { - create annotation std::description := - "\"From\" address of system emails sent for e.g. \ - password reset, etc."; - }; - create property host: std::str { - create annotation std::description := - "Host of SMTP server to use for sending emails. \ - If not set, \"localhost\" will be used."; - }; - create property port: std::int32 { - create annotation std::description := - "Port of SMTP server to use for sending emails. \ - If not set, common defaults will be used depending on security: \ - 465 for TLS, 587 for STARTTLS, 25 otherwise."; - }; - create property username: std::str { - create annotation std::description := - "Username to login as after connected to SMTP server."; - }; - create property password: std::str { - set secret := true; - create annotation std::description := - "Password for login after connected to SMTP server."; - }; - create required property security: ext::auth::SMTPSecurity { - set default := ext::auth::SMTPSecurity.STARTTLSOrPlainText; - create annotation std::description := - "Security mode of the connection to SMTP server. \ - By default, initiate a STARTTLS upgrade if supported by the \ - server, or fallback to PlainText."; - }; - create required property validate_certs: std::bool { - set default := true; - create annotation std::description := - "Determines if SMTP server certificates are validated."; - }; - create required property timeout_per_email: std::duration { - set default := '60 seconds'; - create annotation std::description := - "Maximum time to send an email, including retry attempts."; - }; - create required property timeout_per_attempt: std::duration { - set default := '15 seconds'; - create annotation std::description := - "Maximum time for each SMTP request."; - }; - }; - create type ext::auth::AuthConfig extending cfg::ExtensionConfig { create multi link providers: ext::auth::ProviderConfig { create annotation std::description := @@ -488,16 +420,6 @@ CREATE EXTENSION PACKAGE auth VERSION '1.0' { "Configuration for webhooks."; }; - create multi link email_providers: ext::auth::EmailProviderConfig { - create annotation std::description := - "Configuration for available email providers."; - }; - - create property current_email_provider_name: std::str { - create annotation std::description := - "The name of the current email provider."; - }; - create property app_name: std::str { create annotation std::description := "The name of your application.";