Skip to content

Commit 9f80bc8

Browse files
committed
Make permissions endpoint configurable
Added a 'permissions_endpoint' config option to allow customization of the permissions API endpoint. Updated PermissionsClient to use this configurable endpoint, and adjusted tests to set the endpoint accordingly.
1 parent cbcf67b commit 9f80bc8

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

src/Services/PermissionsClient.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
class PermissionsClient
1010
{
1111
protected ApiGatewayClientInterface $gateway;
12+
protected string $endpoint;
1213

1314
public function __construct(ApiGatewayClientInterface $gateway)
1415
{
1516
$this->gateway = $gateway;
17+
$this->endpoint = rtrim(config('microservice.permissions_endpoint', '/auth/permissions'), '/');
1618
}
1719

1820
public function getAccessFor(AccessUserInterface $user): array
@@ -21,7 +23,7 @@ public function getAccessFor(AccessUserInterface $user): array
2123
$ttl = config('microservice.permissions_cache_ttl', 60);
2224

2325
return Cache::remember($cacheKey, $ttl, function () use ($user) {
24-
$response = $this->gateway->get('/auth/permissions/' . $user->getAuthIdentifier());
26+
$response = $this->gateway->get($this->endpoint . '/' . $user->getAuthIdentifier());
2527

2628
if ($response->failed()) {
2729
throw new \RuntimeException("Failed to fetch permissions from API Gateway.");

src/config/microservice.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,5 @@
140140
| environment variable to control cache duration.
141141
*/
142142
'permissions_cache_ttl' => env('PERMISSIONS_CACHE_TTL', 60),
143+
'permissions_endpoint' => env('PERMISSIONS_ENDPOINT', '/auth/permissions')
143144
];

tests/Services/PermissionClientTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function json() { return ['roles' => ['admin'], 'permissions' => ['edit.p
3737
};
3838
$this->app->bind(ApiGatewayClientInterface::class, fn () => $this->gateway);
3939
Cache::flush();
40+
$this->app['config']->set('microservice.permissions_endpoint', '/permissions');
4041
}
4142

4243
protected function getPackageProviders($app)

0 commit comments

Comments
 (0)