├── .gitignore ├── LICENSE ├── README.md ├── composer.json ├── src └── Kong │ ├── Apis │ ├── AbstractApi.php │ ├── Api.php │ ├── ApiInterface.php │ ├── Certificate.php │ ├── CertificateInterface.php │ ├── Consumer.php │ ├── ConsumerInterface.php │ ├── Node.php │ ├── NodeInterface.php │ ├── Plugin.php │ ├── PluginInterface.php │ ├── Plugins │ │ ├── BasicAuth.php │ │ ├── BasicAuthInterface.php │ │ ├── Jwt.php │ │ ├── JwtInterface.php │ │ ├── KeyAuth.php │ │ └── KeyAuthInterface.php │ ├── Route.php │ ├── RouteInterface.php │ ├── Service.php │ ├── ServiceInterface.php │ ├── Sni.php │ ├── SniInterface.php │ ├── Upstream.php │ └── UpstreamInterface.php │ ├── Exceptions │ ├── InvalidHttpMethodException.php │ ├── InvalidUrlException.php │ └── KongHttpException.php │ └── Kong.php └── tests └── .gitignore /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### JetBrains template 3 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 4 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 5 | 6 | # User-specific stuff: 7 | .idea 8 | 9 | # Sensitive or high-churn files: 10 | .idea/dataSources/ 11 | .idea/dataSources.ids 12 | .idea/dataSources.xml 13 | .idea/dataSources.local.xml 14 | .idea/sqlDataSources.xml 15 | .idea/dynamic.xml 16 | .idea/uiDesigner.xml 17 | 18 | # Gradle: 19 | .idea/gradle.xml 20 | .idea/libraries 21 | 22 | # Mongo Explorer plugin: 23 | .idea/mongoSettings.xml 24 | 25 | ## File-based project format: 26 | *.iws 27 | 28 | ## Plugin-specific files: 29 | 30 | # IntelliJ 31 | /out/ 32 | 33 | # mpeltonen/sbt-idea plugin 34 | .idea_modules/ 35 | 36 | # JIRA plugin 37 | atlassian-ide-plugin.xml 38 | 39 | # Crashlytics plugin (for Android Studio and IntelliJ) 40 | com_crashlytics_export_strings.xml 41 | crashlytics.properties 42 | crashlytics-build.properties 43 | fabric.properties 44 | 45 | composer.lock 46 | vendor -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Kris 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # kong-php 2 | A PHP7 compliant library for interacting with the Kong Gateway Admin API. 3 | 4 | ## Kong Compatibility 5 | Currently supporting Kong >= 0.10.0 6 | 7 | ## Requirements 8 | 9 | - [cURL](http://php.net/manual/en/book.curl.php) 10 | - PHP 7.0+ 11 | 12 | ## Installation 13 | 14 | ### Using [Composer](https://getcomposer.org) 15 | 16 | To install kong-php with Composer, just add the following to your `composer.json` file: 17 | 18 | ```json 19 | { 20 | "require-dev": { 21 | "therealgambo/kong-php": "0.10.*" 22 | } 23 | } 24 | ``` 25 | 26 | or by running the following command: 27 | 28 | ```shell 29 | composer require therealgambo/kong-php 30 | ``` 31 | 32 | ## Usage 33 | 34 | ### PHP 35 | 36 | Retrieving Kong node information 37 | ```php 38 | $kong = new \TheRealGambo\Kong\Kong(KONG_URL, KONG_PORT); 39 | $node = $kong->getNodeObject(); 40 | 41 | print_r($node->getInformation()); 42 | ``` 43 | 44 | Retrieving a list of all API's on Kong 45 | ```php 46 | $kong = new \TheRealGambo\Kong\Kong(KONG_URL, KONG_PORT); 47 | $apis = $kong->getApiObject(); 48 | 49 | print_r($apis->list()); 50 | ``` 51 | 52 | ## Versions 53 | 54 | All releases will match for the stable versions of Kong released >= 0.10.0 55 | 56 | This ensures stability and resillence within the library reducing any compatibility issues between versions. 57 | 58 | ## License 59 | 60 | Kong-php is open-source software and licensed under the [MIT License](http://opensource.org/licenses/MIT). 61 | 62 | Kong is Copyright Mashape, inc. -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "therealgambo/kong-php", 3 | "description": "A PHP7 compliant library for interacting with the Kong Gateway Admin API.", 4 | "keywords": ["kong", "kong gateway", "mashape-kong", "api-gateway"], 5 | "type": "Library", 6 | "require": { 7 | "php": ">=7.0", 8 | "mashape/unirest-php": "3.*" 9 | }, 10 | "require-dev": { 11 | "phpunit/phpunit": "~4.0", 12 | "mockery/mockery": "^0.9.4" 13 | }, 14 | "support": { 15 | "issues": "https://github.com/therealgambo/kong-php/issues" 16 | }, 17 | "license": "MIT", 18 | "author": "therealgambo (https://github.com/therealgambo)", 19 | "autoload": { 20 | "psr-4": { 21 | "TheRealGambo\\Kong\\": "src/Kong" 22 | } 23 | }, 24 | "autoload-dev": { 25 | "psr-4": { 26 | "Tests\\": "tests/" 27 | } 28 | }, 29 | "minimum-stability": "dev" 30 | } 31 | -------------------------------------------------------------------------------- /src/Kong/Apis/AbstractApi.php: -------------------------------------------------------------------------------- 1 | url = $url; 50 | $this->port = $port; 51 | } 52 | 53 | /** 54 | * Make a delete request 55 | * 56 | * @param string $uri 57 | * @param array $headers 58 | * 59 | * @return array|\stdClass 60 | */ 61 | public function deleteRequest($uri, array $headers = []) 62 | { 63 | return $this->request(Method::DELETE, $uri, [], [], $headers); 64 | } 65 | 66 | /** 67 | * Make a get request 68 | * 69 | * @param string $uri 70 | * @param array $params 71 | * @param array $headers 72 | * 73 | * @return array|\stdClass 74 | */ 75 | public function getRequest($uri, array $params = [], array $headers = []) 76 | { 77 | return $this->request(Method::GET, $uri, $params, [], $headers); 78 | } 79 | 80 | /** 81 | * Make a patch request 82 | * 83 | * @param string $uri 84 | * @param array $body 85 | * @param array $headers 86 | * 87 | * @return array|\stdClass 88 | */ 89 | public function patchRequest($uri, array $body = [], array $headers = []) 90 | { 91 | return $this->request(Method::PATCH, $uri, [], $body, $headers); 92 | } 93 | 94 | /** 95 | * Make a post request 96 | * 97 | * @param string $uri 98 | * @param array $body 99 | * @param array $headers 100 | * 101 | * @return array|\stdClass 102 | */ 103 | public function postRequest($uri, array $body = [], array $headers = []) 104 | { 105 | return $this->request(Method::POST, $uri, [], $body, $headers); 106 | } 107 | 108 | /** 109 | * Make a put request 110 | * 111 | * @param string $uri 112 | * @param array $body 113 | * @param array $headers 114 | * 115 | * @return array|\stdClass 116 | */ 117 | public function putRequest($uri, array $body = [], array $headers = []) 118 | { 119 | return $this->request(Method::PUT, $uri, [], $body, $headers); 120 | } 121 | 122 | /** 123 | * Make a request to the Kong Admin API 124 | * 125 | * @param string $http_verb 126 | * @param string $uri 127 | * @param array $params 128 | * @param array $body 129 | * @param array $headers 130 | * 131 | * @throws InvalidHttpMethodException 132 | * @throws KongHttpException 133 | * 134 | * @return array|\stdClass 135 | */ 136 | public function request($http_verb, $uri, array $params = [], array $body = [], array $headers = []) 137 | { 138 | // Format the URL for the API request 139 | $api = $this->url . ':' . $this->port . '/' . $uri; 140 | 141 | // Transform all request body contents to json 142 | $body = Request\Body::json($body); 143 | 144 | try { 145 | switch ($http_verb) { 146 | case Method::GET: 147 | $request = Request::get($api, $headers, $params); 148 | break; 149 | case Method::POST: 150 | $request = Request::post($api, $headers, $body); 151 | break; 152 | case Method::PUT: 153 | $request = Request::put($api, $headers, $body); 154 | break; 155 | case Method::PATCH: 156 | $request = Request::patch($api, $headers, $body); 157 | break; 158 | case Method::DELETE: 159 | $request = Request::delete($api, $headers); 160 | break; 161 | default: 162 | throw new InvalidHttpMethodException('Invalid HTTP request method'); 163 | } 164 | } catch (\Exception $e) { 165 | throw new KongHttpException($e->getMessage()); 166 | } 167 | 168 | // Store the response object 169 | $this->response = $request; 170 | 171 | // Return the body response 172 | return $request->body; 173 | } 174 | 175 | /** 176 | * Return the response object for the last request 177 | * 178 | * @return Response 179 | */ 180 | public function getResponse(): Response 181 | { 182 | return $this->response; 183 | } 184 | 185 | /** 186 | * Return the HTTP status code for the last request 187 | * 188 | * @return integer 189 | */ 190 | public function getStatusCode() 191 | { 192 | return $this->getResponse()->code; 193 | } 194 | 195 | /** 196 | * Return the raw body response content; 197 | * 198 | * @return string 199 | */ 200 | public function getRawBody() 201 | { 202 | return $this->getResponse()->raw_body; 203 | } 204 | 205 | /** 206 | * Create a valid request body, removing all non valid options 207 | * 208 | * @param array $body 209 | * @param array $merge 210 | * 211 | * @return array 212 | */ 213 | public function createRequestBody(array $body, array $merge = []) 214 | { 215 | $result = []; 216 | 217 | foreach ($body as $key => $value) { 218 | if (!in_array($key, $this->allowedOptions) && strpos($key, 'config.') < 0) { 219 | continue; 220 | } 221 | 222 | $result[$key] = $value; 223 | } 224 | 225 | return array_merge($result, $merge); 226 | } 227 | 228 | /** 229 | * Set the array of allowed options for each request 230 | * 231 | * @param array $options 232 | * 233 | * @return void 234 | */ 235 | public function setAllowedOptions(array $options = []) 236 | { 237 | $this->allowedOptions = $options; 238 | } 239 | } 240 | -------------------------------------------------------------------------------- /src/Kong/Apis/Api.php: -------------------------------------------------------------------------------- 1 | setAllowedOptions($this->apiAllowedOptions); 34 | $body = $this->createRequestBody($body); 35 | 36 | return $this->postRequest('apis', $body, $headers); 37 | } 38 | 39 | /** 40 | * Delete an API endpoint from Kong 41 | * 42 | * @see https://getkong.org/docs/0.13.x/admin-api/#delete-api 43 | * 44 | * @param string $identifier 45 | * @param array $headers 46 | * 47 | * @return array|\stdClass 48 | */ 49 | public function delete($identifier, array $headers = []) 50 | { 51 | return $this->deleteRequest('apis/' . $identifier, $headers); 52 | } 53 | 54 | /** 55 | * Retrieve information about a specific API from Kong 56 | * 57 | * @see https://getkong.org/docs/0.13.x/admin-api/#retrieve-api 58 | * 59 | * @param string $identifier 60 | * @param array $params 61 | * @param array $headers 62 | * 63 | * @return array|\stdClass 64 | */ 65 | public function get($identifier, array $params = [], array $headers = []) 66 | { 67 | return $this->getRequest('apis/' . $identifier, $params, $headers); 68 | } 69 | 70 | /** 71 | * List all API's in Kong 72 | * 73 | * @see https://getkong.org/docs/0.13.x/admin-api/#list-apis 74 | * 75 | * @param array $params 76 | * @param array $headers 77 | * 78 | * @return array|\stdClass 79 | */ 80 | public function list(array $params = [], array $headers = []) 81 | { 82 | return $this->getRequest('apis', $params, $headers); 83 | } 84 | 85 | /** 86 | * Update an API on Kong 87 | * 88 | * @see https://getkong.org/docs/0.13.x/admin-api/#update-api 89 | * 90 | * @param string $identifier 91 | * @param array $body 92 | * @param array $headers 93 | * 94 | * @return array|\stdClass 95 | */ 96 | public function update($identifier, array $body = [], array $headers = []) 97 | { 98 | $this->setAllowedOptions($this->apiAllowedOptions); 99 | $body = $this->createRequestBody($body); 100 | 101 | return $this->patchRequest('apis' . $identifier, $body, $headers); 102 | } 103 | 104 | /** 105 | * Update or Create an API on Kong 106 | * 107 | * @see https://getkong.org/docs/0.13.x/admin-api/#update-or-create-api 108 | * 109 | * @param array $body 110 | * @param array $headers 111 | * 112 | * @return array|\stdClass 113 | */ 114 | public function updateOrCreate(array $body = [], array $headers = []) 115 | { 116 | $this->setAllowedOptions(array_merge($this->apiAllowedOptions, ['id'])); 117 | $body = $this->createRequestBody($body); 118 | 119 | return $this->putRequest('apis', $body, $headers); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/Kong/Apis/ApiInterface.php: -------------------------------------------------------------------------------- 1 | setAllowedOptions($this->certificateAllowedOptions); 27 | $body = $this->createRequestBody($body); 28 | 29 | return $this->postRequest('certificates', $body, $headers); 30 | } 31 | 32 | /** 33 | * Delete a specific certificate from Kong 34 | * 35 | * @see https://getkong.org/docs/0.13.x/admin-api/#delete-certificate 36 | * 37 | * @param string $identifier 38 | * @param array $headers 39 | * 40 | * @return array|\stdClass 41 | */ 42 | public function delete($identifier, array $headers = []) 43 | { 44 | return $this->deleteRequest('certificates/' . $identifier, $headers); 45 | } 46 | 47 | /** 48 | * Retrieve a specific certificate from Kong 49 | * 50 | * @see https://getkong.org/docs/0.13.x/admin-api/#retrieve-certificate 51 | * 52 | * @param string $identifier 53 | * @param array $params 54 | * @param array $headers 55 | * 56 | * @return array|\stdClass 57 | */ 58 | public function get($identifier, array $params = [], array $headers = []) 59 | { 60 | return $this->getRequest('certificates/' . $identifier, $params, $headers); 61 | } 62 | 63 | /** 64 | * Retrieve all certificates from Kong 65 | * 66 | * @see https://getkong.org/docs/0.13.x/admin-api/#list-certificates 67 | * 68 | * @param array $params 69 | * @param array $headers 70 | * 71 | * @return array|\stdClass 72 | */ 73 | public function list(array $params = [], array $headers = []) 74 | { 75 | return $this->getRequest('certificates', $params, $headers); 76 | } 77 | 78 | /** 79 | * Update a certificate on Kong 80 | * 81 | * @see https://getkong.org/docs/0.13.x/admin-api/#update-certificate 82 | * 83 | * @param string $identifier 84 | * @param array $body 85 | * @param array $headers 86 | * 87 | * @return array|\stdClass 88 | */ 89 | public function update($identifier, array $body = [], array $headers = []) 90 | { 91 | $this->setAllowedOptions($this->certificateAllowedOptions); 92 | $body = $this->createRequestBody($body); 93 | 94 | return $this->patchRequest('certificates/' . $identifier, $body, $headers); 95 | } 96 | 97 | /** 98 | * Update or Create a certificate on Kong 99 | * 100 | * @see https://getkong.org/docs/0.13.x/admin-api/#update-or-create-certificate 101 | * 102 | * @param array $body 103 | * @param array $headers 104 | * 105 | * @return array|\stdClass 106 | */ 107 | public function updateOrCreate(array $body = [], array $headers = []) 108 | { 109 | $this->setAllowedOptions(array_merge($this->certificateAllowedOptions, ['id'])); 110 | $body = $this->createRequestBody($body); 111 | 112 | return $this->putRequest('certificates', $body, $headers); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/Kong/Apis/CertificateInterface.php: -------------------------------------------------------------------------------- 1 | setAllowedOptions($this->consumerAllowedOptions); 27 | $body = $this->createRequestBody($body); 28 | 29 | return $this->postRequest('consumers', $body, $headers); 30 | } 31 | 32 | /** 33 | * Delete a consumer from Kong 34 | * 35 | * @see https://getkong.org/docs/0.13.x/admin-api/#delete-consumer 36 | * 37 | * @param string $identifier 38 | * @param array $headers 39 | * 40 | * @return array|\stdClass 41 | */ 42 | public function delete($identifier, array $headers = []) 43 | { 44 | return $this->deleteRequest('consumers/' . $identifier, $headers); 45 | } 46 | 47 | /** 48 | * Retrieve information about a consumer from Kong 49 | * 50 | * @see https://getkong.org/docs/0.13.x/admin-api/#retrieve-consumer 51 | * 52 | * @param string $identifier 53 | * @param array $params 54 | * @param array $headers 55 | * 56 | * @return array|\stdClass 57 | */ 58 | public function get($identifier, array $params = [], array $headers = []) 59 | { 60 | return $this->getRequest('consumers/' . $identifier, $params, $headers); 61 | } 62 | 63 | /** 64 | * Retrieve information about a specific plugin assigned to a Kong consumer 65 | * 66 | * @see https://github.com/Mashape/kong/pull/2714 67 | * 68 | * @param string $identifier 69 | * @param string $plugin_identifier 70 | * @param array $params 71 | * @param array $headers 72 | * 73 | * @return array|\stdClass 74 | */ 75 | public function getConsumerPlugin($identifier, $plugin_identifier, array $params = [], array $headers = []) 76 | { 77 | return $this->getRequest('consumers/' . $identifier . '/plugins/' . $plugin_identifier, $params, $headers); 78 | } 79 | 80 | /** 81 | * Retrieve all consumers from Kong 82 | * 83 | * @see https://getkong.org/docs/0.13.x/admin-api/#list-consumers 84 | * 85 | * @param array $params 86 | * @param array $headers 87 | * 88 | * @return array|\stdClass 89 | */ 90 | public function list(array $params = [], array $headers = []) 91 | { 92 | return $this->getRequest('consumers', $params, $headers); 93 | } 94 | 95 | /** 96 | * Retrieve all plugins that are assigned to a Kong consumer 97 | * 98 | * @see https://github.com/Mashape/kong/pull/2714 99 | * 100 | * @param string $identifier 101 | * @param array $params 102 | * @param array $headers 103 | * 104 | * @return array|\stdClass 105 | */ 106 | public function listConsumerPlugins($identifier, array $params = [], array $headers = []) 107 | { 108 | return $this->getRequest('consumers/' . $identifier . '/plugins', $params, $headers); 109 | } 110 | 111 | /** 112 | * Update a consumer in Kong 113 | * 114 | * @see https://getkong.org/docs/0.13.x/admin-api/#update-consumer 115 | * 116 | * @param string $identifier 117 | * @param array $body 118 | * @param array $headers 119 | * 120 | * @return array|\stdClass 121 | */ 122 | public function update($identifier, array $body = [], array $headers = []) 123 | { 124 | $this->setAllowedOptions($this->consumerAllowedOptions); 125 | $body = $this->createRequestBody($body); 126 | 127 | return $this->patchRequest('consumers/' . $identifier, $body, $headers); 128 | } 129 | 130 | /** 131 | * Update or Create a consumer in Kong 132 | * 133 | * @see https://getkong.org/docs/0.13.x/admin-api/#update-or-create-consumer 134 | * 135 | * @param array $body 136 | * @param array $headers 137 | * 138 | * @return array|\stdClass 139 | */ 140 | public function updateOrCreate(array $body = [], array $headers = []) 141 | { 142 | $this->setAllowedOptions(array_merge($this->consumerAllowedOptions, ['id'])); 143 | $body = $this->createRequestBody($body); 144 | 145 | return $this->putRequest('consumers', $body, $headers); 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /src/Kong/Apis/ConsumerInterface.php: -------------------------------------------------------------------------------- 1 | getRequest('', [], $headers); 19 | } 20 | 21 | /** 22 | * Retrieve the status of the Kong node 23 | * 24 | * @see https://getkong.org/docs/0.10.x/admin-api/#retrieve-node-status 25 | * 26 | * @param array $headers 27 | * 28 | * @return array|\stdClass 29 | */ 30 | public function getStatus(array $headers = []) 31 | { 32 | return $this->getRequest('status', [], $headers); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Kong/Apis/NodeInterface.php: -------------------------------------------------------------------------------- 1 | setAllowedOptions($this->pluginAllowedOptions); 27 | $body = $this->createRequestBody($body); 28 | 29 | return $this->postRequest('plugins', $body, $headers); 30 | } 31 | 32 | /** 33 | * Remove a plugin from an API 34 | * 35 | * @see https://getkong.org/docs/0.13.x/admin-api/#delete-plugin 36 | * 37 | * @param string $api_identifier 38 | * @param string $identifier 39 | * @param array $headers 40 | * 41 | * @return array|\stdClass 42 | */ 43 | public function delete($api_identifier, $identifier, array $headers = []) 44 | { 45 | return $this->deleteRequest('apis/' . $api_identifier . '/plugins/' . $identifier, $headers); 46 | } 47 | 48 | /** 49 | * Retrieve information about a specific plugin from Kong 50 | * 51 | * @see https://getkong.org/docs/0.13.x/admin-api/#retrieve-plugin 52 | * 53 | * @param string $identifier 54 | * @param array $params 55 | * @param array $headers 56 | * 57 | * @return array|\stdClass 58 | */ 59 | public function get($identifier, array $params = [], array $headers = []) 60 | { 61 | return $this->getRequest('plugins/' . $identifier, $params, $headers); 62 | } 63 | 64 | /** 65 | * Retrieve all available plugins from Kong 66 | * 67 | * @see https://getkong.org/docs/0.13.x/admin-api/#retrieve-enabled-plugins 68 | * 69 | * @param array $params 70 | * @param array $headers 71 | * 72 | * @return array|\stdClass 73 | */ 74 | public function getEnabledPlugins(array $params = [], array $headers = []) 75 | { 76 | return $this->getRequest('plugins/enabled', $params, $headers); 77 | } 78 | 79 | /** 80 | * Retrieve the schema for a specific plugin from Kong 81 | * 82 | * @see https://getkong.org/docs/0.13.x/admin-api/#retrieve-plugin-schema 83 | * 84 | * @param string $identifier 85 | * @param array $params 86 | * @param array $headers 87 | * 88 | * @return array|\stdClass 89 | */ 90 | public function getPluginSchema($identifier, array $params = [], array $headers = []) 91 | { 92 | return $this->getRequest('plugins/schema/' . $identifier, [], $headers); 93 | } 94 | 95 | /** 96 | * Retrieve all plugins configured from Kong 97 | * 98 | * @see https://getkong.org/docs/0.13.x/admin-api/#list-all-plugins 99 | * 100 | * @param array $params 101 | * @param array $headers 102 | * 103 | * @return array|\stdClass 104 | */ 105 | public function list(array $params = [], array $headers = []) 106 | { 107 | return $this->getRequest('plugins', $params, $headers); 108 | } 109 | 110 | /** 111 | * Update a plugins configuration on Kong 112 | * 113 | * @see https://getkong.org/docs/0.13.x/admin-api/#update-plugin 114 | * 115 | * @param string $api_identifier 116 | * @param string $identifier 117 | * @param array $body 118 | * @param array $headers 119 | * 120 | * @return array|\stdClass 121 | */ 122 | public function update($api_identifier, $identifier, array $body = [], array $headers = []) 123 | { 124 | $this->setAllowedOptions($this->pluginAllowedOptions); 125 | $body = $this->createRequestBody($body); 126 | 127 | return $this->patchRequest('apis/' . $api_identifier . '/plugins/' . $identifier, $body, $headers); 128 | } 129 | 130 | /** 131 | * Update or create a plugin on Kong 132 | * 133 | * @see https://getkong.org/docs/0.13.x/admin-api/#update-or-add-plugin 134 | * 135 | * @param string $api_identifier 136 | * @param array $body 137 | * @param array $headers 138 | * 139 | * @return array|\stdClass 140 | */ 141 | public function updateOrAdd($api_identifier, array $body = [], array $headers = []) 142 | { 143 | $this->setAllowedOptions(array_merge($this->pluginAllowedOptions, ['id'])); 144 | $body = $this->createRequestBody($body); 145 | 146 | return $this->putRequest('apis/' . $api_identifier . '/plugins', $body, $headers); 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /src/Kong/Apis/PluginInterface.php: -------------------------------------------------------------------------------- 1 | url, $this->port); 23 | 24 | return $consumer->add($body, $headers); 25 | } 26 | 27 | /** 28 | * Create a new basic auth credential for a consumer 29 | * 30 | * @see https://getkong.org/plugins/basic-authentication/#create-a-credential 31 | * 32 | * @param string $identifier 33 | * @param array $body 34 | * @param array $headers 35 | * 36 | * @return array|\stdClass 37 | */ 38 | public function create($identifier, array $body = [], array $headers = []) 39 | { 40 | $this->setAllowedOptions(['username', 'password']); 41 | $body = $this->createRequestBody($body); 42 | 43 | return $this->postRequest('consumers/' . $identifier . '/basic-auth', $body, $headers); 44 | } 45 | 46 | /** 47 | * Delete a basic auth credential for a consumer 48 | * 49 | * @see 50 | * 51 | * @param $identifier 52 | * @param $auth_identifier 53 | * @param array $headers 54 | * 55 | * @return array|\stdClass 56 | */ 57 | public function delete($identifier, $auth_identifier, array $headers = []) 58 | { 59 | return $this->deleteRequest('consumers/' . $identifier . '/basic-auth/' . $auth_identifier, $headers); 60 | } 61 | 62 | /** 63 | * List all basic auth credentials for a consumer 64 | * 65 | * @see 66 | * 67 | * @param string $identifier 68 | * @param array $params 69 | * @param array $headers 70 | * 71 | * @return array|\stdClass 72 | */ 73 | public function list($identifier, array $params = [], array $headers = []) 74 | { 75 | return $this->getRequest('consumers/' . $identifier . '/basic-auth', $params, $headers); 76 | } 77 | 78 | /** 79 | * Get a single basic auth credential for a consumer 80 | * 81 | * @see 82 | * 83 | * @param string $identifier 84 | * @param string $auth_identifier 85 | * @param array $params 86 | * @param array $headers 87 | * 88 | * @return array|\stdClass 89 | */ 90 | public function get($identifier, $auth_identifier, array $params = [], array $headers = []) 91 | { 92 | return $this->getRequest('consumers/' . $identifier . '/basic-auth/' . $auth_identifier, $params, $headers); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/Kong/Apis/Plugins/BasicAuthInterface.php: -------------------------------------------------------------------------------- 1 | url, $this->port); 23 | 24 | return $consumer->add($body, $headers); 25 | } 26 | 27 | /** 28 | * Create a new JWT credential for a consumer 29 | * 30 | * @see https://getkong.org/plugins/jwt/#create-a-jwt-credential 31 | * 32 | * @param string $identifier 33 | * @param array $body 34 | * @param array $headers 35 | * 36 | * @return array|\stdClass 37 | */ 38 | public function create($identifier, array $body = [], array $headers = []) 39 | { 40 | $this->setAllowedOptions(['key', 'algorithm', 'rsa_public_key', 'secret']); 41 | $body = $this->createRequestBody($body); 42 | 43 | return $this->postRequest('consumers/' . $identifier . '/jwt', $body, $headers); 44 | } 45 | 46 | /** 47 | * Delete a JWT credential for a consumer 48 | * 49 | * @see https://getkong.org/plugins/jwt/#delete-a-jwt-credential 50 | * 51 | * @param string $identifier 52 | * @param string $jwt_identifier 53 | * @param array $headers 54 | * 55 | * @return array|\stdClass 56 | */ 57 | public function delete($identifier, $jwt_identifier, array $headers = []) 58 | { 59 | return $this->deleteRequest('consumers/' . $identifier . '/jwt/' . $jwt_identifier, $headers); 60 | } 61 | 62 | /** 63 | * List all JWT credentials for a consumer 64 | * 65 | * @see https://github.com/Mashape/getkong.org/issues/423 66 | * 67 | * @param string $identifier 68 | * @param array $params 69 | * @param array $headers 70 | * 71 | * @return array|\stdClass 72 | */ 73 | public function list($identifier, array $params = [], array $headers = []) 74 | { 75 | return $this->getRequest('consumers/' . $identifier . '/jwt', $params, $headers); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/Kong/Apis/Plugins/JwtInterface.php: -------------------------------------------------------------------------------- 1 | url, $this->port); 23 | 24 | return $consumer->add($body, $headers); 25 | } 26 | 27 | /** 28 | * Create a key auth credential for a consumer 29 | * 30 | * @see https://getkong.org/plugins/key-authentication/#create-an-api-key 31 | * 32 | * @param string $identifier 33 | * @param array $body 34 | * @param array $headers 35 | * 36 | * @return array|\stdClass 37 | */ 38 | public function create($identifier, array $body = [], array $headers = []) 39 | { 40 | $this->setAllowedOptions(['key']); 41 | $body = $this->createRequestBody($body); 42 | 43 | return $this->postRequest('consumers/' . $identifier . '/key-auth', $body, $headers); 44 | } 45 | 46 | /** 47 | * Delete a key auth credential for a consumer 48 | * 49 | * @see 50 | * 51 | * @param string $identifier 52 | * @param string $auth_identifier 53 | * @param array $headers 54 | * 55 | * @return array|\stdClass 56 | */ 57 | public function delete($identifier, $auth_identifier, array $headers = []) 58 | { 59 | return $this->deleteRequest('consumers/' . $identifier . '/key-auth/' . $auth_identifier, $headers); 60 | } 61 | 62 | /** 63 | * List all key auth credentials for a consumer 64 | * 65 | * @see 66 | * 67 | * @param string $identifier 68 | * @param array $params 69 | * @param array $headers 70 | * 71 | * @return array|\stdClass 72 | */ 73 | public function list($identifier, array $params = [], array $headers = []) 74 | { 75 | return $this->getRequest('consumers/' . $identifier . '/key-auth', $params, $headers); 76 | } 77 | 78 | /** 79 | * Get a single key auth credential for a consumer 80 | * 81 | * @see 82 | * 83 | * @param string $identifier 84 | * @param string $auth_identifier 85 | * @param array $params 86 | * @param array $headers 87 | * 88 | * @return array|\stdClass 89 | */ 90 | public function get($identifier, $auth_identifier, array $params = [], array $headers = []) 91 | { 92 | return $this->getRequest('consumers/' . $identifier . '/key-auth/' . $auth_identifier, $params, $headers); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/Kong/Apis/Plugins/KeyAuthInterface.php: -------------------------------------------------------------------------------- 1 | setAllowedOptions($this->routeAllowedOptions); 29 | $body = $this->createRequestBody($body); 30 | 31 | return $this->postRequest('routes', $body, $headers); 32 | } 33 | 34 | /** 35 | * Delete a Route from Kong 36 | * 37 | * @see https://getkong.org/docs/0.13.x/admin-api/#delete-route 38 | * 39 | * @param string $identifier 40 | * @param array $headers 41 | * 42 | * @return array|\stdClass 43 | */ 44 | public function delete($identifier, array $headers = []) 45 | { 46 | return $this->deleteRequest('routes/' . $identifier, $headers); 47 | } 48 | 49 | /** 50 | * Retrieve information about a specific Route from Kong 51 | * 52 | * @see https://getkong.org/docs/0.13.x/admin-api/#retrieve-route 53 | * 54 | * @param string $identifier 55 | * @param array $params 56 | * @param array $headers 57 | * 58 | * @return array|\stdClass 59 | */ 60 | public function get($identifier, array $params = [], array $headers = []) 61 | { 62 | return $this->getRequest('routes/' . $identifier, $params, $headers); 63 | } 64 | 65 | /** 66 | * List all Routes in Kong 67 | * 68 | * @see https://getkong.org/docs/0.13.x/admin-api/#list-routes 69 | * 70 | * @param array $params 71 | * @param array $headers 72 | * 73 | * @return array|\stdClass 74 | */ 75 | public function list(array $params = [], array $headers = []) 76 | { 77 | return $this->getRequest('routes', $params, $headers); 78 | } 79 | 80 | /** 81 | * List all Routes in Kong that are associated with a service 82 | * 83 | * @see https://getkong.org/docs/0.13.x/admin-api/#list-routes-associated-to-a-service 84 | * 85 | * @param string $identifier 86 | * @param array $params 87 | * @param array $headers 88 | * 89 | * @return array|\stdClass 90 | */ 91 | public function listRoutesWithServiceId($identifier, array $params = [], array $headers = []) 92 | { 93 | return $this->getRequest('services/' . $identifier . '/routes', $params, $headers); 94 | } 95 | 96 | /** 97 | * Update a Route on Kong 98 | * 99 | * @see https://getkong.org/docs/0.13.x/admin-api/#update-route 100 | * 101 | * @param string $identifier 102 | * @param array $body 103 | * @param array $headers 104 | * 105 | * @return array|\stdClass 106 | */ 107 | public function update($identifier, array $body = [], array $headers = []) 108 | { 109 | $this->setAllowedOptions($this->routeAllowedOptions); 110 | $body = $this->createRequestBody($body); 111 | 112 | return $this->patchRequest('routes/' . $identifier, $body, $headers); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/Kong/Apis/RouteInterface.php: -------------------------------------------------------------------------------- 1 | setAllowedOptions($this->serviceAllowedOptions); 30 | $body = $this->createRequestBody($body); 31 | 32 | return $this->postRequest('services', $body, $headers); 33 | } 34 | 35 | /** 36 | * Delete a Service from Kong 37 | * 38 | * @see https://getkong.org/docs/0.13.x/admin-api/#delete-service 39 | * 40 | * @param string $identifier 41 | * @param array $headers 42 | * 43 | * @return array|\stdClass 44 | */ 45 | public function delete($identifier, array $headers = []) 46 | { 47 | return $this->deleteRequest('services/' . $identifier, $headers); 48 | } 49 | 50 | /** 51 | * Retrieve information about a specific Service from Kong 52 | * 53 | * @see https://getkong.org/docs/0.13.x/admin-api/#retrieve-service 54 | * 55 | * @param string $identifier 56 | * @param array $params 57 | * @param array $headers 58 | * 59 | * @return array|\stdClass 60 | */ 61 | public function get($identifier, array $params = [], array $headers = []) 62 | { 63 | return $this->getRequest('services/' . $identifier, $params, $headers); 64 | } 65 | 66 | /** 67 | * Retrieve information about a specific Service from Kong using the route ID 68 | * 69 | * @see https://getkong.org/docs/0.13.x/admin-api/#retrieve-service 70 | * 71 | * @param string $identifier 72 | * @param array $params 73 | * @param array $headers 74 | * 75 | * @return array|\stdClass 76 | */ 77 | public function getServiceByRouteId($identifier, array $params = [], array $headers = []) 78 | { 79 | return $this->getRequest('routes/' . $identifier . '/service', $params, $headers); 80 | } 81 | 82 | /** 83 | * List all Services in Kong 84 | * 85 | * @see https://getkong.org/docs/0.13.x/admin-api/#list-services 86 | * 87 | * @param array $params 88 | * @param array $headers 89 | * 90 | * @return array|\stdClass 91 | */ 92 | public function list(array $params = [], array $headers = []) 93 | { 94 | return $this->getRequest('services', $params, $headers); 95 | } 96 | 97 | /** 98 | * Update a Service on Kong 99 | * 100 | * @see https://getkong.org/docs/0.13.x/admin-api/#update-service 101 | * 102 | * @param string $identifier 103 | * @param array $body 104 | * @param array $headers 105 | * 106 | * @return array|\stdClass 107 | */ 108 | public function update($identifier, array $body = [], array $headers = []) 109 | { 110 | $this->setAllowedOptions($this->serviceAllowedOptions); 111 | $body = $this->createRequestBody($body); 112 | 113 | return $this->patchRequest('services/' . $identifier, $body, $headers); 114 | } 115 | 116 | /** 117 | * Update a Service on Kong using the route ID 118 | * 119 | * @see https://getkong.org/docs/0.13.x/admin-api/#update-service 120 | * 121 | * @param string $identifier 122 | * @param array $body 123 | * @param array $headers 124 | * 125 | * @return array|\stdClass 126 | */ 127 | public function updateServiceByRouteId($identifier, array $body = [], array $headers = []) 128 | { 129 | $this->setAllowedOptions($this->serviceAllowedOptions); 130 | $body = $this->createRequestBody($body); 131 | 132 | return $this->patchRequest('routes/' . $identifier . '/service', $body, $headers); 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /src/Kong/Apis/ServiceInterface.php: -------------------------------------------------------------------------------- 1 | setAllowedOptions($this->sniAllowedOptions); 27 | $body = $this->createRequestBody($body); 28 | 29 | return $this->postRequest('snis', $body, $headers); 30 | } 31 | 32 | /** 33 | * Delete an SNI object from Kong 34 | * 35 | * @see https://getkong.org/docs/0.13.x/admin-api/#delete-sni 36 | * 37 | * @param string $identifier 38 | * @param array $headers 39 | * 40 | * @return array|\stdClass 41 | */ 42 | public function delete($identifier, array $headers = []) 43 | { 44 | return $this->deleteRequest('snis/' . $identifier, $headers); 45 | } 46 | 47 | /** 48 | * Retrieve a specific SNI object from Kong 49 | * 50 | * @see https://getkong.org/docs/0.13.x/admin-api/#retrieve-sni 51 | * 52 | * @param string $identifier 53 | * @param array $params 54 | * @param array $headers 55 | * 56 | * @return array|\stdClass 57 | */ 58 | public function get($identifier, array $params = [], array $headers = []) 59 | { 60 | return $this->getRequest('snis/' . $identifier, $params, $headers); 61 | } 62 | 63 | /** 64 | * Retrieve all SNI objects from Kong 65 | * 66 | * @see https://getkong.org/docs/0.13.x/admin-api/#list-snis 67 | * 68 | * @param array $params 69 | * @param array $headers 70 | * 71 | * @return array|\stdClass 72 | */ 73 | public function list(array $params = [], array $headers = []) 74 | { 75 | return $this->getRequest('snis', $params, $headers); 76 | } 77 | 78 | /** 79 | * Update an SNI entry on Kong 80 | * 81 | * @see https://getkong.org/docs/0.13.x/admin-api/#update-sni 82 | * 83 | * @param string $identifier 84 | * @param array $body 85 | * @param array $headers 86 | * 87 | * @return array|\stdClass 88 | */ 89 | public function update($identifier, array $body = [], array $headers = []) 90 | { 91 | $this->setAllowedOptions($this->sniAllowedOptions); 92 | $body = $this->createRequestBody($body); 93 | 94 | return $this->patchRequest('snis/' . $identifier, $body, $headers); 95 | } 96 | 97 | /** 98 | * Update or Create an SNI entry on Kong 99 | * 100 | * @see https://getkong.org/docs/0.13.x/admin-api/#update-or-create-sni 101 | * 102 | * @param array $body 103 | * @param array $headers 104 | * 105 | * @return array|\stdClass 106 | */ 107 | public function updateOrCreate(array $body = [], array $headers = []) 108 | { 109 | $this->setAllowedOptions(array_merge($this->sniAllowedOptions, ['id'])); 110 | $body = $this->createRequestBody($body); 111 | 112 | return $this->putRequest('snis', $body, $headers); 113 | } 114 | } -------------------------------------------------------------------------------- /src/Kong/Apis/SniInterface.php: -------------------------------------------------------------------------------- 1 | setAllowedOptions($this->upstreamAllowedOptions); 36 | $body = $this->createRequestBody($body); 37 | 38 | return $this->postRequest('upstreams', $body, $headers); 39 | } 40 | 41 | /** 42 | * Add a target to an upstream on Kong 43 | * 44 | * @see https://getkong.org/docs/0.13.x/admin-api/#add-target 45 | * 46 | * @param string $identifier 47 | * @param array $body 48 | * @param array $headers 49 | * 50 | * @return array|\stdClass 51 | */ 52 | public function addTarget($identifier, array $body = [], array $headers = []) 53 | { 54 | $this->setAllowedOptions($this->targetAllowedOptions); 55 | $body = $this->createRequestBody($body); 56 | 57 | return $this->postRequest('upstreams/' . $identifier . '/targets', $body, $headers); 58 | } 59 | 60 | /** 61 | * Delete an upstream from Kong 62 | * 63 | * @see https://getkong.org/docs/0.13.x/admin-api/#delete-upstream 64 | * 65 | * @param string $identifier 66 | * @param array $headers 67 | * 68 | * @return array|\stdClass 69 | */ 70 | public function delete($identifier, array $headers = []) 71 | { 72 | return $this->deleteRequest('upstreams/' . $identifier, $headers); 73 | } 74 | 75 | /** 76 | * Disable an upstream target in the load-balancer 77 | * 78 | * @see https://getkong.org/docs/0.13.x/admin-api/#delete-target 79 | * 80 | * @param string $identifier 81 | * @param string $target_identifier 82 | * @param array $headers 83 | * 84 | * @return array|\stdClass 85 | */ 86 | public function deleteTarget($identifier, $target_identifier, array $headers = []) 87 | { 88 | return $this->deleteRequest('upstreams/' . $identifier . '/targets/' . $target_identifier, $headers); 89 | } 90 | 91 | /** 92 | * Retrieve a specific upstream from Kong 93 | * 94 | * @see https://getkong.org/docs/0.13.x/admin-api/#retrieve-upstream 95 | * 96 | * @param string $identifier 97 | * @param array $params 98 | * @param array $headers 99 | * 100 | * @return array|\stdClass 101 | */ 102 | public function get($identifier, array $params = [], array $headers = []) 103 | { 104 | return $this->getRequest('upstreams/' . $identifier, $params, $headers); 105 | } 106 | 107 | /** 108 | * Retrieve all upstreams from Kong 109 | * 110 | * @see https://getkong.org/docs/0.13.x/admin-api/#list-upstreams 111 | * 112 | * @param array $params 113 | * @param array $headers 114 | * 115 | * @return array|\stdClass 116 | */ 117 | public function list(array $params = [], array $headers = []) 118 | { 119 | return $this->getRequest('upstreams', $params, $headers); 120 | } 121 | 122 | /** 123 | * Retrieve all active targets for an upstream from Kong 124 | * 125 | * @see https://getkong.org/docs/0.13.x/admin-api/#list-targets 126 | * 127 | * @param string $identifier 128 | * @param array $params 129 | * @param array $headers 130 | * 131 | * @return array|\stdClass 132 | */ 133 | public function listTargets($identifier, array $params = [], array $headers = []) 134 | { 135 | return $this->getRequest('upstreams/' . $identifier . '/targets', $params, $headers); 136 | } 137 | 138 | /** 139 | * Retrieve all targets for an upstream from Kong 140 | * 141 | * @see https://getkong.org/docs/0.13.x/admin-api/#list-all-targets 142 | * 143 | * @param string $identifier 144 | * @param array $params 145 | * @param array $headers 146 | * 147 | * @return array|\stdClass 148 | */ 149 | public function listAllTargets($identifier, array $params = [], array $headers = []) 150 | { 151 | return $this->getRequest('upstreams/' . $identifier . '/targets/all', $params, $headers); 152 | } 153 | 154 | /** 155 | * Update an upstream entry on Kong 156 | * 157 | * @see https://getkong.org/docs/0.13.x/admin-api/#update-upstream 158 | * 159 | * @param string $identifier 160 | * @param array $body 161 | * @param array $headers 162 | * 163 | * @return array|\stdClass 164 | */ 165 | public function update($identifier, array $body = [], array $headers = []) 166 | { 167 | $this->setAllowedOptions($this->upstreamAllowedOptions); 168 | $body = $this->createRequestBody($body); 169 | 170 | return $this->patchRequest('upstreams/' . $identifier, $body, $headers); 171 | } 172 | 173 | /** 174 | * Update or Create a new upstream on Kong 175 | * 176 | * @see https://getkong.org/docs/0.13.x/admin-api/#update-or-create-upstream 177 | * 178 | * @param array $body 179 | * @param array $headers 180 | * 181 | * @return array|\stdClass 182 | */ 183 | public function updateOrCreate(array $body = [], array $headers = []) 184 | { 185 | $this->setAllowedOptions(array_merge($this->upstreamAllowedOptions, ['id'])); 186 | $body = $this->createRequestBody($body); 187 | 188 | return $this->putRequest('upstreams', $body, $headers); 189 | } 190 | 191 | /** 192 | * Mark Target as Healthy in Kong 193 | * 194 | * @see https://getkong.org/docs/0.13.x/admin-api/#set-target-as-healthy 195 | * 196 | * @param array $body 197 | * @param array $headers 198 | * 199 | * @return array|\stdClass 200 | */ 201 | public function setTargetHealthy($identifier, $target_identifier, array $body = [], array $headers = []) 202 | { 203 | $this->setAllowedOptions(); 204 | $body = $this->createRequestBody($body); 205 | 206 | return $this->postRequest( 207 | 'upstreams/' . $identifier . '/targets/' . $target_identifier . '/healthy', 208 | $body, 209 | $headers 210 | ); 211 | } 212 | 213 | /** 214 | * Mark Target as Healthy in Kong 215 | * 216 | * @see https://getkong.org/docs/0.13.x/admin-api/#set-target-as-unhealthy 217 | * 218 | * @param array $body 219 | * @param array $headers 220 | * 221 | * @return array|\stdClass 222 | */ 223 | public function setTargetUnhealthy($identifier, $target_identifier, array $body = [], array $headers = []) 224 | { 225 | $this->setAllowedOptions(); 226 | $body = $this->createRequestBody($body); 227 | 228 | return $this->postRequest( 229 | 'upstreams/' . $identifier . '/targets/' . $target_identifier . '/unhealthy', 230 | $body, 231 | $headers 232 | ); 233 | } 234 | } 235 | -------------------------------------------------------------------------------- /src/Kong/Apis/UpstreamInterface.php: -------------------------------------------------------------------------------- 1 | port = $port; 56 | $this->url = rtrim($url, '/'); 57 | 58 | // Configure the response to be a JSON object instead of \StdClass 59 | if ($return_json) { 60 | Request::jsonOpts(true, 512, JSON_NUMERIC_CHECK & JSON_FORCE_OBJECT & JSON_UNESCAPED_SLASHES); 61 | } 62 | 63 | // Set the default timeout for all requests 64 | Request::timeout($default_timeout); 65 | 66 | // Verify SSL if configured 67 | Request::verifyPeer($verify_ssl); 68 | 69 | // Ensure we are always sending and receiving JSON 70 | $this->setDefaultHeader('Content-Type', 'application/json'); 71 | $this->setDefaultHeader('Accept', 'application/json'); 72 | } 73 | 74 | /** 75 | * Set default header to be used on all requests 76 | * 77 | * @param string $key 78 | * @param string $value 79 | * 80 | * @return void 81 | */ 82 | public function setDefaultHeader($key, $value) 83 | { 84 | Request::defaultHeader($key, $value); 85 | } 86 | 87 | /** 88 | * Set default headers to be used on all requests 89 | * 90 | * @param array $headers 91 | * 92 | * @return void 93 | */ 94 | public function setDefaultHeaders(array $headers = []) 95 | { 96 | Request::defaultHeaders($headers); 97 | } 98 | 99 | /** 100 | * Clear all default headers 101 | * 102 | * @return void 103 | */ 104 | public function clearDefaultHeaders() 105 | { 106 | Request::clearDefaultHeaders(); 107 | } 108 | 109 | /** 110 | * Returns a new instance of the Service endpoint 111 | * 112 | * @return Service 113 | */ 114 | public function getServiceObject() 115 | { 116 | return new Service($this->url, $this->port); 117 | } 118 | 119 | /** 120 | * Returns a new instance of the Route endpoint 121 | * 122 | * @return Route 123 | */ 124 | public function getRouteObject() 125 | { 126 | return new Route($this->url, $this->port); 127 | } 128 | 129 | /** 130 | * Returns a new instance of the Node endpoint 131 | * 132 | * @return Node 133 | */ 134 | public function getNodeObject() 135 | { 136 | return new Node($this->url, $this->port); 137 | } 138 | 139 | /** 140 | * Returns a new instance of the Api endpoint 141 | * 142 | * @deprecated 143 | * 144 | * @return Api 145 | */ 146 | public function getApiObject() 147 | { 148 | return new Api($this->url, $this->port); 149 | } 150 | 151 | /** 152 | * Returns a new instance of the Consumer endpoint 153 | * 154 | * @return Consumer 155 | */ 156 | public function getConsumerObject() 157 | { 158 | return new Consumer($this->url, $this->port); 159 | } 160 | 161 | /** 162 | * Returns a new instance of the Plugin endpoint 163 | * 164 | * @return Plugin 165 | */ 166 | public function getPluginObject() 167 | { 168 | return new Plugin($this->url, $this->port); 169 | } 170 | 171 | /** 172 | * Returns a new instance of the Certificate endpoint 173 | * 174 | * @return Certificate 175 | */ 176 | public function getCertificateObject() 177 | { 178 | return new Certificate($this->url, $this->port); 179 | } 180 | 181 | /** 182 | * Returns a new instance of the SNI endpoint 183 | * 184 | * @return Sni 185 | */ 186 | public function getSNIObject() 187 | { 188 | return new Sni($this->url, $this->port); 189 | } 190 | 191 | /** 192 | * Returns a new instance of the Upstream endpoint 193 | * 194 | * @return Upstream 195 | */ 196 | public function getUpstreamObject() 197 | { 198 | return new Upstream($this->url, $this->port); 199 | } 200 | 201 | /** 202 | * Returns a new instance of the Key Auth plugin 203 | * 204 | * @return KeyAuth 205 | */ 206 | public function getPluginKeyAuth() 207 | { 208 | return new KeyAuth($this->url, $this->port); 209 | } 210 | 211 | /** 212 | * Returns a new instance of the Basic Auth Plugin 213 | * 214 | * @return BasicAuth 215 | */ 216 | public function getPluginBasicAuth() 217 | { 218 | return new BasicAuth($this->url, $this->port); 219 | } 220 | 221 | /** 222 | * Returns a new instance of the JWT plugin 223 | * 224 | * @return Jwt 225 | */ 226 | public function getPluginJwt() 227 | { 228 | return new Jwt($this->url, $this->port); 229 | } 230 | } 231 | -------------------------------------------------------------------------------- /tests/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/therealgambo/kong-php/5fc3774a920cbcd3adccb9fda2803943a3b178f8/tests/.gitignore --------------------------------------------------------------------------------