From 05d20a28071326f8f591f654474c2f6b05fd7e36 Mon Sep 17 00:00:00 2001 From: Luca Castelnuovo Date: Thu, 8 Apr 2021 13:26:05 +0200 Subject: [PATCH 1/2] Use CQ\Request instead of Guzzle --- README.md | 45 +----- composer.json | 2 +- composer.lock | 308 ++++++++++++++++++++++--------------- examples/Vault.php | 41 +++++ src/Vault/BaseClient.php | 62 ++------ src/Vault/Models/Token.php | 2 - 6 files changed, 237 insertions(+), 223 deletions(-) create mode 100644 examples/Vault.php diff --git a/README.md b/README.md index ee90b17..df84dfe 100644 --- a/README.md +++ b/README.md @@ -14,50 +14,9 @@ PHP8 HashiCorp Vault client 1. `composer require cubequence/vault` -## Demo Code -```php -write('/kv1/helloworld', [ - 'foo' => 'bar', - ]); - $read = $client->read('/kv1/helloworld'); - $keys = $client->keys('/kv1'); - $revoke = $client->revoke('/kv1/helloworld'); -} catch (\Throwable $th) { - echo $th->getMessage(); - exit; -} - -echo json_encode([ - "write" => $write, // NoContent - "read" => $read, - "keys" => $keys, - "revoke" => $revoke, // NoContent -]); -``` +Look at the `examples` folder ## Security Vulnerabilities diff --git a/composer.json b/composer.json index 4c3ed46..733f20c 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ ], "require": { "php": ">=8.0.0", - "guzzlehttp/guzzle": "^7.0" + "cubequence/request": "^1.0" }, "require-dev": { "nunomaduro/phpinsights": "dev-master", diff --git a/composer.lock b/composer.lock index 0c1fa5e..105878f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,26 +4,75 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "63909e48ec1ca237f05648201619e05d", + "content-hash": "c1615a0d6cb28a92a5543350564924f9", "packages": [ + { + "name": "cubequence/request", + "version": "v1.0.1", + "source": { + "type": "git", + "url": "https://github.com/CubeQuence/request.git", + "reference": "84c8008f7635b59c90a64d43164e1188211e94ed" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/CubeQuence/request/zipball/84c8008f7635b59c90a64d43164e1188211e94ed", + "reference": "84c8008f7635b59c90a64d43164e1188211e94ed", + "shasum": "" + }, + "require": { + "guzzlehttp/guzzle": "^7.3", + "php": ">=8.0.0" + }, + "require-dev": { + "nunomaduro/phpinsights": "dev-master", + "pestphp/pest": "^1.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "CQ\\Request\\": "src/Request" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Luca Castelnuovo", + "email": "luca@castelnuovo.xyz" + } + ], + "description": "A simplified Guzzle client for CubeQuence", + "keywords": [ + "Guzzle", + "cubequence" + ], + "support": { + "issues": "https://github.com/CubeQuence/Request/issues", + "source": "https://github.com/CubeQuence/Request" + }, + "time": "2021-04-07T09:32:33+00:00" + }, { "name": "guzzlehttp/guzzle", - "version": "7.2.0", + "version": "7.3.0", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "0aa74dfb41ae110835923ef10a9d803a22d50e79" + "reference": "7008573787b430c1c1f650e3722d9bba59967628" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/0aa74dfb41ae110835923ef10a9d803a22d50e79", - "reference": "0aa74dfb41ae110835923ef10a9d803a22d50e79", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/7008573787b430c1c1f650e3722d9bba59967628", + "reference": "7008573787b430c1c1f650e3722d9bba59967628", "shasum": "" }, "require": { "ext-json": "*", "guzzlehttp/promises": "^1.4", - "guzzlehttp/psr7": "^1.7", + "guzzlehttp/psr7": "^1.7 || ^2.0", "php": "^7.2.5 || ^8.0", "psr/http-client": "^1.0" }, @@ -31,6 +80,7 @@ "psr/http-client-implementation": "1.0" }, "require-dev": { + "bamarni/composer-bin-plugin": "^1.4.1", "ext-curl": "*", "php-http/client-integration-tests": "^3.0", "phpunit/phpunit": "^8.5.5 || ^9.3.5", @@ -44,7 +94,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "7.1-dev" + "dev-master": "7.3-dev" } }, "autoload": { @@ -86,7 +136,7 @@ ], "support": { "issues": "https://github.com/guzzle/guzzle/issues", - "source": "https://github.com/guzzle/guzzle/tree/7.2.0" + "source": "https://github.com/guzzle/guzzle/tree/7.3.0" }, "funding": [ { @@ -106,20 +156,20 @@ "type": "github" } ], - "time": "2020-10-10T11:47:56+00:00" + "time": "2021-03-23T11:33:13+00:00" }, { "name": "guzzlehttp/promises", - "version": "1.4.0", + "version": "1.4.1", "source": { "type": "git", "url": "https://github.com/guzzle/promises.git", - "reference": "60d379c243457e073cff02bc323a2a86cb355631" + "reference": "8e7d04f1f6450fef59366c399cfad4b9383aa30d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/60d379c243457e073cff02bc323a2a86cb355631", - "reference": "60d379c243457e073cff02bc323a2a86cb355631", + "url": "https://api.github.com/repos/guzzle/promises/zipball/8e7d04f1f6450fef59366c399cfad4b9383aa30d", + "reference": "8e7d04f1f6450fef59366c399cfad4b9383aa30d", "shasum": "" }, "require": { @@ -159,22 +209,22 @@ ], "support": { "issues": "https://github.com/guzzle/promises/issues", - "source": "https://github.com/guzzle/promises/tree/1.4.0" + "source": "https://github.com/guzzle/promises/tree/1.4.1" }, - "time": "2020-09-30T07:37:28+00:00" + "time": "2021-03-07T09:25:29+00:00" }, { "name": "guzzlehttp/psr7", - "version": "1.7.0", + "version": "1.8.1", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "53330f47520498c0ae1f61f7e2c90f55690c06a3" + "reference": "35ea11d335fd638b5882ff1725228b3d35496ab1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/53330f47520498c0ae1f61f7e2c90f55690c06a3", - "reference": "53330f47520498c0ae1f61f7e2c90f55690c06a3", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/35ea11d335fd638b5882ff1725228b3d35496ab1", + "reference": "35ea11d335fd638b5882ff1725228b3d35496ab1", "shasum": "" }, "require": { @@ -234,9 +284,9 @@ ], "support": { "issues": "https://github.com/guzzle/psr7/issues", - "source": "https://github.com/guzzle/psr7/tree/1.7.0" + "source": "https://github.com/guzzle/psr7/tree/1.8.1" }, - "time": "2020-09-30T07:37:11+00:00" + "time": "2021-03-21T16:25:00+00:00" }, { "name": "psr/http-client", @@ -467,16 +517,16 @@ }, { "name": "composer/composer", - "version": "2.0.11", + "version": "2.0.12", "source": { "type": "git", "url": "https://github.com/composer/composer.git", - "reference": "a5a5632da0b1c2d6fa9a3b65f1f4e90d1f04abb9" + "reference": "6c12ce263da71641903e399c3ce8ecb08fd375fb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/composer/zipball/a5a5632da0b1c2d6fa9a3b65f1f4e90d1f04abb9", - "reference": "a5a5632da0b1c2d6fa9a3b65f1f4e90d1f04abb9", + "url": "https://api.github.com/repos/composer/composer/zipball/6c12ce263da71641903e399c3ce8ecb08fd375fb", + "reference": "6c12ce263da71641903e399c3ce8ecb08fd375fb", "shasum": "" }, "require": { @@ -544,7 +594,7 @@ "support": { "irc": "irc://irc.freenode.org/composer", "issues": "https://github.com/composer/composer/issues", - "source": "https://github.com/composer/composer/tree/2.0.11" + "source": "https://github.com/composer/composer/tree/2.0.12" }, "funding": [ { @@ -560,7 +610,7 @@ "type": "tidelift" } ], - "time": "2021-02-24T13:57:23+00:00" + "time": "2021-04-01T08:14:59+00:00" }, { "name": "composer/semver", @@ -724,16 +774,16 @@ }, { "name": "composer/xdebug-handler", - "version": "1.4.5", + "version": "1.4.6", "source": { "type": "git", "url": "https://github.com/composer/xdebug-handler.git", - "reference": "f28d44c286812c714741478d968104c5e604a1d4" + "reference": "f27e06cd9675801df441b3656569b328e04aa37c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/f28d44c286812c714741478d968104c5e604a1d4", - "reference": "f28d44c286812c714741478d968104c5e604a1d4", + "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/f27e06cd9675801df441b3656569b328e04aa37c", + "reference": "f27e06cd9675801df441b3656569b328e04aa37c", "shasum": "" }, "require": { @@ -741,7 +791,8 @@ "psr/log": "^1.0" }, "require-dev": { - "phpunit/phpunit": "^4.8.35 || ^5.7 || 6.5 - 8" + "phpstan/phpstan": "^0.12.55", + "symfony/phpunit-bridge": "^4.2 || ^5" }, "type": "library", "autoload": { @@ -767,7 +818,7 @@ "support": { "irc": "irc://irc.freenode.org/composer", "issues": "https://github.com/composer/xdebug-handler/issues", - "source": "https://github.com/composer/xdebug-handler/tree/1.4.5" + "source": "https://github.com/composer/xdebug-handler/tree/1.4.6" }, "funding": [ { @@ -783,7 +834,7 @@ "type": "tidelift" } ], - "time": "2020-11-13T08:04:11+00:00" + "time": "2021-03-25T17:01:18+00:00" }, { "name": "dealerdirect/phpcodesniffer-composer-installer", @@ -1129,16 +1180,16 @@ }, { "name": "filp/whoops", - "version": "2.9.2", + "version": "2.12.0", "source": { "type": "git", "url": "https://github.com/filp/whoops.git", - "reference": "df7933820090489623ce0be5e85c7e693638e536" + "reference": "d501fd2658d55491a2295ff600ae5978eaad7403" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/filp/whoops/zipball/df7933820090489623ce0be5e85c7e693638e536", - "reference": "df7933820090489623ce0be5e85c7e693638e536", + "url": "https://api.github.com/repos/filp/whoops/zipball/d501fd2658d55491a2295ff600ae5978eaad7403", + "reference": "d501fd2658d55491a2295ff600ae5978eaad7403", "shasum": "" }, "require": { @@ -1188,7 +1239,7 @@ ], "support": { "issues": "https://github.com/filp/whoops/issues", - "source": "https://github.com/filp/whoops/tree/2.9.2" + "source": "https://github.com/filp/whoops/tree/2.12.0" }, "funding": [ { @@ -1196,20 +1247,20 @@ "type": "github" } ], - "time": "2021-01-24T12:00:00+00:00" + "time": "2021-03-30T12:00:00+00:00" }, { "name": "friendsofphp/php-cs-fixer", - "version": "v2.18.4", + "version": "v2.18.5", "source": { "type": "git", "url": "https://github.com/FriendsOfPHP/PHP-CS-Fixer.git", - "reference": "06f764e3cb6d60822d8f5135205f9d32b5508a31" + "reference": "e0f6d05c8b157f50029ca6c65c19ed2694f475bf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/06f764e3cb6d60822d8f5135205f9d32b5508a31", - "reference": "06f764e3cb6d60822d8f5135205f9d32b5508a31", + "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/e0f6d05c8b157f50029ca6c65c19ed2694f475bf", + "reference": "e0f6d05c8b157f50029ca6c65c19ed2694f475bf", "shasum": "" }, "require": { @@ -1292,7 +1343,7 @@ "description": "A tool to automatically fix PHP code style", "support": { "issues": "https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues", - "source": "https://github.com/FriendsOfPHP/PHP-CS-Fixer/tree/v2.18.4" + "source": "https://github.com/FriendsOfPHP/PHP-CS-Fixer/tree/v2.18.5" }, "funding": [ { @@ -1300,7 +1351,7 @@ "type": "github" } ], - "time": "2021-03-20T14:52:33+00:00" + "time": "2021-04-06T18:37:33+00:00" }, { "name": "justinrainbow/json-schema", @@ -1901,16 +1952,16 @@ }, { "name": "pestphp/pest", - "version": "v1.0.2", + "version": "v1.0.5", "source": { "type": "git", "url": "https://github.com/pestphp/pest.git", - "reference": "fa130167857fe5daed0c281f1f14cd4a88c56184" + "reference": "6616b6299bd9f01f9d5390c03c82df3ba30413fb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pestphp/pest/zipball/fa130167857fe5daed0c281f1f14cd4a88c56184", - "reference": "fa130167857fe5daed0c281f1f14cd4a88c56184", + "url": "https://api.github.com/repos/pestphp/pest/zipball/6616b6299bd9f01f9d5390c03c82df3ba30413fb", + "reference": "6616b6299bd9f01f9d5390c03c82df3ba30413fb", "shasum": "" }, "require": { @@ -1920,13 +1971,13 @@ "pestphp/pest-plugin-expectations": "^1.0", "pestphp/pest-plugin-init": "^1.0", "php": "^7.3 || ^8.0", - "phpunit/phpunit": ">= 9.3.7 <= 9.5.2" + "phpunit/phpunit": ">= 9.3.7 <= 9.5.4" }, "require-dev": { - "illuminate/console": "^8.0", - "illuminate/support": "^8.0", - "laravel/dusk": "^6.9.1", - "mockery/mockery": "^1.4.1", + "illuminate/console": "^8.32.1", + "illuminate/support": "^8.32.1", + "laravel/dusk": "^6.13.0", + "mockery/mockery": "^1.4.3", "pestphp/pest-dev-tools": "dev-master" }, "bin": [ @@ -1978,7 +2029,7 @@ ], "support": { "issues": "https://github.com/pestphp/pest/issues", - "source": "https://github.com/pestphp/pest/tree/v1.0.2" + "source": "https://github.com/pestphp/pest/tree/v1.0.5" }, "funding": [ { @@ -2006,7 +2057,7 @@ "type": "patreon" } ], - "time": "2021-02-04T09:15:54+00:00" + "time": "2021-03-31T15:00:01+00:00" }, { "name": "pestphp/pest-plugin", @@ -2471,21 +2522,21 @@ }, { "name": "php-parallel-lint/php-parallel-lint", - "version": "v1.2.0", + "version": "v1.3.0", "source": { "type": "git", "url": "https://github.com/php-parallel-lint/PHP-Parallel-Lint.git", - "reference": "474f18bc6cc6aca61ca40bfab55139de614e51ca" + "reference": "772a954e5f119f6f5871d015b23eabed8cbdadfb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-parallel-lint/PHP-Parallel-Lint/zipball/474f18bc6cc6aca61ca40bfab55139de614e51ca", - "reference": "474f18bc6cc6aca61ca40bfab55139de614e51ca", + "url": "https://api.github.com/repos/php-parallel-lint/PHP-Parallel-Lint/zipball/772a954e5f119f6f5871d015b23eabed8cbdadfb", + "reference": "772a954e5f119f6f5871d015b23eabed8cbdadfb", "shasum": "" }, "require": { "ext-json": "*", - "php": ">=5.4.0" + "php": ">=5.3.0" }, "replace": { "grogy/php-parallel-lint": "*", @@ -2494,7 +2545,7 @@ "require-dev": { "nette/tester": "^1.3 || ^2.0", "php-parallel-lint/php-console-highlighter": "~0.3", - "squizlabs/php_codesniffer": "~3.0" + "squizlabs/php_codesniffer": "^3.5" }, "suggest": { "php-parallel-lint/php-console-highlighter": "Highlight syntax in code snippet" @@ -2522,9 +2573,9 @@ "homepage": "https://github.com/php-parallel-lint/PHP-Parallel-Lint", "support": { "issues": "https://github.com/php-parallel-lint/PHP-Parallel-Lint/issues", - "source": "https://github.com/php-parallel-lint/PHP-Parallel-Lint/tree/master" + "source": "https://github.com/php-parallel-lint/PHP-Parallel-Lint/tree/v1.3.0" }, - "time": "2020-04-04T12:18:32+00:00" + "time": "2021-04-07T14:42:48+00:00" }, { "name": "phpdocumentor/reflection-common", @@ -2747,16 +2798,16 @@ }, { "name": "phpspec/prophecy", - "version": "1.12.2", + "version": "1.13.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "245710e971a030f42e08f4912863805570f23d39" + "reference": "be1996ed8adc35c3fd795488a653f4b518be70ea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/245710e971a030f42e08f4912863805570f23d39", - "reference": "245710e971a030f42e08f4912863805570f23d39", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/be1996ed8adc35c3fd795488a653f4b518be70ea", + "reference": "be1996ed8adc35c3fd795488a653f4b518be70ea", "shasum": "" }, "require": { @@ -2808,9 +2859,9 @@ ], "support": { "issues": "https://github.com/phpspec/prophecy/issues", - "source": "https://github.com/phpspec/prophecy/tree/1.12.2" + "source": "https://github.com/phpspec/prophecy/tree/1.13.0" }, - "time": "2020-12-19T10:15:11+00:00" + "time": "2021-03-17T13:42:18+00:00" }, { "name": "phpstan/phpdoc-parser", @@ -2867,16 +2918,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "9.2.5", + "version": "9.2.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "f3e026641cc91909d421802dd3ac7827ebfd97e1" + "reference": "f6293e1b30a2354e8428e004689671b83871edde" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f3e026641cc91909d421802dd3ac7827ebfd97e1", - "reference": "f3e026641cc91909d421802dd3ac7827ebfd97e1", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f6293e1b30a2354e8428e004689671b83871edde", + "reference": "f6293e1b30a2354e8428e004689671b83871edde", "shasum": "" }, "require": { @@ -2932,7 +2983,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.5" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.6" }, "funding": [ { @@ -2940,7 +2991,7 @@ "type": "github" } ], - "time": "2020-11-28T06:44:49+00:00" + "time": "2021-03-28T07:26:59+00:00" }, { "name": "phpunit/php-file-iterator", @@ -3185,16 +3236,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.5.2", + "version": "9.5.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "f661659747f2f87f9e72095bb207bceb0f151cb4" + "reference": "c73c6737305e779771147af66c96ca6a7ed8a741" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/f661659747f2f87f9e72095bb207bceb0f151cb4", - "reference": "f661659747f2f87f9e72095bb207bceb0f151cb4", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c73c6737305e779771147af66c96ca6a7ed8a741", + "reference": "c73c6737305e779771147af66c96ca6a7ed8a741", "shasum": "" }, "require": { @@ -3272,7 +3323,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.2" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.4" }, "funding": [ { @@ -3284,7 +3335,7 @@ "type": "github" } ], - "time": "2021-02-02T14:45:58+00:00" + "time": "2021-03-23T07:16:29+00:00" }, { "name": "psr/cache", @@ -4778,16 +4829,16 @@ }, { "name": "symfony/cache", - "version": "v5.2.4", + "version": "v5.2.6", "source": { "type": "git", "url": "https://github.com/symfony/cache.git", - "reference": "d15fb2576cdbe2c40d7c851e62f85b0faff3dd3d" + "reference": "093d69bb10c959553c8beb828b8d4ea250a247dd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/cache/zipball/d15fb2576cdbe2c40d7c851e62f85b0faff3dd3d", - "reference": "d15fb2576cdbe2c40d7c851e62f85b0faff3dd3d", + "url": "https://api.github.com/repos/symfony/cache/zipball/093d69bb10c959553c8beb828b8d4ea250a247dd", + "reference": "093d69bb10c959553c8beb828b8d4ea250a247dd", "shasum": "" }, "require": { @@ -4853,7 +4904,7 @@ "psr6" ], "support": { - "source": "https://github.com/symfony/cache/tree/v5.2.4" + "source": "https://github.com/symfony/cache/tree/v5.2.6" }, "funding": [ { @@ -4869,7 +4920,7 @@ "type": "tidelift" } ], - "time": "2021-02-25T23:54:56+00:00" + "time": "2021-03-16T09:10:13+00:00" }, { "name": "symfony/cache-contracts", @@ -4877,12 +4928,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/cache-contracts.git", - "reference": "648977af9989c325eec96ba2671a20d5ff58fbea" + "reference": "c0446463729b89dd4fa62e9aeecc80287323615d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/cache-contracts/zipball/648977af9989c325eec96ba2671a20d5ff58fbea", - "reference": "648977af9989c325eec96ba2671a20d5ff58fbea", + "url": "https://api.github.com/repos/symfony/cache-contracts/zipball/c0446463729b89dd4fa62e9aeecc80287323615d", + "reference": "c0446463729b89dd4fa62e9aeecc80287323615d", "shasum": "" }, "require": { @@ -4949,20 +5000,20 @@ "type": "tidelift" } ], - "time": "2021-02-25T16:38:04+00:00" + "time": "2021-03-23T23:28:01+00:00" }, { "name": "symfony/console", - "version": "v5.2.4", + "version": "v5.2.6", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "d6d0cc30d8c0fda4e7b213c20509b0159a8f4556" + "reference": "35f039df40a3b335ebf310f244cb242b3a83ac8d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/d6d0cc30d8c0fda4e7b213c20509b0159a8f4556", - "reference": "d6d0cc30d8c0fda4e7b213c20509b0159a8f4556", + "url": "https://api.github.com/repos/symfony/console/zipball/35f039df40a3b335ebf310f244cb242b3a83ac8d", + "reference": "35f039df40a3b335ebf310f244cb242b3a83ac8d", "shasum": "" }, "require": { @@ -5030,7 +5081,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v5.2.4" + "source": "https://github.com/symfony/console/tree/v5.2.6" }, "funding": [ { @@ -5046,7 +5097,7 @@ "type": "tidelift" } ], - "time": "2021-02-23T10:08:49+00:00" + "time": "2021-03-28T09:42:18+00:00" }, { "name": "symfony/deprecation-contracts", @@ -5281,16 +5332,16 @@ }, { "name": "symfony/filesystem", - "version": "v5.2.4", + "version": "v5.2.6", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "710d364200997a5afde34d9fe57bd52f3cc1e108" + "reference": "8c86a82f51658188119e62cff0a050a12d09836f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/710d364200997a5afde34d9fe57bd52f3cc1e108", - "reference": "710d364200997a5afde34d9fe57bd52f3cc1e108", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/8c86a82f51658188119e62cff0a050a12d09836f", + "reference": "8c86a82f51658188119e62cff0a050a12d09836f", "shasum": "" }, "require": { @@ -5323,7 +5374,7 @@ "description": "Provides basic utilities for the filesystem", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/filesystem/tree/v5.2.4" + "source": "https://github.com/symfony/filesystem/tree/v5.2.6" }, "funding": [ { @@ -5339,7 +5390,7 @@ "type": "tidelift" } ], - "time": "2021-02-12T10:38:38+00:00" + "time": "2021-03-28T14:30:26+00:00" }, { "name": "symfony/finder", @@ -5404,16 +5455,16 @@ }, { "name": "symfony/http-client", - "version": "v5.2.4", + "version": "v5.2.6", "source": { "type": "git", "url": "https://github.com/symfony/http-client.git", - "reference": "c7d1f35a31ef153a302e3f80336170e1280b983d" + "reference": "3c3075467da15bc2edf38d2ac20d34719e794bd8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-client/zipball/c7d1f35a31ef153a302e3f80336170e1280b983d", - "reference": "c7d1f35a31ef153a302e3f80336170e1280b983d", + "url": "https://api.github.com/repos/symfony/http-client/zipball/3c3075467da15bc2edf38d2ac20d34719e794bd8", + "reference": "3c3075467da15bc2edf38d2ac20d34719e794bd8", "shasum": "" }, "require": { @@ -5470,7 +5521,7 @@ "description": "Provides powerful methods to fetch HTTP resources synchronously or asynchronously", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/http-client/tree/v5.2.4" + "source": "https://github.com/symfony/http-client/tree/v5.2.6" }, "funding": [ { @@ -5486,7 +5537,7 @@ "type": "tidelift" } ], - "time": "2021-03-01T00:40:14+00:00" + "time": "2021-03-28T09:42:18+00:00" }, { "name": "symfony/http-client-contracts", @@ -6471,16 +6522,16 @@ }, { "name": "symfony/string", - "version": "v5.2.4", + "version": "v5.2.6", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "4e78d7d47061fa183639927ec40d607973699609" + "reference": "ad0bd91bce2054103f5eaa18ebeba8d3bc2a0572" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/4e78d7d47061fa183639927ec40d607973699609", - "reference": "4e78d7d47061fa183639927ec40d607973699609", + "url": "https://api.github.com/repos/symfony/string/zipball/ad0bd91bce2054103f5eaa18ebeba8d3bc2a0572", + "reference": "ad0bd91bce2054103f5eaa18ebeba8d3bc2a0572", "shasum": "" }, "require": { @@ -6534,7 +6585,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v5.2.4" + "source": "https://github.com/symfony/string/tree/v5.2.6" }, "funding": [ { @@ -6550,7 +6601,7 @@ "type": "tidelift" } ], - "time": "2021-02-16T10:20:28+00:00" + "time": "2021-03-17T17:12:15+00:00" }, { "name": "symfony/var-exporter", @@ -6677,30 +6728,35 @@ }, { "name": "webmozart/assert", - "version": "1.9.1", + "version": "1.10.0", "source": { "type": "git", "url": "https://github.com/webmozarts/assert.git", - "reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389" + "reference": "6964c76c7804814a842473e0c8fd15bab0f18e25" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozarts/assert/zipball/bafc69caeb4d49c39fd0779086c03a3738cbb389", - "reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389", + "url": "https://api.github.com/repos/webmozarts/assert/zipball/6964c76c7804814a842473e0c8fd15bab0f18e25", + "reference": "6964c76c7804814a842473e0c8fd15bab0f18e25", "shasum": "" }, "require": { - "php": "^5.3.3 || ^7.0 || ^8.0", + "php": "^7.2 || ^8.0", "symfony/polyfill-ctype": "^1.8" }, "conflict": { "phpstan/phpstan": "<0.12.20", - "vimeo/psalm": "<3.9.1" + "vimeo/psalm": "<4.6.1 || 4.6.2" }, "require-dev": { - "phpunit/phpunit": "^4.8.36 || ^7.5.13" + "phpunit/phpunit": "^8.5.13" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.10-dev" + } + }, "autoload": { "psr-4": { "Webmozart\\Assert\\": "src/" @@ -6724,9 +6780,9 @@ ], "support": { "issues": "https://github.com/webmozarts/assert/issues", - "source": "https://github.com/webmozarts/assert/tree/1.9.1" + "source": "https://github.com/webmozarts/assert/tree/1.10.0" }, - "time": "2020-07-08T17:02:28+00:00" + "time": "2021-03-09T10:59:23+00:00" } ], "aliases": [], diff --git a/examples/Vault.php b/examples/Vault.php new file mode 100644 index 0000000..83d2b9a --- /dev/null +++ b/examples/Vault.php @@ -0,0 +1,41 @@ +write('/kv1/helloworld', [ + 'foo' => 'bar', + ]); + $read = $client->read('/kv1/helloworld'); + $keys = $client->keys('/kv1'); + $revoke = $client->revoke('/kv1/helloworld'); +} catch (\Throwable $th) { + echo $th->getMessage(); + exit; +} + +echo json_encode([ + 'write' => $write, // NoContent + 'read' => $read, + 'keys' => $keys, + 'revoke' => $revoke, // NoContent +]); diff --git a/src/Vault/BaseClient.php b/src/Vault/BaseClient.php index 21709ca..7c98530 100644 --- a/src/Vault/BaseClient.php +++ b/src/Vault/BaseClient.php @@ -4,8 +4,7 @@ namespace CQ\Vault; -use GuzzleHttp\Client; -use GuzzleHttp\Exception\TransferException; +use CQ\Request\Request; use CQ\Vault\Auth\AuthProvider; use CQ\Vault\Exceptions\AuthenticationException; use CQ\Vault\Exceptions\RequestException; @@ -75,10 +74,13 @@ protected function send( array | null $body = null ): object { try { - return $this->send_raw( + return Request::send( method: $method, path: $path, - body: $body + json: $body, + headers: [ + 'X-Vault-Token' => $this->token->getToken(), + ] ); } catch (RequestException $error) { // Try to re-authenticate if 403 and token is expired @@ -88,59 +90,17 @@ protected function send( ) { $this->authenticate(); - return $this->send_raw( + return Request::send( method: $method, path: $path, - body: $body + json: $body, + headers: [ + 'X-Vault-Token' => $this->token->getToken(), + ] ); } throw $error; } } - - /** - * Send request to API - */ - private function send_raw( - string $method, - string $path, - array | null $body = null - ): object { - $client = new Client([ - 'base_uri' => $this->baseUri, - 'timeout' => 2.0, - ]); - - $query = null; - $headers = [ - 'X-Vault-Token' => $this->token->getToken(), - ]; - - if (strpos($path, '?') !== false) { - [$path, $query] = explode('?', $path, 2); - } - - try { - $response = $client->request($method, $path, [ - 'headers' => $headers, - 'query' => $query, - 'json' => $body, - ]); - } catch (TransferException $error) { - throw new RequestException( - message: $error->getMessage(), - code: $error->getCode(), - previous: $error - ); - } - - $output = $response->getBody()->getContents(); - - if (!$output) { - return (object) []; - } - - return json_decode($output); - } } diff --git a/src/Vault/Models/Token.php b/src/Vault/Models/Token.php index f7cf969..a0c5c86 100644 --- a/src/Vault/Models/Token.php +++ b/src/Vault/Models/Token.php @@ -4,8 +4,6 @@ namespace CQ\Vault\Models; -use CQ\Vault\Exceptions\TokenException; - final class Token { public function __construct( From c641530c39fd6267f2c80cff6bb9dffdb59d0d1d Mon Sep 17 00:00:00 2001 From: Luca Castelnuovo Date: Thu, 8 Apr 2021 13:26:13 +0200 Subject: [PATCH 2/2] remove unused exceptions --- src/Vault/BaseClient.php | 4 ++-- src/Vault/Exceptions/RequestException.php | 17 ----------------- src/Vault/Exceptions/TokenException.php | 11 ----------- 3 files changed, 2 insertions(+), 30 deletions(-) delete mode 100755 src/Vault/Exceptions/RequestException.php delete mode 100644 src/Vault/Exceptions/TokenException.php diff --git a/src/Vault/BaseClient.php b/src/Vault/BaseClient.php index 7c98530..55d0de3 100644 --- a/src/Vault/BaseClient.php +++ b/src/Vault/BaseClient.php @@ -5,9 +5,9 @@ namespace CQ\Vault; use CQ\Request\Request; +use CQ\Request\Exceptions\BadResponseException; use CQ\Vault\Auth\AuthProvider; use CQ\Vault\Exceptions\AuthenticationException; -use CQ\Vault\Exceptions\RequestException; use CQ\Vault\Models\Token; abstract class BaseClient @@ -82,7 +82,7 @@ protected function send( 'X-Vault-Token' => $this->token->getToken(), ] ); - } catch (RequestException $error) { + } catch (BadResponseException $error) { // Try to re-authenticate if 403 and token is expired if ( $error->getCode() === 403 && diff --git a/src/Vault/Exceptions/RequestException.php b/src/Vault/Exceptions/RequestException.php deleted file mode 100755 index 3dc49dd..0000000 --- a/src/Vault/Exceptions/RequestException.php +++ /dev/null @@ -1,17 +0,0 @@ -request; - } -} diff --git a/src/Vault/Exceptions/TokenException.php b/src/Vault/Exceptions/TokenException.php deleted file mode 100644 index 5842de6..0000000 --- a/src/Vault/Exceptions/TokenException.php +++ /dev/null @@ -1,11 +0,0 @@ -