diff --git a/src/Kitar/Dynamodb/Connection.php b/src/Kitar/Dynamodb/Connection.php index 6be55ef..fa09132 100644 --- a/src/Kitar/Dynamodb/Connection.php +++ b/src/Kitar/Dynamodb/Connection.php @@ -79,6 +79,10 @@ protected function createClient(array $config) 'endpoint' => $config['endpoint'] ?? null, ]; + if (! empty($dynamoConfig['endpoint']) && preg_match('#^https?://#i', $dynamoConfig['endpoint']) === 0) { + $dynamoConfig['endpoint'] = "https://" . $dynamoConfig['endpoint']; + } + if ($key = $config['access_key'] ?? null) { $config['key'] = $key; unset($config['access_key']); diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index e093ab7..682dd83 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -96,4 +96,30 @@ public function it_can_forward_call_to_dynamodb_client() 'TableName' => 'User' ]); } + + /** @test */ + public function it_prepends_default_protocol_if_not_given() + { + $connection = new Connection(['endpoint' => 'examples.com']); + $this->assertEquals($connection->getClient()->getEndpoint()->getScheme(), 'https'); + $this->assertEquals($connection->getClient()->getEndpoint()->getHost(), 'examples.com'); + $this->assertEquals($this->connection->getClient()->getEndpoint()->getScheme(), 'https'); + $this->assertEquals($this->connection->getClient()->getEndpoint()->getHost(), 'dynamodb.us-east-1.amazonaws.com'); + } + + /** @test */ + public function it_dont_prepends_default_protocol_if_http_given() + { + $connection = new Connection(['endpoint' => 'http://examples.com']); + $this->assertEquals($connection->getClient()->getEndpoint()->getScheme(), 'http'); + $this->assertEquals($connection->getClient()->getEndpoint()->getHost(), 'examples.com'); + } + + /** @test */ + public function it_dont_prepends_default_protocol_if_https_given() + { + $connection = new Connection(['endpoint' => 'https://examples.com']); + $this->assertEquals($connection->getClient()->getEndpoint()->getScheme(), 'https'); + $this->assertEquals($connection->getClient()->getEndpoint()->getHost(), 'examples.com'); + } }