/** * Requests a list of or specific resource * * @param string $resource The resource to retrieve * @param mixed|null $id An id to append to the resource request * * @return array|bool|\stdClass */ public function resource($resource, $id = null) { try { $_response = (array) $this->get(Uri::segment([$resource, $id])); return array_get($_response, 'resource', false); } catch (\Exception $_ex) { $this->error('[dfe.instance-api-client] resource() call failure from instance "' . $this->instance->instance_id_text . '": ' . $_ex->getMessage(), Curl::getInfo()); return []; } }
/** * Makes a shout out to an instance's private back-end. Should be called bootyCall() ;) * * @param string $uri The REST uri (i.e. "/[rest|api][/v[1|2]]/db", "/rest/system/users", etc.) to retrieve * from the instance * @param array $payload Any payload to send with request * @param array $options Any options to pass to transport layer * @param string $method The HTTP method. Defaults to "POST" * * @return array|bool|\stdClass */ public function call($uri, $payload = [], $options = [], $method = Request::METHOD_POST) { $options[CURLOPT_HTTPHEADER] = array_merge(array_get($options, CURLOPT_HTTPHEADER, []), [EnterpriseDefaults::CONSOLE_X_HEADER . ': ' . $this->token]); try { $_response = Curl::request($method, Uri::segment([$this->resourceUri, $uri], false), $payload, $options); } catch (\Exception $_ex) { return false; } return $_response; }
/** * Makes a shout out to an instance's private back-end. Should be called bootyCall() ;) * * @param string $uri The REST uri (i.e. "/[rest|api][/v[1|2]]/db", "/rest/system/users", etc.) to retrieve from the instance * @param array $payload Any payload to send with request * @param array $options Any options to pass to transport layer * @param string $method The HTTP method. Defaults to "POST" * @param bool $object If true, the default, the response is returned as an object. If false, an array is returned. * * @return array|bool|\stdClass */ public function call($uri, $payload = [], $options = [], $method = Request::METHOD_POST, $object = true) { $_token = $this->generateToken(); $options['headers'] = array_merge(array_get($options, 'headers', []), [EnterpriseDefaults::CONSOLE_X_HEADER => $_token, 'Content-Type' => 'application/json', 'Accept' => 'application/json']); try { return $this->guzzleAny(Uri::segment([$this->getProvisionedEndpoint(), $uri], false), $payload, $options, $method, $object); } catch (\Exception $_ex) { return false; } }
/** * @param string|array $origin The parse_url value of origin * @param array $additional Additional origin(s) to allow * @param bool $isStar Set to true if the allowed origin is "*" * * @return bool|array false if not allowed, otherwise array of verbs allowed */ protected function _checkOrigin($origin, array $additional = [], &$isStar = false) { $_checklist = array_merge($this->_whitelist, $additional); foreach ($_checklist as $_hostInfo) { // Always start with defaults $_allowedVerbs = $this->_verbs; $_whiteGuy = $_hostInfo; if (is_array($_hostInfo)) { // If is_enabled prop not there, assuming enabled. if (!Scalar::boolval(IfSet::get($_hostInfo, 'is_enabled', true))) { continue; } if (null === ($_whiteGuy = IfSet::get($_hostInfo, 'host'))) { $this->_logger->error('whitelist entry missing "host" parameter'); continue; } if (isset($_hostInfo['verbs'])) { if (!in_array(Verbs::OPTIONS, $_hostInfo['verbs'])) { // add OPTION to allowed list $_hostInfo['verbs'][] = Verbs::OPTIONS; } $_allowedVerbs = $_hostInfo['verbs']; } } // All allowed? if (static::ALLOW_ALL == $_whiteGuy) { $isStar = true; return $_allowedVerbs; } if (false === ($_whiteParts = Uri::parse($_whiteGuy))) { $this->_logger->error('unable to parse "' . $_whiteGuy . '" whitelist entry'); continue; } $this->_logger->debug('whitelist "' . $_whiteGuy . '" > parts: ' . print_r($_whiteParts, true)); // Check for un-parsed origin, 'null' sent when testing js files locally if (is_array($origin) && Uri::compare($origin, $_whiteParts)) { // This origin is on the whitelist return $_allowedVerbs; } } return false; }