Skip to content

Commit a7465c5

Browse files
committed
AC-1271: Add rate limiting for payment information endpoint and mutation
1 parent e22c998 commit a7465c5

File tree

5 files changed

+35
-23
lines changed

5 files changed

+35
-23
lines changed

lib/internal/Magento/Framework/Cache/Backend/Redis.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,22 @@
66

77
namespace Magento\Framework\Cache\Backend;
88

9+
use InvalidArgumentException;
10+
911
/**
10-
* Redis wrapper to extend current implementation behaviour.
12+
* Redis wrapper to extend current implementation behaviour
1113
*/
1214
class Redis extends \Cm_Cache_Backend_Redis
1315
{
1416
/**
15-
* Local state of preloaded keys.
17+
* Local state of preloaded keys
1618
*
1719
* @var array
1820
*/
1921
private $preloadedData = [];
2022

2123
/**
22-
* Array of keys to be preloaded.
24+
* Array of keys to be preloaded
2325
*
2426
* @var array
2527
*/
@@ -62,7 +64,7 @@ public function load($id, $doNotTestCacheValidity = false)
6264
}
6365

6466
/**
65-
* Cover errors on save operations, which may occurs when Redis cannot evict keys, which is expected in some cases.
67+
* Cover errors on save operations, which may occurs when Redis cannot evict keys, which is expected in some cases
6668
*
6769
* @param string $data
6870
* @param string $id
@@ -96,28 +98,31 @@ public function remove($id)
9698
}
9799

98100
/**
99-
* Increment/decrement an item by given number (positive or negative for decrement).
101+
* Increment/decrement an item by given number (positive or negative for decrement)
100102
*
101103
* @param string $id
102104
* @param int $update
103-
* @param int|null $expireAt Expire item at ts.
105+
* @param int|null $expireAt Expire item at ts
104106
* @return void
105-
* @throws \InvalidArgumentException When increment is incorrect or the item is not a number.
107+
* @throws InvalidArgumentException When increment is incorrect or the item is not a number
106108
*/
107109
public function updateByAndGet(string $id, int $update, ?int $expireAt): int
108110
{
109111
if ($update === 0) {
110-
throw new \InvalidArgumentException('Update must be != 0');
112+
throw new InvalidArgumentException('Update must be != 0');
111113
}
114+
112115
$method = 'incrBy';
113116
if ($update < 0) {
114117
$method = 'decrBy';
115118
}
119+
116120
$redis = $this->_redis->pipeline();
117121
$redis->$method($id, abs($update));
118122
if ($expireAt) {
119123
$redis->expireAt($id, $expireAt);
120124
}
125+
121126
$response = $redis->exec();
122127

123128
return (int)$response[0];

lib/internal/Magento/Framework/Webapi/Backpressure/BackpressureContextFactory.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010

1111
use Magento\Framework\App\Backpressure\ContextInterface;
1212
use Magento\Framework\App\Backpressure\IdentityProviderInterface;
13+
use Magento\Framework\App\ObjectManager;
1314
use Magento\Framework\App\RequestInterface;
1415

1516
/**
16-
* Creates backpressure context for a request.
17+
* Creates backpressure context for a request
1718
*/
1819
class BackpressureContextFactory
1920
{
@@ -48,7 +49,7 @@ public function __construct(
4849
}
4950

5051
/**
51-
* Create context if possible for current request.
52+
* Create context if possible for current request
5253
*
5354
* @param string $service Service class
5455
* @param string $method Service method
@@ -62,14 +63,17 @@ public function create(string $service, string $method, string $endpoint): ?Cont
6263
return null;
6364
}
6465

65-
return new RestContext(
66-
$this->request,
67-
$this->identityProvider->fetchIdentity(),
68-
$this->identityProvider->fetchIdentityType(),
69-
$typeId,
70-
$service,
71-
$method,
72-
$endpoint
66+
return ObjectManager::getInstance()->create(
67+
RestContext::class,
68+
[
69+
$this->request,
70+
$this->identityProvider->fetchIdentity(),
71+
$this->identityProvider->fetchIdentityType(),
72+
$typeId,
73+
$service,
74+
$method,
75+
$endpoint
76+
]
7377
);
7478
}
7579
}

lib/internal/Magento/Framework/Webapi/Backpressure/BackpressureRequestTypeExtractorInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace Magento\Framework\Webapi\Backpressure;
1010

1111
/**
12-
* Extracts request type ID from endpoints.
12+
* Extracts request type ID from endpoints
1313
*/
1414
interface BackpressureRequestTypeExtractorInterface
1515
{

lib/internal/Magento/Framework/Webapi/Backpressure/CompositeRequestTypeExtractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace Magento\Framework\Webapi\Backpressure;
1010

1111
/**
12-
* Uses other extractors.
12+
* Uses other extractors
1313
*/
1414
class CompositeRequestTypeExtractor implements BackpressureRequestTypeExtractorInterface
1515
{

lib/internal/Magento/Framework/Webapi/Backpressure/RestContext.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
use Magento\Framework\App\Backpressure\ContextInterface;
1212
use Magento\Framework\App\RequestInterface;
1313

14+
/**
15+
* REST request context
16+
*/
1417
class RestContext implements ContextInterface
1518
{
1619
/**
@@ -108,7 +111,7 @@ public function getTypeId(): string
108111
}
109112

110113
/**
111-
* Service class name.
114+
* Service class name
112115
*
113116
* @return string
114117
*/
@@ -118,7 +121,7 @@ public function getService(): string
118121
}
119122

120123
/**
121-
* Service method.
124+
* Service method
122125
*
123126
* @return string
124127
*/
@@ -128,7 +131,7 @@ public function getMethod(): string
128131
}
129132

130133
/**
131-
* Endpoint route.
134+
* Endpoint route
132135
*
133136
* @return string
134137
*/

0 commit comments

Comments
 (0)