/** * Handle a request * * @param ManifestJob $command * * * @return bool * @throws \Exception */ public function handle(ManifestJob $command) { \Log::debug('[dfe:manifest] begin'); if ($command->showManifest()) { $_manifest = ClusterManifest::createFromFile(base_path() . DIRECTORY_SEPARATOR . ConsoleDefaults::CLUSTER_MANIFEST_FILE); $_result = !$_manifest->existed() ? ErrorPacket::create() : SuccessPacket::make($_manifest->toArray()); // And then show it... if ($_manifest->existed()) { \Log::debug(' * Manifest found: ' . print_r($_manifest->all(), true)); } else { \Log::info(' * No manifest file found. Nothing to show.'); } } else { try { $_key = $command->noKeys() ? false : AppKey::createKey($command->getOwnerId(), $command->getOwnerType()); if ($_key) { $command->getOutput()->getVerbosity() == OutputInterface::VERBOSITY_VERBOSE && $command->getOutput()->writeln(' - generated client-id and secret: ' . $_key->client_id); } if ($command->createManifest()) { // Create a new manifest... $_manifest = ClusterManifest::make(base_path(), ['cluster-id' => config('dfe.cluster-id'), 'default-domain' => config('provisioning.default-domain'), 'signature-method' => config('dfe.signature-method'), 'storage-root' => config('provisioning.storage-root'), 'console-api-url' => config('dfe.security.console-api-url'), 'console-api-key' => config('dfe.security.console-api-key'), 'client-id' => !$_key ? null : $_key->client_id, 'client-secret' => !$_key ? null : $_key->client_secret]); $command->setResult($_result = SuccessPacket::make($_manifest->toArray(), Response::HTTP_CREATED)); } } catch (\Exception $_ex) { $command->setResult($_result = ErrorPacket::create(Response::HTTP_BAD_REQUEST)); } } \Log::debug('[dfe:manifest] end'); return $command; }
/** * Handle a request * * @param RegisterJob $command * * @return mixed * @throws \Exception */ public function handle(RegisterJob $command) { $_key = config('dfe.security.console-api-key'); try { $_owner = $command->getOwnerInfo(); // Generate the key $_key = AppKey::createKey($_owner->id, $_owner->type, ['server_secret' => $_key]); $this->debug('[dfe:register] Successfully created app key "' . $_key->client_id . '"'); $_result = SuccessPacket::make($_key->toArray(), Response::HTTP_CREATED); } catch (\Exception $_ex) { $this->error('[dfe:register] Exception while creating key: ' . $_ex->getMessage()); $_result = ErrorPacket::create(Response::HTTP_BAD_REQUEST, $_ex); } $command->publishResult($command->getJobId(), $_result); return $_result; }
/** {@InheritDoc} */ public function destroy($id) { try { $_model = call_user_func([$this->model, 'findOrFail'], $id); if (!$_model->delete()) { return ErrorPacket::create(\Illuminate\Http\Response::HTTP_INTERNAL_SERVER_ERROR, 'Delete of id "' . $id . '" failed.'); } return SuccessPacket::make(); } catch (\Exception $_ex) { return ErrorPacket::create(); } }
/** * Converts data to JSON and spits it out * * @param array $data * @param int $totalRows * @param int $totalFiltered * * @return \Illuminate\Http\JsonResponse */ protected function respond($data, $totalRows = null, $totalFiltered = null) { // Don't wrap if there are no totals if (!$this->dataTables || null === $totalRows && null === $totalFiltered) { return SuccessPacket::make($data); } $_response = ['draw' => (int) array_get($_REQUEST, 'draw'), 'recordsTotal' => (int) ($totalRows ?: 0), 'recordsFiltered' => (int) ($totalFiltered ?: $totalRows), 'data' => $this->prepareResponseData($data)]; return \Response::json($_response); }