Skip to content

Commit

Permalink
Move EmailProvider into main cfg
Browse files Browse the repository at this point in the history
Providers need to be set up per-instance to allow instance-wide fallback
to a configured provider.
  • Loading branch information
scotttrinh committed Oct 30, 2024
1 parent 82a069f commit c740860
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 78 deletions.
76 changes: 76 additions & 0 deletions edb/lib/cfg.edgeql
Original file line number Diff line number Diff line change
Expand Up @@ -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 := <std::duration>'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 := <std::duration>'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 {
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -312,6 +385,9 @@ ALTER TYPE cfg::AbstractConfig {
CREATE CONSTRAINT std::min_value(1);
SET default := 100;
};

# Email providers

};


Expand Down
78 changes: 0 additions & 78 deletions edb/lib/ext/auth.edgeql
Original file line number Diff line number Diff line change
Expand Up @@ -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 := <std::duration>'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 := <std::duration>'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 :=
Expand All @@ -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.";
Expand Down

0 comments on commit c740860

Please sign in to comment.