Skip to content

Commit

Permalink
Get rid of 2nd param & unset perm
Browse files Browse the repository at this point in the history
  • Loading branch information
RMartinOscar committed Nov 7, 2024
1 parent d2488e8 commit 33a227d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion app/Http/Controllers/Admin/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public function store(StoreApplicationApiKeyRequest $request): RedirectResponse
$this->keyCreationService->setKeyType(ApiKey::TYPE_APPLICATION)->handle([
'memo' => $request->input('memo'),
'user_id' => $request->user()->id,
], $request->getKeyPermissions());
'permissions' => $request->getKeyPermissions(),
]);

$this->alert->success('A new application API key has been generated for your account.')->flash();

Expand Down
6 changes: 3 additions & 3 deletions app/Services/Api/KeyCreationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ public function setKeyType(int $type): self
*
* @throws \App\Exceptions\Model\DataValidationException
*/
public function handle(array $data, array $permissions = []): ApiKey
public function handle(array $data): ApiKey
{
$data = array_merge($data, [
'key_type' => $this->keyType,
'identifier' => ApiKey::generateTokenIdentifier($this->keyType),
'token' => str_random(ApiKey::KEY_LENGTH),
]);

if ($this->keyType === ApiKey::TYPE_APPLICATION) {
$data['permissions'] = array_merge($data['permissions'] ?? [], $permissions);
if ($this->keyType !== ApiKey::TYPE_APPLICATION) {
unset($data['permissions']);
}

return ApiKey::query()->forceCreate($data);
Expand Down
3 changes: 2 additions & 1 deletion app/Services/Nodes/NodeAutoDeployService.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public function handle(Request $request, Node $node, ?bool $docker = false): ?st
$key = $this->keyCreationService->setKeyType(ApiKey::TYPE_APPLICATION)->handle([
'memo' => 'Automatically generated node deployment key.',
'user_id' => $request->user()->id,
], [Node::RESOURCE_NAME => AdminAcl::READ]);
'permissions' => [Node::RESOURCE_NAME => AdminAcl::READ],
]);
}

$token = $key->identifier . $key->token;
Expand Down

0 comments on commit 33a227d

Please sign in to comment.