Skip to content

Add a protocol by default on config endpoint #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
}
}