Skip to content

Commit a499a45

Browse files
committed
Fix using secure connector for TLS/SSL urls
1 parent 29164c3 commit a499a45

3 files changed

Lines changed: 34 additions & 5 deletions

File tree

README.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,39 @@ It helps with establishing a plain TCP/IP or secure SSL/TLS connection to the AM
104104
and issuing an initial `login` action.
105105

106106
```php
107-
$factory->createClient('user:secret@localhost')->then(
107+
$factory->createClient($amiUrl)->then(
108108
function (Client $client) {
109-
// client connected and authenticated
109+
// client connected (and authenticated)
110110
},
111111
function (Exception $e) {
112112
// an error occured while trying to connect or authorize client
113113
}
114114
);
115115
```
116116

117-
> Note: The given $amiUrl *must* include a host, it *should* include a username and secret
118-
> and it *can* include a scheme (tcp/ssl) and port definition.
117+
The `$amiUrl` contains the host and optional port to connect to:
118+
119+
```php
120+
$factory->createClient('127.0.0.1:5038');
121+
```
122+
123+
> If the `$amiUrl` is `null` (or omitted) this method defaults to connecting
124+
to your local host (`127.0.0.1:5038`).
125+
126+
The above examples to not pass any authentication details, so you may have to
127+
call `ActionSender::login()` after connecting or use the recommended shortcut
128+
to pass a username and secret for your AMI login details like this:
129+
130+
```php
131+
$factory->createClient('user:secret@localhost');
132+
```
133+
134+
The `Factory` defaults to establishing a plaintext TCP connection.
135+
If you want to connect through a secure TLS proxy, you can use the `tls` scheme:
136+
137+
```php
138+
$factory->createClient('tls://user:secret@localhost:12345');
139+
```
119140

120141
### Client
121142

src/Factory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function createClient($address = null)
3535
{
3636
$parts = $this->parseUrl($address);
3737

38-
$secure = (isset($parts['schema']) && $parts['schema'] !== 'tcp');
38+
$secure = (isset($parts['scheme']) && $parts['scheme'] !== 'tcp');
3939
$connector = $secure ? $this->secureConnector : $this->connector;
4040

4141
$promise = $connector->create($parts['host'], $parts['port'])->then(function (Stream $stream) {

tests/FactoryTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,12 @@ public function testCreateClientUsesTcpConnectorWithLocalhostLocation()
3838

3939
$this->factory->createClient('localhost');
4040
}
41+
42+
public function testCreateClientUsesTlsConnectorWithTlsLocation()
43+
{
44+
$promise = new Promise(function () { });
45+
$this->tls->expects($this->once())->method('create')->with('ami.local', 1234)->willReturn($promise);
46+
47+
$this->factory->createClient('tls://ami.local:1234');
48+
}
4149
}

0 commit comments

Comments
 (0)