To create and manage your Private Networks, check out the [VPC API](https://www.scaleway.com/en/developers/api/vpc). (switchcolumn) ## Concepts Refer to our [dedicated concepts page](https://www.scaleway.com/en/docs/public-gateways/concepts/) to find definitions of all terminology related to Public Gateways, including NAT, SSH bastion and more. (switchcolumn) (switchcolumn) ## Quickstart 1. Configure your environment variables. This is an optional step that seeks to simplify your usage of the Public Gateways API. ```bash export SCW_SECRET_KEY=\"\" export SCW_DEFAULT_ZONE=\"\" export SCW_PROJECT_ID=\"\" ``` 2. **Choose a Public Gateway type**: Public Gateways come in different shapes and sizes, with different network capabilities and pricing. When you create your Public Gateway, you need to include the required Public Gateway type in the request. Use the following call to get a list of available Public Gateway offer types and their details: ```bash curl -X GET \\ -H \"X-Auth-Token: $SCW_SECRET_KEY\" \\ -H \"Content-Type: application/json\" \\ \"https://api.scaleway.com/vpc-gw/v2/zones/$SCW_DEFAULT_ZONE/gateway-types\" ``` 3. **Create a Public Gateway**: run the following command to create a Public Gateway. You can customize the details in the payload (name, description, tags, etc) to your needs: use the information below to adjust the payload as necessary. ```bash curl -X POST \\ -H \"X-Auth-Token: $SCW_SECRET_KEY\" \\ -H \"Content-Type: application/json\" \\ \"https://api.scaleway.com/vpc-gw/v2/zones/$SCW_DEFAULT_ZONE/gateways\" \\ -d '{ \"type\": \"VPC-GW-S\", \"name\": \"my-new-gateway\", \"tags\": [\"my-first-tag\", \"my-second-tag\"], \"project_id\": \"'\"$SCW_PROJECT_ID\"'\" }' ``` | Parameter | Description | Valid values | |-----------------|-----------------------------------------------------|-------------------------------| | type | The type of Public Gateway (commercial offer type) to create. Use the Gateway Types endpoint to get a list of offer types. | Any valid offer type string, e.g. `VPC-GW-S` | | name | A name of your choice for the Public Gateway | Any string containing only alphanumeric characters and dashes, e.g. `my-new-gateway`. | | tags | A list of tags to describe your Public Gateway. These can help you manage and filter your gateways. | A list of alphanumeric strings, e.g. `[\"my-first-tag`, `my-second-tag` | | project_id | The Scaleway Project ID to create the Public Gateway in. | A valid Scaleway Project ID, e.g. `f5fe13a0-b9c7-11ed-afa1-0242ac120002` | **Note**: Further parameters are available, but for the purposes of this quickstart we have included only the essentials. See the `Create a Public Gateway` endpoint documentation below for full details of all possible parameters. 4. **Get a list of your Public Gateways**: run the following command to get a list of all your Public Gateways. ```bash curl -X GET \\ -H \"X-Auth-Token: $SCW_SECRET_KEY\" \\ -H \"Content-Type: application/json\" \\ \"https://api.scaleway.com/vpc-gw/v2/zones/$SCW_DEFAULT_ZONE/gateways\" ``` 5. **Attach a Private Network to a Public Gateway**: run the following command to attach a Private Network to your Public Gateway, and make all the Gateway's services such as NAT available to the Private Network. You can customize the details in the payload to your needs: use the information below to adjust the payload as necessary. If you haven't created a Private Network yet, see the [Private Networks](https://www/scaleway.com/en/developers/api/vpc/) documentation to learn how to do so. Ensure you retain the ID of the Private Network. ```bash curl -X POST \\ -H \"X-Auth-Token: $SCW_SECRET_KEY\" \\ -H \"Content-Type: application/json\" \\ \"https://api.scaleway.com/vpc-gw/v2/zones/$SCW_DEFAULT_ZONE/gateway-networks\" \\ -d '{ \"gateway_id\": \"b1b2edda-9364-422d-93f2-ad04e6a054dc\", \"private_network_id\": \"548dbcc3-8b78-486f-a79a-c3f5a17642f9\", \"enable_masquerade\": true }' ``` This configuration will set up the Public Gateway as a NAT gateway, masquerading traffic sent to it to the outer internet to provide internet access to resources in the Private Network. | Parameter | Description | Valid values | |-----------------|-----------------------------------------------------|-------------------------------| | gateway_id | The Public Gateway ID of an existing Public Gateway | Any valid Public Gateway ID, e.g. `b1b2edda-9364-422d-93f2-ad04e6a054dc` | | private_network_id | The Private Network ID of an existing Private Network | Any valid Private Network ID in the same Availability Zone as the Public Gateway, e.g. `548dbcc3-8b78-486f-a79a-c3f5a17642f9` | | enable_masquerade | Defines whether the gateway should masquerade traffic for the attached Private Network (i.e. whether to enable dynamic NAT) | A boolean value, e.g. `true` | Further parameters are available, but for the purposes of this quickstart we have included only the essentials. See the [Attach a gateway to a Private Network](#path-gateway-networks-attach-a-public-gateway-to-a-private-network) documentation below for full details of all possible parameters. 6. **Delete a Public Gateway**: run the following call to delete your Public Gateway. Ensure that you replace `` in the URL with the ID of the Public Gateway you want to delete. ```bash curl -X DELETE \\ -H \"X-Auth-Token: $SCW_SECRET_KEY\" \\ -H \"Content-Type: application/json\" \\ \"https://api.scaleway.com/vpc-gw/v2/zones/$SCW_DEFAULT_ZONE/gateways/\" ``` The expected successful response is empty. (switchcolumn) - You have a [Scaleway account](https://console.scaleway.com/) - You have [created an API key](https://www.scaleway.com/en/docs/iam/how-to/create-api-keys/) and that the API key has sufficient [IAM permissions](https://www.scaleway.com/en/docs/iam/reference-content/permission-sets/) to perform the actions described on this page - You have [installed `curl`](https://curl.se/download.html) (switchcolumn) ## Technical limitations The following limitations apply to Public Gateways: - A maximum of eight (8) Private Networks can be plugged into a single Public Gateway - Note that the Public Gateway takes some time to start up, and actions on it are impossible unless it is in the `running` state. To check the current state of a Public Gateway, use the [Get a Public Gateway](#path-gateways-get-a-public-gateway) endpoint to get information for your gateway: the `status` field of the response will tell you if it is running or in another state. - For further information about Public Gateway limitations see our [dedicated documentation](https://www.scaleway.com/en/docs/public-gateways/troubleshooting/gw-limitations/). ## Technical information ### Availability Zones Public Gateways can be deployed in the following Availability Zones: | Name | API ID | |-----------|-----------------------| | Paris | `fr-par-1` `fr-par-2` | | Amsterdam | `nl-ams-1` `nl-ams-2` `nl-ams-3` | | Warsaw | `pl-waw-1` `pl-waw-2` `pl-waw-3` | The Scaleway Public Gateways API is a **zoned** API, meaning that each call must specify in its path parameters the Availability Zone for the resources concerned by the call. ## Going further For more help using Scaleway Public Gateways, check out the following resources: - Our [main documentation](https://www.scaleway.com/en/docs/public-gateways/) - The #public-gateway channel on our [Slack Community](https://www.scaleway.com/en/docs/tutorials/scaleway-slack-community/) - Our [support ticketing system](https://www.scaleway.com/en/docs/account/how-to/open-a-support-ticket/). * * The version of the OpenAPI document: v2 * Generated by: https://openapi-generator.tech * Generator version: 7.11.0 */ /** * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). * https://openapi-generator.tech * Do not edit the class manually. */ namespace OpenAPI\Client\Api; use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; use OpenAPI\Client\HeaderSelector; use OpenAPI\Client\ObjectSerializer; /** * PATRulesApi Class Doc Comment * * @category Class * @package OpenAPI\Client * @author OpenAPI Generator team * @link https://openapi-generator.tech */ class PATRulesApi { /** * @var ClientInterface */ protected $client; /** * @var Configuration */ protected $config; /** * @var HeaderSelector */ protected $headerSelector; /** * @var int Host index */ protected $hostIndex; /** @var string[] $contentTypes **/ public const contentTypes = [ 'createPatRule' => [ 'application/json', ], 'deletePatRule' => [ 'application/json', ], 'getPatRule' => [ 'application/json', ], 'listPatRules' => [ 'application/json', ], 'setPatRules' => [ 'application/json', ], 'updatePatRule' => [ 'application/json', ], ]; /** * @param ClientInterface $client * @param Configuration $config * @param HeaderSelector $selector * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec */ public function __construct( ?ClientInterface $client = null, ?Configuration $config = null, ?HeaderSelector $selector = null, int $hostIndex = 0 ) { $this->client = $client ?: new Client(); $this->config = $config ?: Configuration::getDefaultConfiguration(); $this->headerSelector = $selector ?: new HeaderSelector(); $this->hostIndex = $hostIndex; } /** * Set the host index * * @param int $hostIndex Host index (required) */ public function setHostIndex($hostIndex): void { $this->hostIndex = $hostIndex; } /** * Get the host index * * @return int Host index */ public function getHostIndex() { return $this->hostIndex; } /** * @return Configuration */ public function getConfig() { return $this->config; } /** * Operation createPatRule * * Create a PAT rule * * @param string $zone The zone you want to target (required) * @param \OpenAPI\Client\Model\CreatePatRuleRequest $create_pat_rule_request create_pat_rule_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['createPatRule'] to see the possible values for this operation * * @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return \OpenAPI\Client\Model\ScalewayVpcGwV2PatRule */ public function createPatRule($zone, $create_pat_rule_request, string $contentType = self::contentTypes['createPatRule'][0]) { list($response) = $this->createPatRuleWithHttpInfo($zone, $create_pat_rule_request, $contentType); return $response; } /** * Operation createPatRuleWithHttpInfo * * Create a PAT rule * * @param string $zone The zone you want to target (required) * @param \OpenAPI\Client\Model\CreatePatRuleRequest $create_pat_rule_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['createPatRule'] to see the possible values for this operation * * @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return array of \OpenAPI\Client\Model\ScalewayVpcGwV2PatRule, HTTP status code, HTTP response headers (array of strings) */ public function createPatRuleWithHttpInfo($zone, $create_pat_rule_request, string $contentType = self::contentTypes['createPatRule'][0]) { $request = $this->createPatRuleRequest($zone, $create_pat_rule_request, $contentType); try { $options = $this->createHttpClientOption(); try { $response = $this->client->send($request, $options); } catch (RequestException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), $e->getResponse() ? $e->getResponse()->getHeaders() : null, $e->getResponse() ? (string) $e->getResponse()->getBody() : null ); } catch (ConnectException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), null, null ); } $statusCode = $response->getStatusCode(); switch($statusCode) { case 200: if ('\OpenAPI\Client\Model\ScalewayVpcGwV2PatRule' === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ('\OpenAPI\Client\Model\ScalewayVpcGwV2PatRule' !== 'string') { try { $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); } catch (\JsonException $exception) { throw new ApiException( sprintf( 'Error JSON decoding server response (%s)', $request->getUri() ), $statusCode, $response->getHeaders(), $content ); } } } return [ ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\ScalewayVpcGwV2PatRule', []), $response->getStatusCode(), $response->getHeaders() ]; } if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, (string) $request->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } $returnType = '\OpenAPI\Client\Model\ScalewayVpcGwV2PatRule'; if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { try { $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); } catch (\JsonException $exception) { throw new ApiException( sprintf( 'Error JSON decoding server response (%s)', $request->getUri() ), $statusCode, $response->getHeaders(), $content ); } } } return [ ObjectSerializer::deserialize($content, $returnType, []), $response->getStatusCode(), $response->getHeaders() ]; } catch (ApiException $e) { switch ($e->getCode()) { case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\OpenAPI\Client\Model\ScalewayVpcGwV2PatRule', $e->getResponseHeaders() ); $e->setResponseObject($data); break; } throw $e; } } /** * Operation createPatRuleAsync * * Create a PAT rule * * @param string $zone The zone you want to target (required) * @param \OpenAPI\Client\Model\CreatePatRuleRequest $create_pat_rule_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['createPatRule'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function createPatRuleAsync($zone, $create_pat_rule_request, string $contentType = self::contentTypes['createPatRule'][0]) { return $this->createPatRuleAsyncWithHttpInfo($zone, $create_pat_rule_request, $contentType) ->then( function ($response) { return $response[0]; } ); } /** * Operation createPatRuleAsyncWithHttpInfo * * Create a PAT rule * * @param string $zone The zone you want to target (required) * @param \OpenAPI\Client\Model\CreatePatRuleRequest $create_pat_rule_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['createPatRule'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function createPatRuleAsyncWithHttpInfo($zone, $create_pat_rule_request, string $contentType = self::contentTypes['createPatRule'][0]) { $returnType = '\OpenAPI\Client\Model\ScalewayVpcGwV2PatRule'; $request = $this->createPatRuleRequest($zone, $create_pat_rule_request, $contentType); return $this->client ->sendAsync($request, $this->createHttpClientOption()) ->then( function ($response) use ($returnType) { if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { $content = json_decode($content); } } return [ ObjectSerializer::deserialize($content, $returnType, []), $response->getStatusCode(), $response->getHeaders() ]; }, function ($exception) { $response = $exception->getResponse(); $statusCode = $response->getStatusCode(); throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, $exception->getRequest()->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } ); } /** * Create request for operation 'createPatRule' * * @param string $zone The zone you want to target (required) * @param \OpenAPI\Client\Model\CreatePatRuleRequest $create_pat_rule_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['createPatRule'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ public function createPatRuleRequest($zone, $create_pat_rule_request, string $contentType = self::contentTypes['createPatRule'][0]) { // verify the required parameter 'zone' is set if ($zone === null || (is_array($zone) && count($zone) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $zone when calling createPatRule' ); } // verify the required parameter 'create_pat_rule_request' is set if ($create_pat_rule_request === null || (is_array($create_pat_rule_request) && count($create_pat_rule_request) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $create_pat_rule_request when calling createPatRule' ); } $resourcePath = '/vpc-gw/v2/zones/{zone}/pat-rules'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; // path params if ($zone !== null) { $resourcePath = str_replace( '{' . 'zone' . '}', ObjectSerializer::toPathValue($zone), $resourcePath ); } $headers = $this->headerSelector->selectHeaders( ['application/json', ], $contentType, $multipart ); // for model (json/xml) if (isset($create_pat_rule_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($create_pat_rule_request)); } else { $httpBody = $create_pat_rule_request; } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; foreach ($formParams as $formParamName => $formParamValue) { $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; foreach ($formParamValueItems as $formParamValueItem) { $multipartContents[] = [ 'name' => $formParamName, 'contents' => $formParamValueItem ]; } } // for HTTP post (form) $httpBody = new MultipartStream($multipartContents); } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); } } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('X-Auth-Token'); if ($apiKey !== null) { $headers['X-Auth-Token'] = $apiKey; } $defaultHeaders = []; if ($this->config->getUserAgent()) { $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } $headers = array_merge( $defaultHeaders, $headerParams, $headers ); $operationHost = $this->config->getHost(); $query = ObjectSerializer::buildQuery($queryParams); return new Request( 'POST', $operationHost . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); } /** * Operation deletePatRule * * Delete a PAT rule * * @param string $zone The zone you want to target (required) * @param string $pat_rule_id ID of the PAT rule to delete. (UUID format) (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deletePatRule'] to see the possible values for this operation * * @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return void */ public function deletePatRule($zone, $pat_rule_id, string $contentType = self::contentTypes['deletePatRule'][0]) { $this->deletePatRuleWithHttpInfo($zone, $pat_rule_id, $contentType); } /** * Operation deletePatRuleWithHttpInfo * * Delete a PAT rule * * @param string $zone The zone you want to target (required) * @param string $pat_rule_id ID of the PAT rule to delete. (UUID format) (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deletePatRule'] to see the possible values for this operation * * @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return array of null, HTTP status code, HTTP response headers (array of strings) */ public function deletePatRuleWithHttpInfo($zone, $pat_rule_id, string $contentType = self::contentTypes['deletePatRule'][0]) { $request = $this->deletePatRuleRequest($zone, $pat_rule_id, $contentType); try { $options = $this->createHttpClientOption(); try { $response = $this->client->send($request, $options); } catch (RequestException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), $e->getResponse() ? $e->getResponse()->getHeaders() : null, $e->getResponse() ? (string) $e->getResponse()->getBody() : null ); } catch (ConnectException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), null, null ); } $statusCode = $response->getStatusCode(); return [null, $statusCode, $response->getHeaders()]; } catch (ApiException $e) { switch ($e->getCode()) { } throw $e; } } /** * Operation deletePatRuleAsync * * Delete a PAT rule * * @param string $zone The zone you want to target (required) * @param string $pat_rule_id ID of the PAT rule to delete. (UUID format) (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deletePatRule'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function deletePatRuleAsync($zone, $pat_rule_id, string $contentType = self::contentTypes['deletePatRule'][0]) { return $this->deletePatRuleAsyncWithHttpInfo($zone, $pat_rule_id, $contentType) ->then( function ($response) { return $response[0]; } ); } /** * Operation deletePatRuleAsyncWithHttpInfo * * Delete a PAT rule * * @param string $zone The zone you want to target (required) * @param string $pat_rule_id ID of the PAT rule to delete. (UUID format) (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deletePatRule'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function deletePatRuleAsyncWithHttpInfo($zone, $pat_rule_id, string $contentType = self::contentTypes['deletePatRule'][0]) { $returnType = ''; $request = $this->deletePatRuleRequest($zone, $pat_rule_id, $contentType); return $this->client ->sendAsync($request, $this->createHttpClientOption()) ->then( function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { $response = $exception->getResponse(); $statusCode = $response->getStatusCode(); throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, $exception->getRequest()->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } ); } /** * Create request for operation 'deletePatRule' * * @param string $zone The zone you want to target (required) * @param string $pat_rule_id ID of the PAT rule to delete. (UUID format) (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deletePatRule'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ public function deletePatRuleRequest($zone, $pat_rule_id, string $contentType = self::contentTypes['deletePatRule'][0]) { // verify the required parameter 'zone' is set if ($zone === null || (is_array($zone) && count($zone) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $zone when calling deletePatRule' ); } // verify the required parameter 'pat_rule_id' is set if ($pat_rule_id === null || (is_array($pat_rule_id) && count($pat_rule_id) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $pat_rule_id when calling deletePatRule' ); } $resourcePath = '/vpc-gw/v2/zones/{zone}/pat-rules/{pat_rule_id}'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; // path params if ($zone !== null) { $resourcePath = str_replace( '{' . 'zone' . '}', ObjectSerializer::toPathValue($zone), $resourcePath ); } // path params if ($pat_rule_id !== null) { $resourcePath = str_replace( '{' . 'pat_rule_id' . '}', ObjectSerializer::toPathValue($pat_rule_id), $resourcePath ); } $headers = $this->headerSelector->selectHeaders( [], $contentType, $multipart ); // for model (json/xml) if (count($formParams) > 0) { if ($multipart) { $multipartContents = []; foreach ($formParams as $formParamName => $formParamValue) { $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; foreach ($formParamValueItems as $formParamValueItem) { $multipartContents[] = [ 'name' => $formParamName, 'contents' => $formParamValueItem ]; } } // for HTTP post (form) $httpBody = new MultipartStream($multipartContents); } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); } } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('X-Auth-Token'); if ($apiKey !== null) { $headers['X-Auth-Token'] = $apiKey; } $defaultHeaders = []; if ($this->config->getUserAgent()) { $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } $headers = array_merge( $defaultHeaders, $headerParams, $headers ); $operationHost = $this->config->getHost(); $query = ObjectSerializer::buildQuery($queryParams); return new Request( 'DELETE', $operationHost . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); } /** * Operation getPatRule * * Get a PAT rule * * @param string $zone The zone you want to target (required) * @param string $pat_rule_id ID of the PAT rule to get. (UUID format) (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getPatRule'] to see the possible values for this operation * * @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return \OpenAPI\Client\Model\ScalewayVpcGwV2PatRule */ public function getPatRule($zone, $pat_rule_id, string $contentType = self::contentTypes['getPatRule'][0]) { list($response) = $this->getPatRuleWithHttpInfo($zone, $pat_rule_id, $contentType); return $response; } /** * Operation getPatRuleWithHttpInfo * * Get a PAT rule * * @param string $zone The zone you want to target (required) * @param string $pat_rule_id ID of the PAT rule to get. (UUID format) (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getPatRule'] to see the possible values for this operation * * @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return array of \OpenAPI\Client\Model\ScalewayVpcGwV2PatRule, HTTP status code, HTTP response headers (array of strings) */ public function getPatRuleWithHttpInfo($zone, $pat_rule_id, string $contentType = self::contentTypes['getPatRule'][0]) { $request = $this->getPatRuleRequest($zone, $pat_rule_id, $contentType); try { $options = $this->createHttpClientOption(); try { $response = $this->client->send($request, $options); } catch (RequestException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), $e->getResponse() ? $e->getResponse()->getHeaders() : null, $e->getResponse() ? (string) $e->getResponse()->getBody() : null ); } catch (ConnectException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), null, null ); } $statusCode = $response->getStatusCode(); switch($statusCode) { case 200: if ('\OpenAPI\Client\Model\ScalewayVpcGwV2PatRule' === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ('\OpenAPI\Client\Model\ScalewayVpcGwV2PatRule' !== 'string') { try { $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); } catch (\JsonException $exception) { throw new ApiException( sprintf( 'Error JSON decoding server response (%s)', $request->getUri() ), $statusCode, $response->getHeaders(), $content ); } } } return [ ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\ScalewayVpcGwV2PatRule', []), $response->getStatusCode(), $response->getHeaders() ]; } if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, (string) $request->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } $returnType = '\OpenAPI\Client\Model\ScalewayVpcGwV2PatRule'; if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { try { $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); } catch (\JsonException $exception) { throw new ApiException( sprintf( 'Error JSON decoding server response (%s)', $request->getUri() ), $statusCode, $response->getHeaders(), $content ); } } } return [ ObjectSerializer::deserialize($content, $returnType, []), $response->getStatusCode(), $response->getHeaders() ]; } catch (ApiException $e) { switch ($e->getCode()) { case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\OpenAPI\Client\Model\ScalewayVpcGwV2PatRule', $e->getResponseHeaders() ); $e->setResponseObject($data); break; } throw $e; } } /** * Operation getPatRuleAsync * * Get a PAT rule * * @param string $zone The zone you want to target (required) * @param string $pat_rule_id ID of the PAT rule to get. (UUID format) (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getPatRule'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function getPatRuleAsync($zone, $pat_rule_id, string $contentType = self::contentTypes['getPatRule'][0]) { return $this->getPatRuleAsyncWithHttpInfo($zone, $pat_rule_id, $contentType) ->then( function ($response) { return $response[0]; } ); } /** * Operation getPatRuleAsyncWithHttpInfo * * Get a PAT rule * * @param string $zone The zone you want to target (required) * @param string $pat_rule_id ID of the PAT rule to get. (UUID format) (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getPatRule'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function getPatRuleAsyncWithHttpInfo($zone, $pat_rule_id, string $contentType = self::contentTypes['getPatRule'][0]) { $returnType = '\OpenAPI\Client\Model\ScalewayVpcGwV2PatRule'; $request = $this->getPatRuleRequest($zone, $pat_rule_id, $contentType); return $this->client ->sendAsync($request, $this->createHttpClientOption()) ->then( function ($response) use ($returnType) { if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { $content = json_decode($content); } } return [ ObjectSerializer::deserialize($content, $returnType, []), $response->getStatusCode(), $response->getHeaders() ]; }, function ($exception) { $response = $exception->getResponse(); $statusCode = $response->getStatusCode(); throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, $exception->getRequest()->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } ); } /** * Create request for operation 'getPatRule' * * @param string $zone The zone you want to target (required) * @param string $pat_rule_id ID of the PAT rule to get. (UUID format) (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getPatRule'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ public function getPatRuleRequest($zone, $pat_rule_id, string $contentType = self::contentTypes['getPatRule'][0]) { // verify the required parameter 'zone' is set if ($zone === null || (is_array($zone) && count($zone) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $zone when calling getPatRule' ); } // verify the required parameter 'pat_rule_id' is set if ($pat_rule_id === null || (is_array($pat_rule_id) && count($pat_rule_id) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $pat_rule_id when calling getPatRule' ); } $resourcePath = '/vpc-gw/v2/zones/{zone}/pat-rules/{pat_rule_id}'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; // path params if ($zone !== null) { $resourcePath = str_replace( '{' . 'zone' . '}', ObjectSerializer::toPathValue($zone), $resourcePath ); } // path params if ($pat_rule_id !== null) { $resourcePath = str_replace( '{' . 'pat_rule_id' . '}', ObjectSerializer::toPathValue($pat_rule_id), $resourcePath ); } $headers = $this->headerSelector->selectHeaders( ['application/json', ], $contentType, $multipart ); // for model (json/xml) if (count($formParams) > 0) { if ($multipart) { $multipartContents = []; foreach ($formParams as $formParamName => $formParamValue) { $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; foreach ($formParamValueItems as $formParamValueItem) { $multipartContents[] = [ 'name' => $formParamName, 'contents' => $formParamValueItem ]; } } // for HTTP post (form) $httpBody = new MultipartStream($multipartContents); } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); } } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('X-Auth-Token'); if ($apiKey !== null) { $headers['X-Auth-Token'] = $apiKey; } $defaultHeaders = []; if ($this->config->getUserAgent()) { $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } $headers = array_merge( $defaultHeaders, $headerParams, $headers ); $operationHost = $this->config->getHost(); $query = ObjectSerializer::buildQuery($queryParams); return new Request( 'GET', $operationHost . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); } /** * Operation listPatRules * * List PAT rules * * @param string $zone The zone you want to target (required) * @param string|null $order_by Order in which to return results. (optional, default to 'created_at_asc') * @param int|null $page Page number. (optional) * @param int|null $page_size PAT rules per page. (optional) * @param string[]|null $gateway_ids Filter for PAT rules on these gateways. (optional) * @param string[]|null $private_ips Filter for PAT rules targeting these private ips. (optional) * @param string|null $protocol Filter for PAT rules with this protocol. (optional, default to 'unknown_protocol') * @param string $contentType The value for the Content-Type header. Check self::contentTypes['listPatRules'] to see the possible values for this operation * * @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return \OpenAPI\Client\Model\ScalewayVpcGwV2ListPatRulesResponse */ public function listPatRules($zone, $order_by = 'created_at_asc', $page = null, $page_size = null, $gateway_ids = null, $private_ips = null, $protocol = 'unknown_protocol', string $contentType = self::contentTypes['listPatRules'][0]) { list($response) = $this->listPatRulesWithHttpInfo($zone, $order_by, $page, $page_size, $gateway_ids, $private_ips, $protocol, $contentType); return $response; } /** * Operation listPatRulesWithHttpInfo * * List PAT rules * * @param string $zone The zone you want to target (required) * @param string|null $order_by Order in which to return results. (optional, default to 'created_at_asc') * @param int|null $page Page number. (optional) * @param int|null $page_size PAT rules per page. (optional) * @param string[]|null $gateway_ids Filter for PAT rules on these gateways. (optional) * @param string[]|null $private_ips Filter for PAT rules targeting these private ips. (optional) * @param string|null $protocol Filter for PAT rules with this protocol. (optional, default to 'unknown_protocol') * @param string $contentType The value for the Content-Type header. Check self::contentTypes['listPatRules'] to see the possible values for this operation * * @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return array of \OpenAPI\Client\Model\ScalewayVpcGwV2ListPatRulesResponse, HTTP status code, HTTP response headers (array of strings) */ public function listPatRulesWithHttpInfo($zone, $order_by = 'created_at_asc', $page = null, $page_size = null, $gateway_ids = null, $private_ips = null, $protocol = 'unknown_protocol', string $contentType = self::contentTypes['listPatRules'][0]) { $request = $this->listPatRulesRequest($zone, $order_by, $page, $page_size, $gateway_ids, $private_ips, $protocol, $contentType); try { $options = $this->createHttpClientOption(); try { $response = $this->client->send($request, $options); } catch (RequestException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), $e->getResponse() ? $e->getResponse()->getHeaders() : null, $e->getResponse() ? (string) $e->getResponse()->getBody() : null ); } catch (ConnectException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), null, null ); } $statusCode = $response->getStatusCode(); switch($statusCode) { case 200: if ('\OpenAPI\Client\Model\ScalewayVpcGwV2ListPatRulesResponse' === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ('\OpenAPI\Client\Model\ScalewayVpcGwV2ListPatRulesResponse' !== 'string') { try { $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); } catch (\JsonException $exception) { throw new ApiException( sprintf( 'Error JSON decoding server response (%s)', $request->getUri() ), $statusCode, $response->getHeaders(), $content ); } } } return [ ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\ScalewayVpcGwV2ListPatRulesResponse', []), $response->getStatusCode(), $response->getHeaders() ]; } if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, (string) $request->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } $returnType = '\OpenAPI\Client\Model\ScalewayVpcGwV2ListPatRulesResponse'; if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { try { $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); } catch (\JsonException $exception) { throw new ApiException( sprintf( 'Error JSON decoding server response (%s)', $request->getUri() ), $statusCode, $response->getHeaders(), $content ); } } } return [ ObjectSerializer::deserialize($content, $returnType, []), $response->getStatusCode(), $response->getHeaders() ]; } catch (ApiException $e) { switch ($e->getCode()) { case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\OpenAPI\Client\Model\ScalewayVpcGwV2ListPatRulesResponse', $e->getResponseHeaders() ); $e->setResponseObject($data); break; } throw $e; } } /** * Operation listPatRulesAsync * * List PAT rules * * @param string $zone The zone you want to target (required) * @param string|null $order_by Order in which to return results. (optional, default to 'created_at_asc') * @param int|null $page Page number. (optional) * @param int|null $page_size PAT rules per page. (optional) * @param string[]|null $gateway_ids Filter for PAT rules on these gateways. (optional) * @param string[]|null $private_ips Filter for PAT rules targeting these private ips. (optional) * @param string|null $protocol Filter for PAT rules with this protocol. (optional, default to 'unknown_protocol') * @param string $contentType The value for the Content-Type header. Check self::contentTypes['listPatRules'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function listPatRulesAsync($zone, $order_by = 'created_at_asc', $page = null, $page_size = null, $gateway_ids = null, $private_ips = null, $protocol = 'unknown_protocol', string $contentType = self::contentTypes['listPatRules'][0]) { return $this->listPatRulesAsyncWithHttpInfo($zone, $order_by, $page, $page_size, $gateway_ids, $private_ips, $protocol, $contentType) ->then( function ($response) { return $response[0]; } ); } /** * Operation listPatRulesAsyncWithHttpInfo * * List PAT rules * * @param string $zone The zone you want to target (required) * @param string|null $order_by Order in which to return results. (optional, default to 'created_at_asc') * @param int|null $page Page number. (optional) * @param int|null $page_size PAT rules per page. (optional) * @param string[]|null $gateway_ids Filter for PAT rules on these gateways. (optional) * @param string[]|null $private_ips Filter for PAT rules targeting these private ips. (optional) * @param string|null $protocol Filter for PAT rules with this protocol. (optional, default to 'unknown_protocol') * @param string $contentType The value for the Content-Type header. Check self::contentTypes['listPatRules'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function listPatRulesAsyncWithHttpInfo($zone, $order_by = 'created_at_asc', $page = null, $page_size = null, $gateway_ids = null, $private_ips = null, $protocol = 'unknown_protocol', string $contentType = self::contentTypes['listPatRules'][0]) { $returnType = '\OpenAPI\Client\Model\ScalewayVpcGwV2ListPatRulesResponse'; $request = $this->listPatRulesRequest($zone, $order_by, $page, $page_size, $gateway_ids, $private_ips, $protocol, $contentType); return $this->client ->sendAsync($request, $this->createHttpClientOption()) ->then( function ($response) use ($returnType) { if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { $content = json_decode($content); } } return [ ObjectSerializer::deserialize($content, $returnType, []), $response->getStatusCode(), $response->getHeaders() ]; }, function ($exception) { $response = $exception->getResponse(); $statusCode = $response->getStatusCode(); throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, $exception->getRequest()->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } ); } /** * Create request for operation 'listPatRules' * * @param string $zone The zone you want to target (required) * @param string|null $order_by Order in which to return results. (optional, default to 'created_at_asc') * @param int|null $page Page number. (optional) * @param int|null $page_size PAT rules per page. (optional) * @param string[]|null $gateway_ids Filter for PAT rules on these gateways. (optional) * @param string[]|null $private_ips Filter for PAT rules targeting these private ips. (optional) * @param string|null $protocol Filter for PAT rules with this protocol. (optional, default to 'unknown_protocol') * @param string $contentType The value for the Content-Type header. Check self::contentTypes['listPatRules'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ public function listPatRulesRequest($zone, $order_by = 'created_at_asc', $page = null, $page_size = null, $gateway_ids = null, $private_ips = null, $protocol = 'unknown_protocol', string $contentType = self::contentTypes['listPatRules'][0]) { // verify the required parameter 'zone' is set if ($zone === null || (is_array($zone) && count($zone) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $zone when calling listPatRules' ); } $resourcePath = '/vpc-gw/v2/zones/{zone}/pat-rules'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $order_by, 'order_by', // param base name 'string', // openApiType 'form', // style true, // explode false // required ) ?? []); // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $page, 'page', // param base name 'integer', // openApiType 'form', // style true, // explode false // required ) ?? []); // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $page_size, 'page_size', // param base name 'integer', // openApiType 'form', // style true, // explode false // required ) ?? []); // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $gateway_ids, 'gateway_ids', // param base name 'array', // openApiType 'form', // style true, // explode false // required ) ?? []); // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $private_ips, 'private_ips', // param base name 'array', // openApiType 'form', // style true, // explode false // required ) ?? []); // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $protocol, 'protocol', // param base name 'string', // openApiType 'form', // style true, // explode false // required ) ?? []); // path params if ($zone !== null) { $resourcePath = str_replace( '{' . 'zone' . '}', ObjectSerializer::toPathValue($zone), $resourcePath ); } $headers = $this->headerSelector->selectHeaders( ['application/json', ], $contentType, $multipart ); // for model (json/xml) if (count($formParams) > 0) { if ($multipart) { $multipartContents = []; foreach ($formParams as $formParamName => $formParamValue) { $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; foreach ($formParamValueItems as $formParamValueItem) { $multipartContents[] = [ 'name' => $formParamName, 'contents' => $formParamValueItem ]; } } // for HTTP post (form) $httpBody = new MultipartStream($multipartContents); } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); } } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('X-Auth-Token'); if ($apiKey !== null) { $headers['X-Auth-Token'] = $apiKey; } $defaultHeaders = []; if ($this->config->getUserAgent()) { $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } $headers = array_merge( $defaultHeaders, $headerParams, $headers ); $operationHost = $this->config->getHost(); $query = ObjectSerializer::buildQuery($queryParams); return new Request( 'GET', $operationHost . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); } /** * Operation setPatRules * * Set all PAT rules * * @param string $zone The zone you want to target (required) * @param \OpenAPI\Client\Model\SetPatRulesRequest $set_pat_rules_request set_pat_rules_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['setPatRules'] to see the possible values for this operation * * @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return \OpenAPI\Client\Model\ScalewayVpcGwV2SetPatRulesResponse */ public function setPatRules($zone, $set_pat_rules_request, string $contentType = self::contentTypes['setPatRules'][0]) { list($response) = $this->setPatRulesWithHttpInfo($zone, $set_pat_rules_request, $contentType); return $response; } /** * Operation setPatRulesWithHttpInfo * * Set all PAT rules * * @param string $zone The zone you want to target (required) * @param \OpenAPI\Client\Model\SetPatRulesRequest $set_pat_rules_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['setPatRules'] to see the possible values for this operation * * @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return array of \OpenAPI\Client\Model\ScalewayVpcGwV2SetPatRulesResponse, HTTP status code, HTTP response headers (array of strings) */ public function setPatRulesWithHttpInfo($zone, $set_pat_rules_request, string $contentType = self::contentTypes['setPatRules'][0]) { $request = $this->setPatRulesRequest($zone, $set_pat_rules_request, $contentType); try { $options = $this->createHttpClientOption(); try { $response = $this->client->send($request, $options); } catch (RequestException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), $e->getResponse() ? $e->getResponse()->getHeaders() : null, $e->getResponse() ? (string) $e->getResponse()->getBody() : null ); } catch (ConnectException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), null, null ); } $statusCode = $response->getStatusCode(); switch($statusCode) { case 200: if ('\OpenAPI\Client\Model\ScalewayVpcGwV2SetPatRulesResponse' === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ('\OpenAPI\Client\Model\ScalewayVpcGwV2SetPatRulesResponse' !== 'string') { try { $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); } catch (\JsonException $exception) { throw new ApiException( sprintf( 'Error JSON decoding server response (%s)', $request->getUri() ), $statusCode, $response->getHeaders(), $content ); } } } return [ ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\ScalewayVpcGwV2SetPatRulesResponse', []), $response->getStatusCode(), $response->getHeaders() ]; } if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, (string) $request->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } $returnType = '\OpenAPI\Client\Model\ScalewayVpcGwV2SetPatRulesResponse'; if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { try { $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); } catch (\JsonException $exception) { throw new ApiException( sprintf( 'Error JSON decoding server response (%s)', $request->getUri() ), $statusCode, $response->getHeaders(), $content ); } } } return [ ObjectSerializer::deserialize($content, $returnType, []), $response->getStatusCode(), $response->getHeaders() ]; } catch (ApiException $e) { switch ($e->getCode()) { case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\OpenAPI\Client\Model\ScalewayVpcGwV2SetPatRulesResponse', $e->getResponseHeaders() ); $e->setResponseObject($data); break; } throw $e; } } /** * Operation setPatRulesAsync * * Set all PAT rules * * @param string $zone The zone you want to target (required) * @param \OpenAPI\Client\Model\SetPatRulesRequest $set_pat_rules_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['setPatRules'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function setPatRulesAsync($zone, $set_pat_rules_request, string $contentType = self::contentTypes['setPatRules'][0]) { return $this->setPatRulesAsyncWithHttpInfo($zone, $set_pat_rules_request, $contentType) ->then( function ($response) { return $response[0]; } ); } /** * Operation setPatRulesAsyncWithHttpInfo * * Set all PAT rules * * @param string $zone The zone you want to target (required) * @param \OpenAPI\Client\Model\SetPatRulesRequest $set_pat_rules_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['setPatRules'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function setPatRulesAsyncWithHttpInfo($zone, $set_pat_rules_request, string $contentType = self::contentTypes['setPatRules'][0]) { $returnType = '\OpenAPI\Client\Model\ScalewayVpcGwV2SetPatRulesResponse'; $request = $this->setPatRulesRequest($zone, $set_pat_rules_request, $contentType); return $this->client ->sendAsync($request, $this->createHttpClientOption()) ->then( function ($response) use ($returnType) { if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { $content = json_decode($content); } } return [ ObjectSerializer::deserialize($content, $returnType, []), $response->getStatusCode(), $response->getHeaders() ]; }, function ($exception) { $response = $exception->getResponse(); $statusCode = $response->getStatusCode(); throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, $exception->getRequest()->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } ); } /** * Create request for operation 'setPatRules' * * @param string $zone The zone you want to target (required) * @param \OpenAPI\Client\Model\SetPatRulesRequest $set_pat_rules_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['setPatRules'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ public function setPatRulesRequest($zone, $set_pat_rules_request, string $contentType = self::contentTypes['setPatRules'][0]) { // verify the required parameter 'zone' is set if ($zone === null || (is_array($zone) && count($zone) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $zone when calling setPatRules' ); } // verify the required parameter 'set_pat_rules_request' is set if ($set_pat_rules_request === null || (is_array($set_pat_rules_request) && count($set_pat_rules_request) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $set_pat_rules_request when calling setPatRules' ); } $resourcePath = '/vpc-gw/v2/zones/{zone}/pat-rules'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; // path params if ($zone !== null) { $resourcePath = str_replace( '{' . 'zone' . '}', ObjectSerializer::toPathValue($zone), $resourcePath ); } $headers = $this->headerSelector->selectHeaders( ['application/json', ], $contentType, $multipart ); // for model (json/xml) if (isset($set_pat_rules_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($set_pat_rules_request)); } else { $httpBody = $set_pat_rules_request; } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; foreach ($formParams as $formParamName => $formParamValue) { $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; foreach ($formParamValueItems as $formParamValueItem) { $multipartContents[] = [ 'name' => $formParamName, 'contents' => $formParamValueItem ]; } } // for HTTP post (form) $httpBody = new MultipartStream($multipartContents); } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); } } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('X-Auth-Token'); if ($apiKey !== null) { $headers['X-Auth-Token'] = $apiKey; } $defaultHeaders = []; if ($this->config->getUserAgent()) { $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } $headers = array_merge( $defaultHeaders, $headerParams, $headers ); $operationHost = $this->config->getHost(); $query = ObjectSerializer::buildQuery($queryParams); return new Request( 'PUT', $operationHost . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); } /** * Operation updatePatRule * * Update a PAT rule * * @param string $zone The zone you want to target (required) * @param string $pat_rule_id ID of the PAT rule to update. (UUID format) (required) * @param \OpenAPI\Client\Model\UpdatePatRuleRequest $update_pat_rule_request update_pat_rule_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['updatePatRule'] to see the possible values for this operation * * @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return \OpenAPI\Client\Model\ScalewayVpcGwV2PatRule */ public function updatePatRule($zone, $pat_rule_id, $update_pat_rule_request, string $contentType = self::contentTypes['updatePatRule'][0]) { list($response) = $this->updatePatRuleWithHttpInfo($zone, $pat_rule_id, $update_pat_rule_request, $contentType); return $response; } /** * Operation updatePatRuleWithHttpInfo * * Update a PAT rule * * @param string $zone The zone you want to target (required) * @param string $pat_rule_id ID of the PAT rule to update. (UUID format) (required) * @param \OpenAPI\Client\Model\UpdatePatRuleRequest $update_pat_rule_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['updatePatRule'] to see the possible values for this operation * * @throws \OpenAPI\Client\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return array of \OpenAPI\Client\Model\ScalewayVpcGwV2PatRule, HTTP status code, HTTP response headers (array of strings) */ public function updatePatRuleWithHttpInfo($zone, $pat_rule_id, $update_pat_rule_request, string $contentType = self::contentTypes['updatePatRule'][0]) { $request = $this->updatePatRuleRequest($zone, $pat_rule_id, $update_pat_rule_request, $contentType); try { $options = $this->createHttpClientOption(); try { $response = $this->client->send($request, $options); } catch (RequestException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), $e->getResponse() ? $e->getResponse()->getHeaders() : null, $e->getResponse() ? (string) $e->getResponse()->getBody() : null ); } catch (ConnectException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), null, null ); } $statusCode = $response->getStatusCode(); switch($statusCode) { case 200: if ('\OpenAPI\Client\Model\ScalewayVpcGwV2PatRule' === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ('\OpenAPI\Client\Model\ScalewayVpcGwV2PatRule' !== 'string') { try { $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); } catch (\JsonException $exception) { throw new ApiException( sprintf( 'Error JSON decoding server response (%s)', $request->getUri() ), $statusCode, $response->getHeaders(), $content ); } } } return [ ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\ScalewayVpcGwV2PatRule', []), $response->getStatusCode(), $response->getHeaders() ]; } if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, (string) $request->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } $returnType = '\OpenAPI\Client\Model\ScalewayVpcGwV2PatRule'; if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { try { $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); } catch (\JsonException $exception) { throw new ApiException( sprintf( 'Error JSON decoding server response (%s)', $request->getUri() ), $statusCode, $response->getHeaders(), $content ); } } } return [ ObjectSerializer::deserialize($content, $returnType, []), $response->getStatusCode(), $response->getHeaders() ]; } catch (ApiException $e) { switch ($e->getCode()) { case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\OpenAPI\Client\Model\ScalewayVpcGwV2PatRule', $e->getResponseHeaders() ); $e->setResponseObject($data); break; } throw $e; } } /** * Operation updatePatRuleAsync * * Update a PAT rule * * @param string $zone The zone you want to target (required) * @param string $pat_rule_id ID of the PAT rule to update. (UUID format) (required) * @param \OpenAPI\Client\Model\UpdatePatRuleRequest $update_pat_rule_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['updatePatRule'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function updatePatRuleAsync($zone, $pat_rule_id, $update_pat_rule_request, string $contentType = self::contentTypes['updatePatRule'][0]) { return $this->updatePatRuleAsyncWithHttpInfo($zone, $pat_rule_id, $update_pat_rule_request, $contentType) ->then( function ($response) { return $response[0]; } ); } /** * Operation updatePatRuleAsyncWithHttpInfo * * Update a PAT rule * * @param string $zone The zone you want to target (required) * @param string $pat_rule_id ID of the PAT rule to update. (UUID format) (required) * @param \OpenAPI\Client\Model\UpdatePatRuleRequest $update_pat_rule_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['updatePatRule'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function updatePatRuleAsyncWithHttpInfo($zone, $pat_rule_id, $update_pat_rule_request, string $contentType = self::contentTypes['updatePatRule'][0]) { $returnType = '\OpenAPI\Client\Model\ScalewayVpcGwV2PatRule'; $request = $this->updatePatRuleRequest($zone, $pat_rule_id, $update_pat_rule_request, $contentType); return $this->client ->sendAsync($request, $this->createHttpClientOption()) ->then( function ($response) use ($returnType) { if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { $content = json_decode($content); } } return [ ObjectSerializer::deserialize($content, $returnType, []), $response->getStatusCode(), $response->getHeaders() ]; }, function ($exception) { $response = $exception->getResponse(); $statusCode = $response->getStatusCode(); throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, $exception->getRequest()->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } ); } /** * Create request for operation 'updatePatRule' * * @param string $zone The zone you want to target (required) * @param string $pat_rule_id ID of the PAT rule to update. (UUID format) (required) * @param \OpenAPI\Client\Model\UpdatePatRuleRequest $update_pat_rule_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['updatePatRule'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ public function updatePatRuleRequest($zone, $pat_rule_id, $update_pat_rule_request, string $contentType = self::contentTypes['updatePatRule'][0]) { // verify the required parameter 'zone' is set if ($zone === null || (is_array($zone) && count($zone) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $zone when calling updatePatRule' ); } // verify the required parameter 'pat_rule_id' is set if ($pat_rule_id === null || (is_array($pat_rule_id) && count($pat_rule_id) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $pat_rule_id when calling updatePatRule' ); } // verify the required parameter 'update_pat_rule_request' is set if ($update_pat_rule_request === null || (is_array($update_pat_rule_request) && count($update_pat_rule_request) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $update_pat_rule_request when calling updatePatRule' ); } $resourcePath = '/vpc-gw/v2/zones/{zone}/pat-rules/{pat_rule_id}'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; // path params if ($zone !== null) { $resourcePath = str_replace( '{' . 'zone' . '}', ObjectSerializer::toPathValue($zone), $resourcePath ); } // path params if ($pat_rule_id !== null) { $resourcePath = str_replace( '{' . 'pat_rule_id' . '}', ObjectSerializer::toPathValue($pat_rule_id), $resourcePath ); } $headers = $this->headerSelector->selectHeaders( ['application/json', ], $contentType, $multipart ); // for model (json/xml) if (isset($update_pat_rule_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($update_pat_rule_request)); } else { $httpBody = $update_pat_rule_request; } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; foreach ($formParams as $formParamName => $formParamValue) { $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; foreach ($formParamValueItems as $formParamValueItem) { $multipartContents[] = [ 'name' => $formParamName, 'contents' => $formParamValueItem ]; } } // for HTTP post (form) $httpBody = new MultipartStream($multipartContents); } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); } } // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('X-Auth-Token'); if ($apiKey !== null) { $headers['X-Auth-Token'] = $apiKey; } $defaultHeaders = []; if ($this->config->getUserAgent()) { $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } $headers = array_merge( $defaultHeaders, $headerParams, $headers ); $operationHost = $this->config->getHost(); $query = ObjectSerializer::buildQuery($queryParams); return new Request( 'PATCH', $operationHost . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); } /** * Create http client option * * @throws \RuntimeException on file opening failure * @return array of http client options */ protected function createHttpClientOption() { $options = []; if ($this->config->getDebug()) { $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a'); if (!$options[RequestOptions::DEBUG]) { throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile()); } } return $options; } }