summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Quantum/SES.pm
diff options
context:
space:
mode:
Diffstat (limited to 'Bugzilla/Quantum/SES.pm')
-rw-r--r--Bugzilla/Quantum/SES.pm58
1 files changed, 55 insertions, 3 deletions
diff --git a/Bugzilla/Quantum/SES.pm b/Bugzilla/Quantum/SES.pm
index 26df7a3eb..119769b32 100644
--- a/Bugzilla/Quantum/SES.pm
+++ b/Bugzilla/Quantum/SES.pm
@@ -18,8 +18,25 @@ use JSON::MaybeXS qw(decode_json);
use LWP::UserAgent ();
use Try::Tiny qw(catch try);
+use Types::Standard qw( :all );
+use Type::Utils;
+use Type::Params qw( compile );
+
+my $Invocant = class_type { class => __PACKAGE__ };
+
sub main {
my ($self) = @_;
+ try {
+ $self->_main;
+ }
+ catch {
+ FATAL($_);
+ die $_;
+ };
+}
+
+sub _main {
+ my ($self) = @_;
Bugzilla->error_mode(ERROR_MODE_DIE);
my $message = $self->_decode_json_wrapper( $self->req->body ) // return;
my $message_type = $self->req->headers->header('X-Amz-SNS-Message-Type') // '(missing)';
@@ -70,8 +87,17 @@ sub _confirm_subscription {
$self->_respond( 200 => 'OK' );
}
+my $NotificationType = Enum [qw( Bounce Complaint )];
+my $TypeField = Enum [qw(eventType notificationType)];
+my $Notification = Dict [
+ eventType => Optional [$NotificationType],
+ notificationType => Optional [$NotificationType],
+ slurpy Any,
+];
+
sub _handle_notification {
- my ( $self, $notification, $type_field ) = @_;
+ state $check = compile($Invocant, $Notification, $TypeField );
+ my ( $self, $notification, $type_field ) = $check->(@_);
if ( !exists $notification->{$type_field} ) {
return 0;
@@ -91,8 +117,23 @@ sub _handle_notification {
return 1;
}
+my $BouncedRecipients = ArrayRef[
+ Dict[
+ emailAddress => Str,
+ action => Str,
+ diagnosticCode => Int,
+ slurpy Any,
+ ],
+];
+my $BounceNotification = Dict[
+ bounce => Dict[
+ bouncedRecipients => $BouncedRecipients,
+ reportingMTA => Str,
+ ],
+];
sub _process_bounce {
- my ($self, $notification) = @_;
+ state $check = compile($Invocant, $BounceNotification);
+ my ($self, $notification) = $check->(@_);
# disable each account that is bouncing
foreach my $recipient ( @{ $notification->{bounce}->{bouncedRecipients} } ) {
@@ -132,8 +173,19 @@ sub _process_bounce {
$self->_respond( 200 => 'OK' );
}
+my $ComplainedRecipients = ArrayRef[Dict[ emailAddress => Str, slurpy Any ]];
+my $ComplaintNotification = Dict[
+ complaint => Dict [
+ complainedRecipients => $ComplainedRecipients,
+ complaintFeedbackType => Str,
+ slurpy Any,
+ ],
+ slurpy Any,
+];
+
sub _process_complaint {
- my ($self, $notification) = @_;
+ state $check = compile($Invocant, $ComplaintNotification);
+ my ($self, $notification) = $check->(@_);
my $template = Bugzilla->template_inner();
my $json = JSON::MaybeXS->new(
pretty => 1,