encrypter = $encrypter; $this->keyCreationService = $keyCreationService; } /** * Returns all of the API keys that exist for the given client. * * @param \Pterodactyl\Http\Requests\Api\Client\ClientApiRequest $request * @return array */ public function index(ClientApiRequest $request) { return $this->fractal->collection($request->user()->apiKeys) ->transformWith($this->getTransformer(ApiKeyTransformer::class)) ->toArray(); } /** * Store a new API key for a user's account. * * @param \Pterodactyl\Http\Requests\Api\Client\Account\StoreApiKeyRequest $request * @return array * * @throws \Pterodactyl\Exceptions\DisplayException * @throws \Pterodactyl\Exceptions\Model\DataValidationException */ public function store(StoreApiKeyRequest $request) { if ($request->user()->apiKeys->count() >= 5) { throw new DisplayException( 'You have reached the account limit for number of API keys.' ); } $key = $this->keyCreationService->setKeyType(ApiKey::TYPE_ACCOUNT)->handle([ 'user_id' => $request->user()->id, 'memo' => $request->input('description'), 'allowed_ips' => $request->input('allowed_ips') ?? [], ]); return $this->fractal->item($key) ->transformWith($this->getTransformer(ApiKeyTransformer::class)) ->addMeta([ 'secret_token' => $this->encrypter->decrypt($key->token), ]) ->toArray(); } public function delete() { } }