diff --git a/CHANGELOG.md b/CHANGELOG.md index 54ad7aa..2f839a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). In order to read more about upgrading and BC breaks have a look at the [UPGRADE Document](UPGRADE.md). +## 2.2.0 (22. October 2019) + ++ [#13](https://github.com/luyadev/luya-module-errorapi/pull/13) Configure `$invalidServers` in any adapter to ignore certain server names. + ## 2.1.0 (13. September 2019) + [#11](https://github.com/luyadev/luya-module-errorapi/issues/11) Add configuration for fingerprint in sentry adapter. diff --git a/composer.json b/composer.json index c28ef99..2a472c2 100644 --- a/composer.json +++ b/composer.json @@ -27,10 +27,5 @@ "luya\\errorapi\\" : "src/", "luya\\errorapi\\tests\\" : "tests/" } - }, - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - } + } } diff --git a/composer.lock b/composer.lock index 3443d77..54defda 100644 --- a/composer.lock +++ b/composer.lock @@ -597,6 +597,64 @@ ], "time": "2017-05-16T10:31:22+00:00" }, + { + "name": "lcobucci/jwt", + "version": "3.2.5", + "source": { + "type": "git", + "url": "https://github.com/lcobucci/jwt.git", + "reference": "82be04b4753f8b7693b62852b7eab30f97524f9b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/lcobucci/jwt/zipball/82be04b4753f8b7693b62852b7eab30f97524f9b", + "reference": "82be04b4753f8b7693b62852b7eab30f97524f9b", + "shasum": "" + }, + "require": { + "ext-openssl": "*", + "php": ">=5.5" + }, + "require-dev": { + "mdanter/ecc": "~0.3.1", + "mikey179/vfsstream": "~1.5", + "phpmd/phpmd": "~2.2", + "phpunit/php-invoker": "~1.1", + "phpunit/phpunit": "~4.5", + "squizlabs/php_codesniffer": "~2.3" + }, + "suggest": { + "mdanter/ecc": "Required to use Elliptic Curves based algorithms." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1-dev" + } + }, + "autoload": { + "psr-4": { + "Lcobucci\\JWT\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Luís Otávio Cobucci Oblonczyk", + "email": "lcobucci@gmail.com", + "role": "Developer" + } + ], + "description": "A simple library to work with JSON Web Token and JSON Web Signature", + "keywords": [ + "JWS", + "jwt" + ], + "time": "2018-11-11T12:22:26+00:00" + }, { "name": "luyadev/luya-composer", "version": "1.0.6", @@ -649,16 +707,16 @@ }, { "name": "luyadev/luya-core", - "version": "1.0.21", + "version": "1.0.22", "source": { "type": "git", "url": "https://github.com/luyadev/luya-core.git", - "reference": "23d8714ce08deddfb586c4e90ccaf0da2a95b112" + "reference": "c818377491124ca702b7b8bd93dc65759844a03c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/luyadev/luya-core/zipball/23d8714ce08deddfb586c4e90ccaf0da2a95b112", - "reference": "23d8714ce08deddfb586c4e90ccaf0da2a95b112", + "url": "https://api.github.com/repos/luyadev/luya-core/zipball/c818377491124ca702b7b8bd93dc65759844a03c", + "reference": "c818377491124ca702b7b8bd93dc65759844a03c", "shasum": "" }, "require": { @@ -702,24 +760,27 @@ "yii", "yii2" ], - "time": "2019-09-09T12:08:23+00:00" + "time": "2019-10-22T11:53:22+00:00" }, { "name": "luyadev/luya-module-admin", - "version": "2.1.0", + "version": "2.2.1", "source": { "type": "git", "url": "https://github.com/luyadev/luya-module-admin.git", - "reference": "d6848fb6b13eab7012f53ebaeea332964ec6afe7" + "reference": "64ebffc9d93ca995c9e0ef71efd45936377f9ae6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/luyadev/luya-module-admin/zipball/d6848fb6b13eab7012f53ebaeea332964ec6afe7", - "reference": "d6848fb6b13eab7012f53ebaeea332964ec6afe7", + "url": "https://api.github.com/repos/luyadev/luya-module-admin/zipball/64ebffc9d93ca995c9e0ef71efd45936377f9ae6", + "reference": "64ebffc9d93ca995c9e0ef71efd45936377f9ae6", "shasum": "" }, "require": { "flowjs/flow-php-server": "^1.0", + "luyadev/luya-core": "^1.0", + "sizeg/yii2-jwt": "^1.2", + "whichbrowser/parser": "^2.0", "yiisoft/yii2-imagine": "~2.1.0", "yiisoft/yii2-queue": "~2.0.0" }, @@ -734,7 +795,7 @@ "bower-asset/ng-wig": "~3.0.0", "bower-asset/twigjs-bower": "~0.10.5", "bower-asset/ui-router": "~0.4.0", - "luyadev/luya-testsuite": "~1.0.11", + "luyadev/luya-testsuite": "^1.0", "twbs/bootstrap": "~4.3.0", "unglue/client": "^1.4.1" }, @@ -780,20 +841,20 @@ "yii", "yii2" ], - "time": "2019-07-22T12:36:19+00:00" + "time": "2019-10-03T16:53:33+00:00" }, { "name": "luyadev/luya-module-cms", - "version": "2.1.0", + "version": "2.1.1", "source": { "type": "git", "url": "https://github.com/luyadev/luya-module-cms.git", - "reference": "4161117f3410342e9cb8fef8dff95e245fac38be" + "reference": "b2ed43763d99aba7b1e2314a3d06bfda617c3cf6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/luyadev/luya-module-cms/zipball/4161117f3410342e9cb8fef8dff95e245fac38be", - "reference": "4161117f3410342e9cb8fef8dff95e245fac38be", + "url": "https://api.github.com/repos/luyadev/luya-module-cms/zipball/b2ed43763d99aba7b1e2314a3d06bfda617c3cf6", + "reference": "b2ed43763d99aba7b1e2314a3d06bfda617c3cf6", "shasum": "" }, "require-dev": { @@ -844,20 +905,20 @@ "yii2", "yii2-cms" ], - "time": "2019-07-22T12:32:51+00:00" + "time": "2019-09-17T17:59:48+00:00" }, { "name": "luyadev/luya-testsuite", - "version": "1.0.20.1", + "version": "1.0.23", "source": { "type": "git", "url": "https://github.com/luyadev/luya-testsuite.git", - "reference": "98936a588f60163b36f79798f769b06cf0d90d98" + "reference": "9c9823a5b1e1cb71ed379fa865481f58f2e7305f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/luyadev/luya-testsuite/zipball/98936a588f60163b36f79798f769b06cf0d90d98", - "reference": "98936a588f60163b36f79798f769b06cf0d90d98", + "url": "https://api.github.com/repos/luyadev/luya-testsuite/zipball/9c9823a5b1e1cb71ed379fa865481f58f2e7305f", + "reference": "9c9823a5b1e1cb71ed379fa865481f58f2e7305f", "shasum": "" }, "require": { @@ -897,7 +958,7 @@ "module", "php" ], - "time": "2019-09-08T12:53:58+00:00" + "time": "2019-10-22T10:13:18+00:00" }, { "name": "myclabs/deep-copy", @@ -1201,16 +1262,16 @@ }, { "name": "phpmailer/phpmailer", - "version": "v6.0.7", + "version": "v6.1.1", "source": { "type": "git", "url": "https://github.com/PHPMailer/PHPMailer.git", - "reference": "0c41a36d4508d470e376498c1c0c527aa36a2d59" + "reference": "26bd96350b0b2fcbf0ef4e6f0f9cf3528302a9d8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/0c41a36d4508d470e376498c1c0c527aa36a2d59", - "reference": "0c41a36d4508d470e376498c1c0c527aa36a2d59", + "url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/26bd96350b0b2fcbf0ef4e6f0f9cf3528302a9d8", + "reference": "26bd96350b0b2fcbf0ef4e6f0f9cf3528302a9d8", "shasum": "" }, "require": { @@ -1243,17 +1304,17 @@ }, "notification-url": "https://packagist.org/downloads/", "license": [ - "LGPL-2.1" + "LGPL-2.1-only" ], "authors": [ - { - "name": "Jim Jagielski", - "email": "jimjag@gmail.com" - }, { "name": "Marcus Bointon", "email": "phpmailer@synchromedia.co.uk" }, + { + "name": "Jim Jagielski", + "email": "jimjag@gmail.com" + }, { "name": "Andy Prevost", "email": "codeworxtech@users.sourceforge.net" @@ -1263,26 +1324,26 @@ } ], "description": "PHPMailer is a full-featured email creation and transfer class for PHP", - "time": "2019-02-01T15:04:28+00:00" + "time": "2019-09-27T21:33:43+00:00" }, { "name": "phpspec/prophecy", - "version": "1.8.1", + "version": "1.9.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "1927e75f4ed19131ec9bcc3b002e07fb1173ee76" + "reference": "f6811d96d97bdf400077a0cc100ae56aa32b9203" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/1927e75f4ed19131ec9bcc3b002e07fb1173ee76", - "reference": "1927e75f4ed19131ec9bcc3b002e07fb1173ee76", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/f6811d96d97bdf400077a0cc100ae56aa32b9203", + "reference": "f6811d96d97bdf400077a0cc100ae56aa32b9203", "shasum": "" }, "require": { "doctrine/instantiator": "^1.0.2", "php": "^5.3|^7.0", - "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0", + "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0|^5.0", "sebastian/comparator": "^1.1|^2.0|^3.0", "sebastian/recursion-context": "^1.0|^2.0|^3.0" }, @@ -1326,7 +1387,7 @@ "spy", "stub" ], - "time": "2019-06-13T12:50:23+00:00" + "time": "2019-10-03T11:07:50+00:00" }, { "name": "phpunit/php-code-coverage", @@ -1934,16 +1995,16 @@ }, { "name": "sebastian/exporter", - "version": "3.1.1", + "version": "3.1.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "06a9a5947f47b3029d76118eb5c22802e5869687" + "reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/06a9a5947f47b3029d76118eb5c22802e5869687", - "reference": "06a9a5947f47b3029d76118eb5c22802e5869687", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/68609e1261d215ea5b21b7987539cbfbe156ec3e", + "reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e", "shasum": "" }, "require": { @@ -1997,7 +2058,7 @@ "export", "exporter" ], - "time": "2019-08-11T12:43:14+00:00" + "time": "2019-09-14T09:02:43+00:00" }, { "name": "sebastian/global-state", @@ -2280,6 +2341,50 @@ "homepage": "https://github.com/sebastianbergmann/version", "time": "2016-10-03T07:35:21+00:00" }, + { + "name": "sizeg/yii2-jwt", + "version": "v1.2.1", + "source": { + "type": "git", + "url": "https://github.com/sizeg/yii2-jwt.git", + "reference": "22100b1313a8ee281525fa63d91d5ef12c06d959" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sizeg/yii2-jwt/zipball/22100b1313a8ee281525fa63d91d5ef12c06d959", + "reference": "22100b1313a8ee281525fa63d91d5ef12c06d959", + "shasum": "" + }, + "require": { + "lcobucci/jwt": "~3.2.0", + "php": ">=5.5.0", + "yiisoft/yii2": "~2.0.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8" + }, + "type": "yii2-extension", + "autoload": { + "psr-4": { + "sizeg\\jwt\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "authors": [ + { + "name": "Dmitriy Demin", + "email": "sizemail@gmail.com", + "homepage": "https://sizeg.tk" + } + ], + "description": "JWT based on Icobucci", + "keywords": [ + "jwt", + "yii 2", + "yii2" + ], + "time": "2019-03-20T06:36:38+00:00" + }, { "name": "symfony/polyfill-ctype", "version": "v1.12.0", @@ -2340,16 +2445,16 @@ }, { "name": "symfony/process", - "version": "v4.3.4", + "version": "v4.3.5", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "e89969c00d762349f078db1128506f7f3dcc0d4a" + "reference": "50556892f3cc47d4200bfd1075314139c4c9ff4b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/e89969c00d762349f078db1128506f7f3dcc0d4a", - "reference": "e89969c00d762349f078db1128506f7f3dcc0d4a", + "url": "https://api.github.com/repos/symfony/process/zipball/50556892f3cc47d4200bfd1075314139c4c9ff4b", + "reference": "50556892f3cc47d4200bfd1075314139c4c9ff4b", "shasum": "" }, "require": { @@ -2385,7 +2490,7 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2019-08-26T08:26:39+00:00" + "time": "2019-09-26T21:17:10+00:00" }, { "name": "theseer/tokenizer", @@ -2596,16 +2701,16 @@ }, { "name": "yiisoft/yii2", - "version": "2.0.26", + "version": "2.0.28", "source": { "type": "git", "url": "https://github.com/yiisoft/yii2-framework.git", - "reference": "5ca9036dd6eb75354fbd287cc57f79ca861fb7f1" + "reference": "80bf3a6e04a0128f753cb73ba7255d8e2ae3a02f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/yiisoft/yii2-framework/zipball/5ca9036dd6eb75354fbd287cc57f79ca861fb7f1", - "reference": "5ca9036dd6eb75354fbd287cc57f79ca861fb7f1", + "url": "https://api.github.com/repos/yiisoft/yii2-framework/zipball/80bf3a6e04a0128f753cb73ba7255d8e2ae3a02f", + "reference": "80bf3a6e04a0128f753cb73ba7255d8e2ae3a02f", "shasum": "" }, "require": { @@ -2692,7 +2797,7 @@ "framework", "yii2" ], - "time": "2019-09-03T21:38:33+00:00" + "time": "2019-10-08T13:14:18+00:00" }, { "name": "yiisoft/yii2-composer", diff --git a/src/BaseIntegrationAdapter.php b/src/BaseIntegrationAdapter.php index 84dc41b..c28a1a3 100644 --- a/src/BaseIntegrationAdapter.php +++ b/src/BaseIntegrationAdapter.php @@ -3,6 +3,7 @@ namespace luya\errorapi; use luya\errorapi\models\Data; +use luya\helpers\StringHelper; use yii\base\BaseObject; /** @@ -15,6 +16,19 @@ */ abstract class BaseIntegrationAdapter extends BaseObject { + /** + * @var array A list of words which the servername can contain and will therefore be ignored. Example + * + * ```php + * 'invalidServers' => ['example.com'] + * ``` + * + * If the server name contains example.com (for example: http://example.com/foobar) the error adapter will ignore the message and + * stops processing. + * @since 2.2.0 + */ + public $invalidServers = []; + /** * The method which will be called when the error api recieves the error data * and the integration object is created. @@ -34,7 +48,10 @@ abstract public function onCreate(Data $data); public function run(Data $data, Module $module) { $this->_module = $module; - $this->onCreate($data); + + if (!$this->isInvalidServer($data, $this->invalidServers)) { + $this->onCreate($data); + } } private $_module; @@ -58,4 +75,24 @@ public function setModule(Module $module) { $this->_module = $module; } + + /** + * Check if the current data contains an invalid server + * + * @param Data $data + * @return boolean + * @since 2.2.0 + */ + public function isInvalidServer(Data $data, array $servers) + { + $serverName = $data->getServerName(); + + if (empty($serverName)) { + return true; + } elseif (StringHelper::contains($servers, $serverName)) { + return true; + } + + return false; + } } \ No newline at end of file diff --git a/src/adapters/SentryAdapter.php b/src/adapters/SentryAdapter.php index 2344243..3b85920 100644 --- a/src/adapters/SentryAdapter.php +++ b/src/adapters/SentryAdapter.php @@ -2,14 +2,15 @@ namespace luya\errorapi\adapters; +use Curl\Curl; +use luya\Exception; +use luya\exceptions\WhitelistedException; use luya\errorapi\BaseIntegrationAdapter; use luya\errorapi\models\Data; use luya\helpers\Inflector; -use Curl\Curl; -use luya\Exception; +use luya\helpers\Url; use yii\helpers\Json; use yii\base\InvalidConfigException; -use luya\helpers\Url; /** * Sentry Integration. @@ -93,18 +94,22 @@ public function getAuth(Data $data) // create the project if not exists if (!$hasProject->isSuccess()) { - $curl->post("https://sentry.io/api/0/teams/{$this->organisation}/{$this->team}/projects/", [ + $newCreated = $curl->post("https://sentry.io/api/0/teams/{$this->organisation}/{$this->team}/projects/", [ 'name' => Url::domain($data->getServerName()), 'slug' => $slug ]); } - // get project id with credentials - + // Get the project keys $keys = $curl->get("https://sentry.io/api/0/projects/{$this->organisation}/{$slug}/keys/"); if ($keys->isError()) { - throw new Exception("The request for organisation key went wrong, maybe invalid sentry api credentials provided?"); + // if the project is newly created try to delete the project otherwise an empty project exists + if ($newCreated->isSuccess()) { + $curl->delete("https://sentry.io/api/0/projects/{$this->organisation}/{$slug}/"); + } + + throw new WhitelistedException("The request for organisation key went wrong, maybe invalid sentry api credentials provided?"); } $keysResponse = json_decode($keys->response, true); diff --git a/tests/adapters/MailAdapterTest.php b/tests/adapters/MailAdapterTest.php index 0951ef6..2418846 100644 --- a/tests/adapters/MailAdapterTest.php +++ b/tests/adapters/MailAdapterTest.php @@ -8,6 +8,25 @@ class MailAdapterTest extends ErrorApiTestCase { + public function testIgnoreServer() + { + $adapter = new MailAdapter(['recipient' => 'foobar@example.com']); + + $data = new Data(); + $data->error_json = json_encode([ + 'serverName' => 'luya.io', + 'message' => 'Hello World!', + 'violate' => '', + 'trace' => [ + 1 => ['file' => 'yes.php', 'line' => 123] + ] + ]); + + $this->assertTrue($adapter->isInvalidServer($data, ['luya.io'])); + $this->assertTrue($adapter->isInvalidServer($data, ['io'])); + $this->assertFalse($adapter->isInvalidServer($data, [])); + } + public function testAdapter() { $adapter = new MailAdapter(['recipient' => 'foobar@example.com']);