Skip to content

Commit

Permalink
Merge pull request #23 from lucasgiovanny/patch-1
Browse files Browse the repository at this point in the history
Add a protocol by default on config endpoint
  • Loading branch information
kitar authored Aug 26, 2022
2 parents b487d4a + baef8cf commit df0c010
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Kitar/Dynamodb/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
26 changes: 26 additions & 0 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

0 comments on commit df0c010

Please sign in to comment.