Skip to content

Commit df0c010

Browse files
authored
Merge pull request #23 from lucasgiovanny/patch-1
Add a protocol by default on config endpoint
2 parents b487d4a + baef8cf commit df0c010

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/Kitar/Dynamodb/Connection.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ protected function createClient(array $config)
7979
'endpoint' => $config['endpoint'] ?? null,
8080
];
8181

82+
if (! empty($dynamoConfig['endpoint']) && preg_match('#^https?://#i', $dynamoConfig['endpoint']) === 0) {
83+
$dynamoConfig['endpoint'] = "https://" . $dynamoConfig['endpoint'];
84+
}
85+
8286
if ($key = $config['access_key'] ?? null) {
8387
$config['key'] = $key;
8488
unset($config['access_key']);

tests/ConnectionTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,30 @@ public function it_can_forward_call_to_dynamodb_client()
9696
'TableName' => 'User'
9797
]);
9898
}
99+
100+
/** @test */
101+
public function it_prepends_default_protocol_if_not_given()
102+
{
103+
$connection = new Connection(['endpoint' => 'examples.com']);
104+
$this->assertEquals($connection->getClient()->getEndpoint()->getScheme(), 'https');
105+
$this->assertEquals($connection->getClient()->getEndpoint()->getHost(), 'examples.com');
106+
$this->assertEquals($this->connection->getClient()->getEndpoint()->getScheme(), 'https');
107+
$this->assertEquals($this->connection->getClient()->getEndpoint()->getHost(), 'dynamodb.us-east-1.amazonaws.com');
108+
}
109+
110+
/** @test */
111+
public function it_dont_prepends_default_protocol_if_http_given()
112+
{
113+
$connection = new Connection(['endpoint' => 'http://examples.com']);
114+
$this->assertEquals($connection->getClient()->getEndpoint()->getScheme(), 'http');
115+
$this->assertEquals($connection->getClient()->getEndpoint()->getHost(), 'examples.com');
116+
}
117+
118+
/** @test */
119+
public function it_dont_prepends_default_protocol_if_https_given()
120+
{
121+
$connection = new Connection(['endpoint' => 'https://examples.com']);
122+
$this->assertEquals($connection->getClient()->getEndpoint()->getScheme(), 'https');
123+
$this->assertEquals($connection->getClient()->getEndpoint()->getHost(), 'examples.com');
124+
}
99125
}

0 commit comments

Comments
 (0)