]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1495901 - SES type checking error
authorDylan William Hardison <dylan@hardison.net>
Thu, 4 Oct 2018 13:34:13 +0000 (09:34 -0400)
committerGitHub <noreply@github.com>
Thu, 4 Oct 2018 13:34:13 +0000 (09:34 -0400)
Bugzilla/Quantum/SES.pm

index 750da4e773c81c930e1c9f0ec5a5eb1527d9081a..2d19de2400ce544760b1ebb9e26d007deef007f5 100644 (file)
@@ -19,11 +19,60 @@ 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__};
+use Type::Library -base, -declare => qw(
+  Self
+  Notification NotificationType TypeField
+  BounceNotification BouncedRecipients
+  ComplaintNotification ComplainedRecipients
+);
+use Type::Utils -all;
+use Types::Standard -all;
+use Type::Params qw(compile);
+
+class_type Self, {class => __PACKAGE__};
+
+declare ComplainedRecipients,
+  as ArrayRef [Dict [emailAddress => Str, slurpy Any]];
+declare ComplaintNotification,
+  as Dict [
+  complaint => Dict [
+    complainedRecipients  => ComplainedRecipients,
+    complaintFeedbackType => Str,
+    slurpy Any,
+  ],
+  slurpy Any,
+  ];
+
+declare BouncedRecipients,
+  as ArrayRef [
+  Dict [
+    emailAddress   => Str,
+    action         => Optional [Str],
+    diagnosticCode => Optional [Str],
+    status         => Optional [Str],
+    slurpy Any,
+  ],
+  ];
+declare BounceNotification,
+  as Dict [
+  bounce => Dict [
+    bouncedRecipients => BouncedRecipients,
+    reportingMTA      => Str,
+    bounceSubType     => Str,
+    bounceType        => Str,
+    slurpy Any,
+  ],
+  slurpy Any,
+  ];
+
+declare NotificationType, as Enum [qw( Bounce Complaint )];
+declare TypeField,        as Enum [qw(eventType notificationType)];
+declare Notification,
+  as Dict [
+  eventType        => Optional [NotificationType],
+  notificationType => Optional [NotificationType],
+  slurpy Any,
+  ];
 
 sub main {
   my ($self) = @_;
@@ -70,7 +119,7 @@ sub _main {
 }
 
 sub _confirm_subscription {
-  state $check = compile($Invocant, Dict [SubscribeURL => Str, slurpy Any]);
+  state $check = compile(Self, Dict [SubscribeURL => Str, slurpy Any]);
   my ($self, $message) = $check->(@_);
 
   my $subscribe_url = $message->{SubscribeURL};
@@ -91,16 +140,8 @@ 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 {
-  state $check = compile($Invocant, $Notification, $TypeField);
+  state $check = compile(Self, Notification, TypeField);
   my ($self, $notification, $type_field) = $check->(@_);
 
   if (!exists $notification->{$type_field}) {
@@ -121,22 +162,8 @@ 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 {
-  state $check = compile($Invocant, $BounceNotification);
+  state $check = compile(Self, BounceNotification);
   my ($self, $notification) = $check->(@_);
 
   # disable each account that is bouncing
@@ -180,18 +207,8 @@ 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 {
-  state $check = compile($Invocant, $ComplaintNotification);
+  state $check = compile(Self, ComplaintNotification);
   my ($self, $notification) = $check->(@_);
   my $template = Bugzilla->template_inner();
   my $json = JSON::MaybeXS->new(pretty => 1, utf8 => 1, canonical => 1,);
@@ -223,7 +240,7 @@ sub _respond {
 }
 
 sub _decode_json_wrapper {
-  state $check = compile($Invocant, Str);
+  state $check = compile(Self, Str);
   my ($self, $json) = $check->(@_);
   my $result;
   my $ok = try {