Skip to content

Commit

Permalink
Apply fixes from StyleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Broder authored and StyleCIBot committed Dec 14, 2018
1 parent 2f012e1 commit aabbd4c
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 60 deletions.
43 changes: 23 additions & 20 deletions src/TransitClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
use Illuminate\Support\Facades\Log;

/**
* Class TransitClient
*
* @package Kidfund\ThinTransportVaultClient
* Class TransitClient.
*/
class TransitClient implements VaultEncrypts
{
Expand Down Expand Up @@ -43,31 +41,32 @@ public function __construct(string $serverUrl, string $token, ClientInterface $c
if ($client == null) {
$this->client = new Client([
'base_uri' => $this->serverUrl,
'timeout' => 5.0,
'timeout' => 5.0,
]);
} else {
$this->client = $client;
}
}

/**
* @param string $key
* @param string $plaintext
* @param string $key
* @param string $plaintext
* @param string|null $context
*
* @return string
* @throws VaultException
* @throws \GuzzleHttp\Exception\GuzzleException
*
* @return string
*/
public function encrypt(string $key, string $plaintext, string $context = null) : string
{
$url = '/transit/encrypt/'.$key;

Log::debug('Encrypting');
Log::debug([
'key' => $key,
'key' => $key,
'plaintext' => $plaintext,
'context' => $context,
'context' => $context,
]);

$data = $this->getEncryptPayload($key, $plaintext, $context);
Expand All @@ -90,8 +89,8 @@ public function encrypt(string $key, string $plaintext, string $context = null)
}

/**
* @param string $key
* @param string $plaintext
* @param string $key
* @param string $plaintext
* @param string|null $context
*
* @return array
Expand Down Expand Up @@ -135,21 +134,22 @@ protected function decode(string $base64) : string
}

/**
* @param string $path
* @param string $cyphertext
* @param string $path
* @param string $cyphertext
* @param string|null $context
*
* @return string
* @throws VaultException
* @throws \GuzzleHttp\Exception\GuzzleException
*
* @return string
*/
public function decrypt(string $path, string $cyphertext, string $context = null) : string
{
Log::debug('Decrypting');
Log::debug([
'path' => $path,
'path' => $path,
'cyphertext' => $cyphertext,
'context' => $context,
'context' => $context,
]);

$url = '/transit/decrypt/'.$path;
Expand All @@ -169,7 +169,7 @@ public function decrypt(string $path, string $cyphertext, string $context = null
}

/**
* @param string $cyphertext
* @param string $cyphertext
* @param string|null $context
*
* @return array
Expand All @@ -196,7 +196,7 @@ protected function getCommandPayload(array $payload) : array
$payload = [
'headers' => [
'X-Vault-Token' => $this->token,
'Content-Type' => 'application/json',
'Content-Type' => 'application/json',
],
'json' => $payload,
];
Expand All @@ -207,11 +207,12 @@ protected function getCommandPayload(array $payload) : array
/**
* @param $url
* @param string $method
* @param array $payload
* @param array $payload
*
* @return mixed
* @throws VaultException
* @throws \GuzzleHttp\Exception\GuzzleException
*
* @return mixed
*/
private function command(string $url, string $method = 'POST', array $payload = [])
{
Expand All @@ -225,11 +226,13 @@ private function command(string $url, string $method = 'POST', array $payload =
$exceptionResponse = $e->getResponse();
$reasonPhrase = $exceptionResponse->getReasonPhrase();
$statusCode = $exceptionResponse->getStatusCode();

throw new VaultException($reasonPhrase, $statusCode);
} catch (ClientException $e) {
$exceptionResponse = $e->getResponse();
$reasonPhrase = $exceptionResponse->getReasonPhrase();
$statusCode = $exceptionResponse->getStatusCode();

throw new VaultException($reasonPhrase, $statusCode);
}

Expand Down
5 changes: 2 additions & 3 deletions src/VaultEncrypts.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
namespace Kidfund\ThinTransportVaultClient;

/**
* Interface VaultEncrypts
*
* @package Kidfund\ThinTransportVaultClient
* Interface VaultEncrypts.
*/
interface VaultEncrypts
{
public function encrypt(string $key, string $plaintext, string $context = null) : string;

public function decrypt(string $path, string $cyphertext, string $context = null) : string;
}
5 changes: 2 additions & 3 deletions src/VaultException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/**
* @author: timbroder
* Date: 4/14/16
*
* @copyright 2015 Kidfund Inc
*/

Expand All @@ -10,9 +11,7 @@
use Exception;

/**
* Class VaultException
*
* @package Kidfund\ThinTransportVaultClient
* Class VaultException.
*/
class VaultException extends Exception
{
Expand Down
22 changes: 13 additions & 9 deletions tests/ThinTransportClientIntegrationTest.php
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
<?php

use \Illuminate\Container\Container as Container;
use \Illuminate\Support\Facades\Facade as Facade;
use Illuminate\Container\Container as Container;
use Illuminate\Support\Facades\Facade as Facade;
use Kidfund\ThinTransportVaultClient\TransitClient;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;

/**
* @author: timbroder
* Date: 4/13/16
*
* @copyright 2018 Kidfund Inc
*/
class ThinTransitClientIntegrationTest extends TestCase
{
// TODO provide setup instructions to run vault

const VAULT_ADDR='http://kidfund-dev-web.app:8200';
const VAULT_TOKEN='6a4a2fd1-0d72-40a3-74f1-0b303e943fda';
const VAULT_ADDR = 'http://kidfund-dev-web.app:8200';
const VAULT_TOKEN = '6a4a2fd1-0d72-40a3-74f1-0b303e943fda';
const VAULT_ROOT_TOKEN = 'ec25daef14e-3bfb81d9-c695-8a8b-2d27';
const VAULTTEST_PREFIX = 'thingtransport_test';
const VALID_STRING = 'the quick brown fox';
const VAULT_PREFIX = 'vault:v1:';

/**
* Get env variables. these are set in phpunit.xml or can be overridden on the CLI
* Get env variables. these are set in phpunit.xml or can be overridden on the CLI.
*/
public function setUp()
{
parent::setUp();

$app = new Container();
$app->singleton('app', Container::class);
$app->bind('log', function($app)
{
$app->bind('log', function ($app) {
return new NullLogger();
});

Expand All @@ -42,6 +42,7 @@ public function setUp()
/**
* @param bool $root
* @param null $addr
*
* @return TransitClient
*/
public function getRealVaultClient($root = false, $addr = null)
Expand All @@ -55,16 +56,18 @@ public function getRealVaultClient($root = false, $addr = null)
if ($addr == null) {
$addr = self::VAULT_ADDR;
}

return new TransitClient($addr, $token);
}

/**
* @param $plaintext
* @param null $client
*
* @return mixed
* @throws \Kidfund\ThinTransportVaultClient\VaultException*
* @throws \GuzzleHttp\Exception\GuzzleException
*
* @return mixed
*/
public function getEncryptResponse($plaintext, $client = null)
{
Expand All @@ -81,9 +84,10 @@ public function getEncryptResponse($plaintext, $client = null)
* @param $ciphertext
* @param null $client
*
* @return mixed
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Kidfund\ThinTransportVaultClient\VaultException
*
* @return mixed
*/
public function getDecryptResponse($ciphertext, $client = null)
{
Expand Down
Loading

0 comments on commit aabbd4c

Please sign in to comment.