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; /** * IPsApi Class Doc Comment * * @category Class * @package OpenAPI\Client * @author OpenAPI Generator team * @link https://openapi-generator.tech */ class IPsApi { /** * @var ClientInterface */ protected $client; /** * @var Configuration */ protected $config; /** * @var HeaderSelector */ protected $headerSelector; /** * @var int Host index */ protected $hostIndex; /** @var string[] $contentTypes **/ public const contentTypes = [ 'createIP' => [ 'application/json', ], 'deleteIP' => [ 'application/json', ], 'getIP' => [ 'application/json', ], 'listIPs' => [ 'application/json', ], 'updateIP' => [ '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 createIP * * Reserve an IP * * @param string $zone The zone you want to target (required) * @param \OpenAPI\Client\Model\CreateIPRequest $create_ip_request create_ip_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['createIP'] 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\ScalewayVpcGwV2IP */ public function createIP($zone, $create_ip_request, string $contentType = self::contentTypes['createIP'][0]) { list($response) = $this->createIPWithHttpInfo($zone, $create_ip_request, $contentType); return $response; } /** * Operation createIPWithHttpInfo * * Reserve an IP * * @param string $zone The zone you want to target (required) * @param \OpenAPI\Client\Model\CreateIPRequest $create_ip_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['createIP'] 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\ScalewayVpcGwV2IP, HTTP status code, HTTP response headers (array of strings) */ public function createIPWithHttpInfo($zone, $create_ip_request, string $contentType = self::contentTypes['createIP'][0]) { $request = $this->createIPRequest($zone, $create_ip_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\ScalewayVpcGwV2IP' === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ('\OpenAPI\Client\Model\ScalewayVpcGwV2IP' !== '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\ScalewayVpcGwV2IP', []), $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\ScalewayVpcGwV2IP'; 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\ScalewayVpcGwV2IP', $e->getResponseHeaders() ); $e->setResponseObject($data); break; } throw $e; } } /** * Operation createIPAsync * * Reserve an IP * * @param string $zone The zone you want to target (required) * @param \OpenAPI\Client\Model\CreateIPRequest $create_ip_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['createIP'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function createIPAsync($zone, $create_ip_request, string $contentType = self::contentTypes['createIP'][0]) { return $this->createIPAsyncWithHttpInfo($zone, $create_ip_request, $contentType) ->then( function ($response) { return $response[0]; } ); } /** * Operation createIPAsyncWithHttpInfo * * Reserve an IP * * @param string $zone The zone you want to target (required) * @param \OpenAPI\Client\Model\CreateIPRequest $create_ip_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['createIP'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function createIPAsyncWithHttpInfo($zone, $create_ip_request, string $contentType = self::contentTypes['createIP'][0]) { $returnType = '\OpenAPI\Client\Model\ScalewayVpcGwV2IP'; $request = $this->createIPRequest($zone, $create_ip_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 'createIP' * * @param string $zone The zone you want to target (required) * @param \OpenAPI\Client\Model\CreateIPRequest $create_ip_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['createIP'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ public function createIPRequest($zone, $create_ip_request, string $contentType = self::contentTypes['createIP'][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 createIP' ); } // verify the required parameter 'create_ip_request' is set if ($create_ip_request === null || (is_array($create_ip_request) && count($create_ip_request) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $create_ip_request when calling createIP' ); } $resourcePath = '/vpc-gw/v2/zones/{zone}/ips'; $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_ip_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_ip_request)); } else { $httpBody = $create_ip_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 deleteIP * * Delete an IP * * @param string $zone The zone you want to target (required) * @param string $ip_id ID of the IP address to delete. (UUID format) (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteIP'] 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 deleteIP($zone, $ip_id, string $contentType = self::contentTypes['deleteIP'][0]) { $this->deleteIPWithHttpInfo($zone, $ip_id, $contentType); } /** * Operation deleteIPWithHttpInfo * * Delete an IP * * @param string $zone The zone you want to target (required) * @param string $ip_id ID of the IP address to delete. (UUID format) (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteIP'] 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 deleteIPWithHttpInfo($zone, $ip_id, string $contentType = self::contentTypes['deleteIP'][0]) { $request = $this->deleteIPRequest($zone, $ip_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 deleteIPAsync * * Delete an IP * * @param string $zone The zone you want to target (required) * @param string $ip_id ID of the IP address to delete. (UUID format) (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteIP'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function deleteIPAsync($zone, $ip_id, string $contentType = self::contentTypes['deleteIP'][0]) { return $this->deleteIPAsyncWithHttpInfo($zone, $ip_id, $contentType) ->then( function ($response) { return $response[0]; } ); } /** * Operation deleteIPAsyncWithHttpInfo * * Delete an IP * * @param string $zone The zone you want to target (required) * @param string $ip_id ID of the IP address to delete. (UUID format) (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteIP'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function deleteIPAsyncWithHttpInfo($zone, $ip_id, string $contentType = self::contentTypes['deleteIP'][0]) { $returnType = ''; $request = $this->deleteIPRequest($zone, $ip_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 'deleteIP' * * @param string $zone The zone you want to target (required) * @param string $ip_id ID of the IP address to delete. (UUID format) (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteIP'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ public function deleteIPRequest($zone, $ip_id, string $contentType = self::contentTypes['deleteIP'][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 deleteIP' ); } // verify the required parameter 'ip_id' is set if ($ip_id === null || (is_array($ip_id) && count($ip_id) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $ip_id when calling deleteIP' ); } $resourcePath = '/vpc-gw/v2/zones/{zone}/ips/{ip_id}'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; // path params if ($zone !== null) { $resourcePath = str_replace( '{' . 'zone' . '}', ObjectSerializer::toPathValue($zone), $resourcePath ); } // path params if ($ip_id !== null) { $resourcePath = str_replace( '{' . 'ip_id' . '}', ObjectSerializer::toPathValue($ip_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 getIP * * Get an IP * * @param string $zone The zone you want to target (required) * @param string $ip_id ID of the IP address to get. (UUID format) (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getIP'] 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\ScalewayVpcGwV2IP */ public function getIP($zone, $ip_id, string $contentType = self::contentTypes['getIP'][0]) { list($response) = $this->getIPWithHttpInfo($zone, $ip_id, $contentType); return $response; } /** * Operation getIPWithHttpInfo * * Get an IP * * @param string $zone The zone you want to target (required) * @param string $ip_id ID of the IP address to get. (UUID format) (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getIP'] 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\ScalewayVpcGwV2IP, HTTP status code, HTTP response headers (array of strings) */ public function getIPWithHttpInfo($zone, $ip_id, string $contentType = self::contentTypes['getIP'][0]) { $request = $this->getIPRequest($zone, $ip_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\ScalewayVpcGwV2IP' === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ('\OpenAPI\Client\Model\ScalewayVpcGwV2IP' !== '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\ScalewayVpcGwV2IP', []), $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\ScalewayVpcGwV2IP'; 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\ScalewayVpcGwV2IP', $e->getResponseHeaders() ); $e->setResponseObject($data); break; } throw $e; } } /** * Operation getIPAsync * * Get an IP * * @param string $zone The zone you want to target (required) * @param string $ip_id ID of the IP address to get. (UUID format) (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getIP'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function getIPAsync($zone, $ip_id, string $contentType = self::contentTypes['getIP'][0]) { return $this->getIPAsyncWithHttpInfo($zone, $ip_id, $contentType) ->then( function ($response) { return $response[0]; } ); } /** * Operation getIPAsyncWithHttpInfo * * Get an IP * * @param string $zone The zone you want to target (required) * @param string $ip_id ID of the IP address to get. (UUID format) (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getIP'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function getIPAsyncWithHttpInfo($zone, $ip_id, string $contentType = self::contentTypes['getIP'][0]) { $returnType = '\OpenAPI\Client\Model\ScalewayVpcGwV2IP'; $request = $this->getIPRequest($zone, $ip_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 'getIP' * * @param string $zone The zone you want to target (required) * @param string $ip_id ID of the IP address to get. (UUID format) (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getIP'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ public function getIPRequest($zone, $ip_id, string $contentType = self::contentTypes['getIP'][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 getIP' ); } // verify the required parameter 'ip_id' is set if ($ip_id === null || (is_array($ip_id) && count($ip_id) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $ip_id when calling getIP' ); } $resourcePath = '/vpc-gw/v2/zones/{zone}/ips/{ip_id}'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; // path params if ($zone !== null) { $resourcePath = str_replace( '{' . 'zone' . '}', ObjectSerializer::toPathValue($zone), $resourcePath ); } // path params if ($ip_id !== null) { $resourcePath = str_replace( '{' . 'ip_id' . '}', ObjectSerializer::toPathValue($ip_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 listIPs * * List IPs * * @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 IP addresses per page. (optional) * @param string|null $organization_id Include only gateways in this Organization. (UUID format) (optional) * @param string|null $project_id Filter for IP addresses in this Project. (UUID format) (optional) * @param string[]|null $tags Filter for IP addresses with these tags. (optional) * @param string|null $reverse Filter for IP addresses that have a reverse containing this string. (optional) * @param bool|null $is_free Filter based on whether the IP is attached to a gateway or not. (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['listIPs'] 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\ScalewayVpcGwV2ListIPsResponse */ public function listIPs($zone, $order_by = 'created_at_asc', $page = null, $page_size = null, $organization_id = null, $project_id = null, $tags = null, $reverse = null, $is_free = null, string $contentType = self::contentTypes['listIPs'][0]) { list($response) = $this->listIPsWithHttpInfo($zone, $order_by, $page, $page_size, $organization_id, $project_id, $tags, $reverse, $is_free, $contentType); return $response; } /** * Operation listIPsWithHttpInfo * * List IPs * * @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 IP addresses per page. (optional) * @param string|null $organization_id Include only gateways in this Organization. (UUID format) (optional) * @param string|null $project_id Filter for IP addresses in this Project. (UUID format) (optional) * @param string[]|null $tags Filter for IP addresses with these tags. (optional) * @param string|null $reverse Filter for IP addresses that have a reverse containing this string. (optional) * @param bool|null $is_free Filter based on whether the IP is attached to a gateway or not. (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['listIPs'] 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\ScalewayVpcGwV2ListIPsResponse, HTTP status code, HTTP response headers (array of strings) */ public function listIPsWithHttpInfo($zone, $order_by = 'created_at_asc', $page = null, $page_size = null, $organization_id = null, $project_id = null, $tags = null, $reverse = null, $is_free = null, string $contentType = self::contentTypes['listIPs'][0]) { $request = $this->listIPsRequest($zone, $order_by, $page, $page_size, $organization_id, $project_id, $tags, $reverse, $is_free, $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\ScalewayVpcGwV2ListIPsResponse' === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ('\OpenAPI\Client\Model\ScalewayVpcGwV2ListIPsResponse' !== '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\ScalewayVpcGwV2ListIPsResponse', []), $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\ScalewayVpcGwV2ListIPsResponse'; 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\ScalewayVpcGwV2ListIPsResponse', $e->getResponseHeaders() ); $e->setResponseObject($data); break; } throw $e; } } /** * Operation listIPsAsync * * List IPs * * @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 IP addresses per page. (optional) * @param string|null $organization_id Include only gateways in this Organization. (UUID format) (optional) * @param string|null $project_id Filter for IP addresses in this Project. (UUID format) (optional) * @param string[]|null $tags Filter for IP addresses with these tags. (optional) * @param string|null $reverse Filter for IP addresses that have a reverse containing this string. (optional) * @param bool|null $is_free Filter based on whether the IP is attached to a gateway or not. (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['listIPs'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function listIPsAsync($zone, $order_by = 'created_at_asc', $page = null, $page_size = null, $organization_id = null, $project_id = null, $tags = null, $reverse = null, $is_free = null, string $contentType = self::contentTypes['listIPs'][0]) { return $this->listIPsAsyncWithHttpInfo($zone, $order_by, $page, $page_size, $organization_id, $project_id, $tags, $reverse, $is_free, $contentType) ->then( function ($response) { return $response[0]; } ); } /** * Operation listIPsAsyncWithHttpInfo * * List IPs * * @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 IP addresses per page. (optional) * @param string|null $organization_id Include only gateways in this Organization. (UUID format) (optional) * @param string|null $project_id Filter for IP addresses in this Project. (UUID format) (optional) * @param string[]|null $tags Filter for IP addresses with these tags. (optional) * @param string|null $reverse Filter for IP addresses that have a reverse containing this string. (optional) * @param bool|null $is_free Filter based on whether the IP is attached to a gateway or not. (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['listIPs'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function listIPsAsyncWithHttpInfo($zone, $order_by = 'created_at_asc', $page = null, $page_size = null, $organization_id = null, $project_id = null, $tags = null, $reverse = null, $is_free = null, string $contentType = self::contentTypes['listIPs'][0]) { $returnType = '\OpenAPI\Client\Model\ScalewayVpcGwV2ListIPsResponse'; $request = $this->listIPsRequest($zone, $order_by, $page, $page_size, $organization_id, $project_id, $tags, $reverse, $is_free, $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 'listIPs' * * @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 IP addresses per page. (optional) * @param string|null $organization_id Include only gateways in this Organization. (UUID format) (optional) * @param string|null $project_id Filter for IP addresses in this Project. (UUID format) (optional) * @param string[]|null $tags Filter for IP addresses with these tags. (optional) * @param string|null $reverse Filter for IP addresses that have a reverse containing this string. (optional) * @param bool|null $is_free Filter based on whether the IP is attached to a gateway or not. (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['listIPs'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ public function listIPsRequest($zone, $order_by = 'created_at_asc', $page = null, $page_size = null, $organization_id = null, $project_id = null, $tags = null, $reverse = null, $is_free = null, string $contentType = self::contentTypes['listIPs'][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 listIPs' ); } $resourcePath = '/vpc-gw/v2/zones/{zone}/ips'; $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( $organization_id, 'organization_id', // param base name 'string', // openApiType 'form', // style true, // explode false // required ) ?? []); // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $project_id, 'project_id', // param base name 'string', // openApiType 'form', // style true, // explode false // required ) ?? []); // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $tags, 'tags', // param base name 'array', // openApiType 'form', // style true, // explode false // required ) ?? []); // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $reverse, 'reverse', // param base name 'string', // openApiType 'form', // style true, // explode false // required ) ?? []); // query params $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( $is_free, 'is_free', // param base name 'boolean', // 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 updateIP * * Update an IP * * @param string $zone The zone you want to target (required) * @param string $ip_id ID of the IP address to update. (UUID format) (required) * @param \OpenAPI\Client\Model\UpdateIPRequest $update_ip_request update_ip_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['updateIP'] 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\ScalewayVpcGwV2IP */ public function updateIP($zone, $ip_id, $update_ip_request, string $contentType = self::contentTypes['updateIP'][0]) { list($response) = $this->updateIPWithHttpInfo($zone, $ip_id, $update_ip_request, $contentType); return $response; } /** * Operation updateIPWithHttpInfo * * Update an IP * * @param string $zone The zone you want to target (required) * @param string $ip_id ID of the IP address to update. (UUID format) (required) * @param \OpenAPI\Client\Model\UpdateIPRequest $update_ip_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['updateIP'] 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\ScalewayVpcGwV2IP, HTTP status code, HTTP response headers (array of strings) */ public function updateIPWithHttpInfo($zone, $ip_id, $update_ip_request, string $contentType = self::contentTypes['updateIP'][0]) { $request = $this->updateIPRequest($zone, $ip_id, $update_ip_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\ScalewayVpcGwV2IP' === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ('\OpenAPI\Client\Model\ScalewayVpcGwV2IP' !== '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\ScalewayVpcGwV2IP', []), $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\ScalewayVpcGwV2IP'; 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\ScalewayVpcGwV2IP', $e->getResponseHeaders() ); $e->setResponseObject($data); break; } throw $e; } } /** * Operation updateIPAsync * * Update an IP * * @param string $zone The zone you want to target (required) * @param string $ip_id ID of the IP address to update. (UUID format) (required) * @param \OpenAPI\Client\Model\UpdateIPRequest $update_ip_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['updateIP'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function updateIPAsync($zone, $ip_id, $update_ip_request, string $contentType = self::contentTypes['updateIP'][0]) { return $this->updateIPAsyncWithHttpInfo($zone, $ip_id, $update_ip_request, $contentType) ->then( function ($response) { return $response[0]; } ); } /** * Operation updateIPAsyncWithHttpInfo * * Update an IP * * @param string $zone The zone you want to target (required) * @param string $ip_id ID of the IP address to update. (UUID format) (required) * @param \OpenAPI\Client\Model\UpdateIPRequest $update_ip_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['updateIP'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function updateIPAsyncWithHttpInfo($zone, $ip_id, $update_ip_request, string $contentType = self::contentTypes['updateIP'][0]) { $returnType = '\OpenAPI\Client\Model\ScalewayVpcGwV2IP'; $request = $this->updateIPRequest($zone, $ip_id, $update_ip_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 'updateIP' * * @param string $zone The zone you want to target (required) * @param string $ip_id ID of the IP address to update. (UUID format) (required) * @param \OpenAPI\Client\Model\UpdateIPRequest $update_ip_request (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['updateIP'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ public function updateIPRequest($zone, $ip_id, $update_ip_request, string $contentType = self::contentTypes['updateIP'][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 updateIP' ); } // verify the required parameter 'ip_id' is set if ($ip_id === null || (is_array($ip_id) && count($ip_id) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $ip_id when calling updateIP' ); } // verify the required parameter 'update_ip_request' is set if ($update_ip_request === null || (is_array($update_ip_request) && count($update_ip_request) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $update_ip_request when calling updateIP' ); } $resourcePath = '/vpc-gw/v2/zones/{zone}/ips/{ip_id}'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; // path params if ($zone !== null) { $resourcePath = str_replace( '{' . 'zone' . '}', ObjectSerializer::toPathValue($zone), $resourcePath ); } // path params if ($ip_id !== null) { $resourcePath = str_replace( '{' . 'ip_id' . '}', ObjectSerializer::toPathValue($ip_id), $resourcePath ); } $headers = $this->headerSelector->selectHeaders( ['application/json', ], $contentType, $multipart ); // for model (json/xml) if (isset($update_ip_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_ip_request)); } else { $httpBody = $update_ip_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; } }