-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #246 from php-enqueue/amqps
[amqp] Add AMQP secure (SSL) connections support
- Loading branch information
Showing
25 changed files
with
599 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ bin/jp.php | |
bin/php-parse | ||
bin/google-cloud-batch | ||
vendor | ||
var | ||
.php_cs | ||
.php_cs.cache | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
set -x | ||
|
||
(cd docker && docker build --rm --force-rm --no-cache --pull --squash --tag "enqueue/rabbitmq:latest" -f Dockerfile.rabbitmq .) | ||
(cd docker && docker login --username="$DOCKER_USER" --password="$DOCKER_PASSWORD") | ||
(cd docker && docker push "enqueue/rabbitmq:latest") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env bash | ||
|
||
|
||
set -e | ||
set -x | ||
|
||
mkdir -p /tmp/roboconf | ||
rm -rf /tmp/roboconf/* | ||
|
||
(cd /tmp/roboconf && git clone [email protected]:roboconf/rabbitmq-with-ssl-in-docker.git) | ||
|
||
(cd /tmp/roboconf/rabbitmq-with-ssl-in-docker && docker build --rm --force-rm --no-cache --pull --squash --tag "enqueue/rabbitmq-ssl:latest" .) | ||
|
||
(cd /tmp/roboconf/rabbitmq-with-ssl-in-docker && docker login --username="$DOCKER_USER" --password="$DOCKER_PASSWORD") | ||
(cd /tmp/roboconf/rabbitmq-with-ssl-in-docker && docker push "enqueue/rabbitmq-ssl:latest") | ||
|
||
docker run --rm -v "`pwd`/var/rabbitmq_certificates:/enqueue" "enqueue/rabbitmq-ssl:latest" cp /home/testca/cacert.pem /enqueue/cacert.pem | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,14 @@ $factory = new AmqpConnectionFactory([ | |
// same as above but given as DSN string | ||
$factory = new AmqpConnectionFactory('amqp://user:[email protected]:10000/%2f'); | ||
|
||
// SSL or secure connection | ||
$factory = new AmqpConnectionFactory([ | ||
'dsn' => 'amqps:', | ||
'ssl_cacert' => '/path/to/cacert.pem', | ||
'ssl_cert' => '/path/to/cert.pem', | ||
'ssl_key' => '/path/to/key.pem', | ||
]); | ||
|
||
$psrContext = $factory->createContext(); | ||
|
||
// if you have enqueue/enqueue library installed you can use a function from there to create the context | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,14 @@ $factory = new AmqpConnectionFactory([ | |
// same as above but given as DSN string | ||
$factory = new AmqpConnectionFactory('amqp://user:[email protected]:10000/%2f'); | ||
|
||
// SSL or secure connection | ||
$factory = new AmqpConnectionFactory([ | ||
'dsn' => 'amqps:', | ||
'ssl_cacert' => '/path/to/cacert.pem', | ||
'ssl_cert' => '/path/to/cert.pem', | ||
'ssl_key' => '/path/to/key.pem', | ||
]); | ||
|
||
$psrContext = $factory->createContext(); | ||
|
||
// if you have enqueue/enqueue library installed you can use a function from there to create the context | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
pkg/amqp-bunny/Tests/Spec/AmqpSslSendToAndReceiveFromQueueTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace Enqueue\AmqpBunny\Tests\Spec; | ||
|
||
use Enqueue\AmqpBunny\AmqpConnectionFactory; | ||
use Enqueue\AmqpBunny\AmqpContext; | ||
use Interop\Queue\PsrContext; | ||
use Interop\Queue\Spec\SendToAndReceiveFromQueueSpec; | ||
|
||
/** | ||
* @group functional | ||
*/ | ||
class AmqpSslSendToAndReceiveFromQueueTest extends SendToAndReceiveFromQueueSpec | ||
{ | ||
public function test() | ||
{ | ||
$this->expectException(\LogicException::class); | ||
$this->expectExceptionMessage('The bunny library does not support SSL connections'); | ||
parent::test(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function createContext() | ||
{ | ||
$baseDir = realpath(__DIR__.'/../../../../'); | ||
|
||
// guard | ||
$this->assertNotEmpty($baseDir); | ||
|
||
$certDir = $baseDir.'/var/rabbitmq_certificates'; | ||
$this->assertDirectoryExists($certDir); | ||
|
||
$factory = new AmqpConnectionFactory([ | ||
'dsn' => getenv('AMQPS_DSN'), | ||
'ssl_verify' => false, | ||
'ssl_cacert' => $certDir.'/cacert.pem', | ||
'ssl_cert' => $certDir.'/cert.pem', | ||
'ssl_key' => $certDir.'/key.pem', | ||
]); | ||
|
||
return $factory->createContext(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @param AmqpContext $context | ||
*/ | ||
protected function createQueue(PsrContext $context, $queueName) | ||
{ | ||
$queue = $context->createQueue($queueName); | ||
$context->declareQueue($queue); | ||
$context->purgeQueue($queue); | ||
|
||
return $queue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
pkg/amqp-ext/Tests/Spec/AmqpSslSendToAndReceiveFromQueueTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace Enqueue\AmqpExt\Tests\Spec; | ||
|
||
use Enqueue\AmqpExt\AmqpConnectionFactory; | ||
use Enqueue\AmqpExt\AmqpContext; | ||
use Interop\Queue\PsrContext; | ||
use Interop\Queue\Spec\SendToAndReceiveFromQueueSpec; | ||
|
||
/** | ||
* @group functional | ||
*/ | ||
class AmqpSslSendToAndReceiveFromQueueTest extends SendToAndReceiveFromQueueSpec | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function createContext() | ||
{ | ||
$baseDir = realpath(__DIR__.'/../../../../'); | ||
|
||
// guard | ||
$this->assertNotEmpty($baseDir); | ||
|
||
$certDir = $baseDir.'/var/rabbitmq_certificates'; | ||
$this->assertDirectoryExists($certDir); | ||
|
||
$factory = new AmqpConnectionFactory([ | ||
'dsn' => getenv('AMQPS_DSN'), | ||
'ssl_verify' => false, | ||
'ssl_cacert' => $certDir.'/cacert.pem', | ||
'ssl_cert' => $certDir.'/cert.pem', | ||
'ssl_key' => $certDir.'/key.pem', | ||
]); | ||
|
||
return $factory->createContext(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @param AmqpContext $context | ||
*/ | ||
protected function createQueue(PsrContext $context, $queueName) | ||
{ | ||
$queue = $context->createQueue($queueName); | ||
$context->declareQueue($queue); | ||
$context->purgeQueue($queue); | ||
|
||
return $queue; | ||
} | ||
} |
Oops, something went wrong.