Skip to content

Commit bba3cff

Browse files
committed
renamed licence with license, AI threw me a tantrum for that
1 parent 25256eb commit bba3cff

File tree

7 files changed

+123
-123
lines changed

7 files changed

+123
-123
lines changed

app/Http/Controllers/NetifyLicenceController.php renamed to app/Http/Controllers/NetifyLicenseController.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,70 +2,70 @@
22

33
namespace App\Http\Controllers;
44

5-
use App\Logic\NetifydLicenceRepository;
6-
use App\NetifydLicenceType;
5+
use App\Logic\NetifydLicenseRepository;
6+
use App\NetifydLicenseType;
77
use Exception;
88
use Illuminate\Http\JsonResponse;
99
use Illuminate\Support\Facades\Cache;
1010
use Illuminate\Support\Facades\Log;
1111

12-
class NetifyLicenceController extends Controller
12+
class NetifyLicenseController extends Controller
1313
{
14-
public function community(NetifydLicenceRepository $licenceProvider): JsonResponse
14+
public function community(NetifydLicenseRepository $licenseProvider): JsonResponse
1515
{
16-
return $this->run($licenceProvider, NetifydLicenceType::COMMUNITY);
16+
return $this->run($licenseProvider, NetifydLicenseType::COMMUNITY);
1717
}
1818

19-
private function run(NetifydLicenceRepository $licenceProvider, NetifydLicenceType $licenceType): JsonResponse
19+
private function run(NetifydLicenseRepository $licenseProvider, NetifydLicenseType $licenseType): JsonResponse
2020
{
2121
// If license is in cache, return it.
22-
if (Cache::has($licenceType->cacheLabel())) {
23-
Log::debug('Requested netifyd licence found in cache, returning it.');
22+
if (Cache::has($licenseType->cacheLabel())) {
23+
Log::debug('Requested netifyd license found in cache, returning it.');
2424

25-
return response()->json(Cache::get($licenceType->cacheLabel()));
25+
return response()->json(Cache::get($licenseType->cacheLabel()));
2626
}
2727

28-
Log::debug('Requested netifyd licence not found in cache, checking remote server.');
28+
Log::debug('Requested netifyd license not found in cache, checking remote server.');
2929
// Check if the community license is on the remote server.
3030
try {
31-
$licences = $licenceProvider->listLicences();
31+
$licenses = $licenseProvider->listLicenses();
3232
} catch (Exception $e) {
3333
return response()->json(['message' => $e->getMessage()], 500);
3434
}
35-
$license = array_find($licences, fn ($item) => $item['issued_to'] == $licenceType->label());
35+
$license = array_find($licenses, fn ($item) => $item['issued_to'] == $licenseType->label());
3636
// If it doesn't exist, create it.
3737
if ($license == null) {
38-
Log::debug('Netifyd licence not found on remote server, creating it.');
38+
Log::debug('Netifyd license not found on remote server, creating it.');
3939
try {
40-
$license = $licenceProvider->createLicence($licenceType);
40+
$license = $licenseProvider->createLicense($licenseType);
4141
} catch (Exception $e) {
4242
return response()->json(['message' => $e->getMessage()], 500);
4343
}
4444
}
4545
// Got license, checking if everything is in place.
46-
Log::debug('Netifyd licence recovered from remote server, checking if it can be renewed.');
46+
Log::debug('Netifyd license recovered from remote server, checking if it can be renewed.');
4747
$expiration = $license['expire_at']['unix'];
4848
$creation = $license['created_at']['unix'];
4949
$renewalThreshold = ($expiration - $creation) / 2 + $creation;
5050
$now = now()->unix();
5151
if ($renewalThreshold < $now) {
52-
Log::debug('Netifyd licence can be renewed, renewing it.');
52+
Log::debug('Netifyd license can be renewed, renewing it.');
5353
try {
54-
$license = $licenceProvider->renewLicence($licenceType, $license['serial']);
54+
$license = $licenseProvider->renewLicense($licenseType, $license['serial']);
5555
} catch (Exception $e) {
5656
return response()->json(['message' => $e->getMessage()], 500);
5757
}
5858
}
5959

6060
$expiration = $license['expire_at']['unix'];
6161
$creation = $license['created_at']['unix'];
62-
Cache::put($licenceType->cacheLabel(), $license, ($expiration - $creation) / 2);
62+
Cache::put($licenseType->cacheLabel(), $license, ($expiration - $creation) / 2);
6363

6464
return response()->json($license);
6565
}
6666

67-
public function enterprise(NetifydLicenceRepository $licenceProvider): JsonResponse
67+
public function enterprise(NetifydLicenseRepository $licenseProvider): JsonResponse
6868
{
69-
return $this->run($licenceProvider, NetifydLicenceType::ENTERPRISE);
69+
return $this->run($licenseProvider, NetifydLicenseType::ENTERPRISE);
7070
}
7171
}
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,68 +2,68 @@
22

33
namespace App\Logic;
44

5-
use App\NetifydLicenceType;
5+
use App\NetifydLicenseType;
66
use Exception;
77
use Illuminate\Http\Client\ConnectionException;
88
use Illuminate\Http\Client\RequestException;
99
use Illuminate\Support\Facades\Http;
1010

11-
class NetifydLicenceRepository
11+
class NetifydLicenseRepository
1212
{
1313
public function __construct(private string $endpoint, private string $apiKey) {}
1414

1515
/**
1616
* @throws Exception
1717
*/
18-
public function listLicences(): array
18+
public function listLicenses(): array
1919
{
2020
try {
2121
return Http::withHeader('x-api-key', $this->apiKey)
2222
->get($this->endpoint.'/api/v2/integrator/licenses?format=netifyd')
2323
->throw()
2424
->json('data');
2525
} catch (ConnectionException|RequestException $e) {
26-
throw new Exception('Could not list licences from netifyd: '.$e->getMessage());
26+
throw new Exception('Could not list licenses from netifyd: '.$e->getMessage());
2727
}
2828
}
2929

3030
/**
3131
* @throws Exception
3232
*/
33-
public function createLicence(NetifydLicenceType $licenceType): array
33+
public function createLicense(NetifydLicenseType $licenseType): array
3434
{
3535
try {
3636
return Http::withHeader('x-api-key', $this->apiKey)
3737
->post(config('netifyd.endpoint').'/api/v2/integrator/licenses', [
3838
'format' => 'object',
39-
'issued_to' => $licenceType->label(),
40-
'duration_days' => $licenceType->durationDays(),
41-
'description' => 'License provided to'.$licenceType->label().'instances.',
39+
'issued_to' => $licenseType->label(),
40+
'duration_days' => $licenseType->durationDays(),
41+
'description' => 'License provided to'.$licenseType->label().'instances.',
4242
'entitlements' => [
4343
'netify-proc-aggregator',
4444
'netify-proc-flow-actions',
4545
],
4646
])->throw()
4747
->json('data');
4848
} catch (ConnectionException|RequestException $e) {
49-
throw new Exception('Could not create licence on netifyd: '.$e->getMessage());
49+
throw new Exception('Could not create license on netifyd: '.$e->getMessage());
5050
}
5151
}
5252

5353
/**
5454
* @throws Exception
5555
*/
56-
public function renewLicence(NetifydLicenceType $licenceType, string $serial): array
56+
public function renewLicense(NetifydLicenseType $licenseType, string $serial): array
5757
{
5858
try {
5959
return Http::withHeader('x-api-key', config('netifyd.api-key'))
6060
->post(config('netifyd.endpoint').'/api/v2/integrator/licenses/'.$serial.'/renew', [
61-
'duration_days' => $licenceType->durationDays(),
61+
'duration_days' => $licenseType->durationDays(),
6262
])->throw()
6363
->json('data');
6464

6565
} catch (ConnectionException|RequestException $e) {
66-
throw new Exception('Could not renew licence on netifyd: '.$e->getMessage());
66+
throw new Exception('Could not renew license on netifyd: '.$e->getMessage());
6767
}
6868
}
6969
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Illuminate\Support\Str;
66

7-
enum NetifydLicenceType: string
7+
enum NetifydLicenseType: string
88
{
99
case COMMUNITY = 'community';
1010
case ENTERPRISE = 'enterprise';

app/Providers/AppServiceProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace App\Providers;
44

55
use App\Logic\LicenceVerification;
6-
use App\Logic\NetifydLicenceRepository;
6+
use App\Logic\NetifydLicenseRepository;
77
use Illuminate\Support\ServiceProvider;
88

99
class AppServiceProvider extends ServiceProvider
@@ -16,8 +16,8 @@ public function register(): void
1616
$this->app->singleton(LicenceVerification::class, function () {
1717
return new LicenceVerification(config('repositories.endpoints.enterprise'), config('repositories.endpoints.community'));
1818
});
19-
$this->app->singleton(NetifydLicenceRepository::class, function () {
20-
return new NetifydLicenceRepository(config('netifyd.endpoint'), config('netifyd.api-key'));
19+
$this->app->singleton(NetifydLicenseRepository::class, function () {
20+
return new NetifydLicenseRepository(config('netifyd.endpoint'), config('netifyd.api-key'));
2121
});
2222
}
2323

routes/api.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<?php
22

3-
use App\Http\Controllers\NetifyLicenceController;
3+
use App\Http\Controllers\NetifyLicenseController;
44
use App\Http\Middleware\CommunityLicenceCheck;
55
use App\Http\Middleware\EnterpriseLicenceCheck;
66
use App\Http\Middleware\ForceBasicAuth;
77
use Illuminate\Support\Facades\Route;
88

99
Route::prefix('/netifyd')->group(function () {
10-
Route::get('/licence', [NetifyLicenceController::class, 'community']);
10+
Route::get('/license', [NetifyLicenseController::class, 'community']);
1111
Route::middleware(ForceBasicAuth::class)->group(function () {
12-
Route::get('/enterprise/licence', [NetifyLicenceController::class, 'enterprise'])
12+
Route::get('/enterprise/license', [NetifyLicenseController::class, 'enterprise'])
1313
->middleware(EnterpriseLicenceCheck::class);
1414

15-
Route::get('/community/licence', [NetifyLicenceController::class, 'enterprise'])
15+
Route::get('/community/license', [NetifyLicenseController::class, 'enterprise'])
1616
->middleware(CommunityLicenceCheck::class);
1717
});
1818
});

0 commit comments

Comments
 (0)