Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
eladcon committed May 20, 2024
1 parent cf21784 commit b672d23
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
11 changes: 10 additions & 1 deletion ses/lib.w
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,26 @@ bring "./types.w" as types;
bring "./sim.w" as sim;
bring "./tfaws.w" as tfaws;

/// EmailService can used for defining and interacting with AWS SES.
/// When running the simulator in a non test environment, it will use the
/// actual cloud implementation.
pub class EmailService impl types.IEmailService {
inner: types.IEmailService;
new(props: types.EmailServiceProps) {
let target = util.env("WING_TARGET");
if target == "sim" {
this.inner = new sim.EmailService_sim(props);
if std.Node.of(this).app.isTestEnvironment {
this.inner = new sim.EmailService_sim(props);
} else {
this.inner = new tfaws.EmailService_tfaws(props);
}
} elif target == "tf-aws" {
this.inner = new tfaws.EmailService_tfaws(props);
} else {
throw "Unknown target: {target}";
}

nodeof(this.inner).hidden = true;
}

pub inflight sendEmail(options: types.SendEmailOptions): str? {
Expand Down
25 changes: 25 additions & 0 deletions ses/tfaws.w
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,31 @@ pub class EmailService_tfaws impl types.IEmailService {
) as "emailIdentity-{email.replaceAll("@", "_")}";
}
}

if let configurationSet = props.configurationSet {
new aws.sesConfigurationSet.SesConfigurationSet(
name: configurationSet.name,
) as "configurationSet";

if let eventDestination = props.eventDestination {
let var cloudwatch: Json? = nil;
if let cloudwatchDestination = eventDestination.cloudwatchDestination {
cloudwatch = {
default_value: cloudwatchDestination.defaultValue,
dimension_name: cloudwatchDestination.dimensionName,
value_source: cloudwatchDestination.valueSource,
};
}
new aws.sesEventDestination.SesEventDestination(
name: eventDestination.name,
configurationSetName: configurationSet.name,
enabled: true,
matchingTypes: eventDestination.matchingTypes,
cloudwatchDestination: cloudwatch,
) as "eventDestination";
}
}

}

pub inflight sendEmail(options: types.SendEmailOptions): str? {
Expand Down
18 changes: 18 additions & 0 deletions ses/types.w
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
pub struct ConfigurationSet {
name: str;
}

pub struct CloudWatchDestination {
defaultValue: str;
dimensionName: str;
valueSource: str;
}

pub struct EventDestination {
name: str;
matchingTypes: Array<str>;
cloudwatchDestination: CloudWatchDestination?;
}

pub struct EmailServiceProps {
emailIdentities: Array<str>?;
configurationSet: ConfigurationSet?;
eventDestination: EventDestination?;
}

pub struct Destination {
Expand Down

0 comments on commit b672d23

Please sign in to comment.