summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Quantum
diff options
context:
space:
mode:
authorDylan William Hardison <dylan@hardison.net>2018-08-26 07:55:24 +0200
committerDylan William Hardison <dylan@hardison.net>2018-08-26 07:55:24 +0200
commit9263f397e701f25af395e8cdee48c87ee3327157 (patch)
treecc7f6b6beef8947090a108701ca34316a5c8edb8 /Bugzilla/Quantum
parent23b94e8410d90e9e15584d3a9220b6bb214f4220 (diff)
parentd57aefa118802606ea7cc424aaa62173be9eec41 (diff)
downloadbugzilla-9263f397e701f25af395e8cdee48c87ee3327157.tar.gz
bugzilla-9263f397e701f25af395e8cdee48c87ee3327157.tar.xz
Merge remote-tracking branch 'bmo/mojo'
Diffstat (limited to 'Bugzilla/Quantum')
-rw-r--r--Bugzilla/Quantum/SES.pm79
-rw-r--r--Bugzilla/Quantum/Static.pm2
-rw-r--r--Bugzilla/Quantum/Stdout.pm3
3 files changed, 68 insertions, 16 deletions
diff --git a/Bugzilla/Quantum/SES.pm b/Bugzilla/Quantum/SES.pm
index 47c591fb5..03916075d 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("Error in SES Handler: ", $_);
+ $self->_respond( 400 => 'Bad Request' );
+ };
+}
+
+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)';
@@ -50,7 +67,8 @@ sub main {
}
sub _confirm_subscription {
- my ($self, $message) = @_;
+ state $check = compile($Invocant, Dict[SubscribeURL => Str, slurpy Any]);
+ my ($self, $message) = $check->(@_);
my $subscribe_url = $message->{SubscribeURL};
if ( !$subscribe_url ) {
@@ -70,8 +88,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 +118,28 @@ sub _handle_notification {
return 1;
}
+my $BouncedRecipients = ArrayRef[
+ Dict[
+ emailAddress => Str,
+ action => Str,
+ diagnosticCode => Str,
+ slurpy Any,
+ ],
+];
+my $BounceNotification = Dict [
+ bounce => Dict [
+ bouncedRecipients => $BouncedRecipients,
+ reportingMTA => Str,
+ bounceSubType => Str,
+ bounceType => Str,
+ slurpy Any,
+ ],
+ slurpy Any,
+];
+
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,11 +179,19 @@ sub _process_bounce {
$self->_respond( 200 => 'OK' );
}
-sub _process_complaint {
- my ($self) = @_;
+my $ComplainedRecipients = ArrayRef[Dict[ emailAddress => Str, slurpy Any ]];
+my $ComplaintNotification = Dict[
+ complaint => Dict [
+ complainedRecipients => $ComplainedRecipients,
+ complaintFeedbackType => Str,
+ slurpy Any,
+ ],
+ slurpy Any,
+];
- # email notification to bugzilla admin
- my ($notification) = @_;
+sub _process_complaint {
+ state $check = compile($Invocant, $ComplaintNotification);
+ my ($self, $notification) = $check->(@_);
my $template = Bugzilla->template_inner();
my $json = JSON::MaybeXS->new(
pretty => 1,
@@ -169,13 +224,9 @@ sub _respond {
}
sub _decode_json_wrapper {
- my ($self, $json) = @_;
+ state $check = compile($Invocant, Str);
+ my ($self, $json) = $check->(@_);
my $result;
- if ( !defined $json ) {
- WARN( 'Missing JSON from ' . $self->tx->remote_address );
- $self->_respond( 400 => 'Bad Request' );
- return undef;
- }
my $ok = try {
$result = decode_json($json);
}
@@ -200,4 +251,4 @@ sub ua {
return $ua;
}
-1; \ No newline at end of file
+1;
diff --git a/Bugzilla/Quantum/Static.pm b/Bugzilla/Quantum/Static.pm
index d687873ab..c01f062a4 100644
--- a/Bugzilla/Quantum/Static.pm
+++ b/Bugzilla/Quantum/Static.pm
@@ -11,7 +11,7 @@ use Bugzilla::Constants qw(bz_locations);
my $LEGACY_RE = qr{
^ (?:static/v[0-9]+\.[0-9]+/) ?
- ( (?:extensions/[^/]+/web|(?:image|skin|j)s)/.+)
+ ( (?:extensions/[^/]+/web|(?:image|graph|skin|j)s)/.+)
$
}xs;
diff --git a/Bugzilla/Quantum/Stdout.pm b/Bugzilla/Quantum/Stdout.pm
index be7b546ea..9cf19992c 100644
--- a/Bugzilla/Quantum/Stdout.pm
+++ b/Bugzilla/Quantum/Stdout.pm
@@ -11,6 +11,7 @@ use Moo;
use Bugzilla::Logging;
use Encode;
+use English qw(-no_match_vars);
has 'controller' => (
is => 'ro',
@@ -41,7 +42,7 @@ sub PRINT { ## no critic (unpack)
if ( $self->_encoding ) {
$bytes = encode( $self->_encoding, $bytes );
}
- $c->write($bytes.$\);
+ $c->write($bytes . ( $OUTPUT_RECORD_SEPARATOR // '' ) );
}
sub BINMODE {