Backport PR #35 to allow EXTERNAL as well as AMQPLAIN auth

f38
Adam Williamson 6 years ago
parent 92b9a820a4
commit bcd200bd27

@ -0,0 +1,70 @@
From db3e849c09c58f563ef99030bdb264fadaa48bed Mon Sep 17 00:00:00 2001
From: Adam Williamson <awilliam@redhat.com>
Date: Thu, 1 Aug 2019 17:55:05 -0700
Subject: [PATCH] Allow EXTERNAL as well as AMQPLAIN auth
I'm trying to publish messages from openQA (which uses this
client library) to fedora-messaging (which is a RabbitMQ broker
using EXTERNAL auth), so I kinda need this. The intent here is
that by default we'll try and use either of AMQPLAIN or EXTERNAL
if the server advertises one or both, preferring AMQPLAIN; the
auth_mechanism query param can be used to specify only one or
the other.
Signed-off-by: Adam Williamson <awilliam@redhat.com>
---
lib/Mojo/RabbitMQ/Client.pm | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/lib/Mojo/RabbitMQ/Client.pm b/lib/Mojo/RabbitMQ/Client.pm
index 03d61b1..574868f 100644
--- a/lib/Mojo/RabbitMQ/Client.pm
+++ b/lib/Mojo/RabbitMQ/Client.pm
@@ -385,9 +385,21 @@ sub _connected {
'Connection::Start' => sub {
my $frame = shift;
- my @mechanisms = split /\s/, $frame->method_frame->mechanisms;
- return $self->emit(error => 'AMQPLAIN is not found in mechanisms')
- if none { $_ eq 'AMQPLAIN' } @mechanisms;
+ my @server_mechanisms = split /\s/, $frame->method_frame->mechanisms;
+ my $param_mechanism = $self->param('auth_mechanism') // '';
+ my @client_mechanisms = ('AMQPLAIN', 'EXTERNAL');
+ @client_mechanisms = ($param_mechanism) if ($param_mechanism);
+ warn "-- Server mechanisms: @server_mechanisms\n" if DEBUG;
+ warn "-- Client mechanisms: @client_mechanisms\n" if DEBUG;
+ my $mechanism;
+ for my $cand (@client_mechanisms) {
+ if (grep { $_ eq $cand } @server_mechanisms) {
+ $mechanism = $cand;
+ last;
+ }
+ }
+ return $self->emit(error => 'No authentication mechanism could be negotiated')
+ unless $mechanism;
my @locales = split /\s/, $frame->method_frame->locales;
return $self->emit(error => 'en_US is not found in locales')
@@ -404,7 +416,7 @@ sub _connected {
information => 'https://github.com/inway/mojo-rabbitmq-client',
version => __PACKAGE__->VERSION,
},
- mechanism => 'AMQPLAIN',
+ mechanism => $mechanism,
response => {LOGIN => $self->user, PASSWORD => $self->pass},
locale => 'en_US',
),
@@ -913,7 +925,9 @@ authority file has been provided, or 0x00 otherwise.
=head2 auth_mechanism
-Currently only AMQPLAIN is supported, B<so this parameter is ignored>.
+Sets the AMQP authentication mechanism. Defaults to AMQPLAIN. AMQPLAIN and
+EXTERNAL are supported; EXTERNAL will only work if L<Mojo::RabbitMQ::Client> does not need
+to do anything beyond passing along a username and password if specified.
=head2 heartbeat
--
2.22.0

@ -1,6 +1,6 @@
Name: perl-Mojo-RabbitMQ-Client Name: perl-Mojo-RabbitMQ-Client
Version: 0.2.3 Version: 0.2.3
Release: 1%{?dist} Release: 2%{?dist}
Summary: Mojo::IOLoop based RabbitMQ client Summary: Mojo::IOLoop based RabbitMQ client
License: Artistic 2.0 and BSD License: Artistic 2.0 and BSD
@ -9,6 +9,9 @@ URL: https://metacpan.org/release/Mojo-RabbitMQ-Client
# This file is non-free since it forbids modification. # This file is non-free since it forbids modification.
# Original source is https://cpan.metacpan.org/authors/id/S/SE/SEBAPOD/Mojo-RabbitMQ-Client-%%{version}.tar.gz # Original source is https://cpan.metacpan.org/authors/id/S/SE/SEBAPOD/Mojo-RabbitMQ-Client-%%{version}.tar.gz
Source0: Mojo-RabbitMQ-Client-without-amqp0.8-spec-%{version}.tar.gz Source0: Mojo-RabbitMQ-Client-without-amqp0.8-spec-%{version}.tar.gz
# Allow EXTERNAL auth (needed for publishing to fedora-messaging)
# https://github.com/inway/mojo-rabbitmq-client/pull/35
Patch0: 0001-Allow-EXTERNAL-as-well-as-AMQPLAIN-auth.patch
BuildArch: noarch BuildArch: noarch
# build requirements # build requirements
@ -55,6 +58,7 @@ Mojo::IOLoop.
%prep %prep
%setup -q -n Mojo-RabbitMQ-Client-%{version} %setup -q -n Mojo-RabbitMQ-Client-%{version}
%patch0 -p1
rm -rf inc rm -rf inc
%build %build
@ -76,6 +80,9 @@ TEST_RMQ='' MOJO_RABBITMQ_DEBUG="" MOJO_CONNECT_TIMEOUT="" ./Build test
%{_mandir}/man3/Mojo* %{_mandir}/man3/Mojo*
%changelog %changelog
* Thu Aug 01 2019 Adam Williamson <awilliam@redhat.com> - 0.2.3-2
- Backport PR #35 to allow EXTERNAL as well as AMQPLAIN auth
* Sun Jul 28 2019 Emmanuel Seyman <emmanuel@seyman.fr> - 0.2.3-1 * Sun Jul 28 2019 Emmanuel Seyman <emmanuel@seyman.fr> - 0.2.3-1
- Update to 0.2.3 - Update to 0.2.3

Loading…
Cancel
Save