diff --git a/Vision/src/V1/AddProductToProductSetRequest.php b/Vision/src/V1/AddProductToProductSetRequest.php index d4333d17298e..b63cb1879314 100644 --- a/Vision/src/V1/AddProductToProductSetRequest.php +++ b/Vision/src/V1/AddProductToProductSetRequest.php @@ -32,6 +32,29 @@ class AddProductToProductSetRequest extends \Google\Protobuf\Internal\Message */ private $product = ''; + /** + * @param string $name Required. The resource name for the ProductSet to modify. + * + * Format is: + * `projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID` + * Please see {@see ProductSearchClient::productSetName()} for help formatting this field. + * @param string $product Required. The resource name for the Product to be added to this ProductSet. + * + * Format is: + * `projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID` + * Please see {@see ProductSearchClient::productName()} for help formatting this field. + * + * @return \Google\Cloud\Vision\V1\AddProductToProductSetRequest + * + * @experimental + */ + public static function build(string $name, string $product): self + { + return (new self()) + ->setName($name) + ->setProduct($product); + } + /** * Constructor. * diff --git a/Vision/src/V1/AsyncBatchAnnotateFilesRequest.php b/Vision/src/V1/AsyncBatchAnnotateFilesRequest.php index 53199fb8405e..404de6b27ac6 100644 --- a/Vision/src/V1/AsyncBatchAnnotateFilesRequest.php +++ b/Vision/src/V1/AsyncBatchAnnotateFilesRequest.php @@ -36,6 +36,19 @@ class AsyncBatchAnnotateFilesRequest extends \Google\Protobuf\Internal\Message */ private $parent = ''; + /** + * @param \Google\Cloud\Vision\V1\AsyncAnnotateFileRequest[] $requests Required. Individual async file annotation requests for this batch. + * + * @return \Google\Cloud\Vision\V1\AsyncBatchAnnotateFilesRequest + * + * @experimental + */ + public static function build(array $requests): self + { + return (new self()) + ->setRequests($requests); + } + /** * Constructor. * diff --git a/Vision/src/V1/AsyncBatchAnnotateImagesRequest.php b/Vision/src/V1/AsyncBatchAnnotateImagesRequest.php index a7a498180eaf..e9a686aed5c2 100644 --- a/Vision/src/V1/AsyncBatchAnnotateImagesRequest.php +++ b/Vision/src/V1/AsyncBatchAnnotateImagesRequest.php @@ -41,6 +41,21 @@ class AsyncBatchAnnotateImagesRequest extends \Google\Protobuf\Internal\Message */ private $parent = ''; + /** + * @param \Google\Cloud\Vision\V1\AnnotateImageRequest[] $requests Required. Individual image annotation requests for this batch. + * @param \Google\Cloud\Vision\V1\OutputConfig $outputConfig Required. The desired output location and metadata (e.g. format). + * + * @return \Google\Cloud\Vision\V1\AsyncBatchAnnotateImagesRequest + * + * @experimental + */ + public static function build(array $requests, \Google\Cloud\Vision\V1\OutputConfig $outputConfig): self + { + return (new self()) + ->setRequests($requests) + ->setOutputConfig($outputConfig); + } + /** * Constructor. * diff --git a/Vision/src/V1/BatchAnnotateFilesRequest.php b/Vision/src/V1/BatchAnnotateFilesRequest.php index ffcbb366d4df..9176fad5c393 100644 --- a/Vision/src/V1/BatchAnnotateFilesRequest.php +++ b/Vision/src/V1/BatchAnnotateFilesRequest.php @@ -36,6 +36,20 @@ class BatchAnnotateFilesRequest extends \Google\Protobuf\Internal\Message */ private $parent = ''; + /** + * @param \Google\Cloud\Vision\V1\AnnotateFileRequest[] $requests Required. The list of file annotation requests. Right now we support only one + * AnnotateFileRequest in BatchAnnotateFilesRequest. + * + * @return \Google\Cloud\Vision\V1\BatchAnnotateFilesRequest + * + * @experimental + */ + public static function build(array $requests): self + { + return (new self()) + ->setRequests($requests); + } + /** * Constructor. * diff --git a/Vision/src/V1/BatchAnnotateImagesRequest.php b/Vision/src/V1/BatchAnnotateImagesRequest.php index ffe3d0a569e1..e2a66c07a760 100644 --- a/Vision/src/V1/BatchAnnotateImagesRequest.php +++ b/Vision/src/V1/BatchAnnotateImagesRequest.php @@ -35,6 +35,19 @@ class BatchAnnotateImagesRequest extends \Google\Protobuf\Internal\Message */ private $parent = ''; + /** + * @param \Google\Cloud\Vision\V1\AnnotateImageRequest[] $requests Required. Individual image annotation requests for this batch. + * + * @return \Google\Cloud\Vision\V1\BatchAnnotateImagesRequest + * + * @experimental + */ + public static function build(array $requests): self + { + return (new self()) + ->setRequests($requests); + } + /** * Constructor. * diff --git a/Vision/src/V1/Client/BaseClient/ImageAnnotatorBaseClient.php b/Vision/src/V1/Client/BaseClient/ImageAnnotatorBaseClient.php new file mode 100644 index 000000000000..400f0b7dd704 --- /dev/null +++ b/Vision/src/V1/Client/BaseClient/ImageAnnotatorBaseClient.php @@ -0,0 +1,376 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/image_annotator_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/image_annotator_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/image_annotator_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/image_annotator_rest_client_config.php', + ], + ], + ]; + } + + /** + * Return an OperationsClient object with the same endpoint as $this. + * + * @return OperationsClient + */ + public function getOperationsClient() + { + return $this->operationsClient; + } + + /** + * Resume an existing long running operation that was previously started by a long + * running API method. If $methodName is not provided, or does not match a long + * running API method, then the operation can still be resumed, but the + * OperationResponse object will not deserialize the final response. + * + * @param string $operationName The name of the long running operation + * @param string $methodName The name of the method used to start the operation + * + * @return OperationResponse + */ + public function resumeOperation($operationName, $methodName = null) + { + $options = isset($this->descriptors[$methodName]['longRunning']) ? $this->descriptors[$methodName]['longRunning'] : []; + $operation = new OperationResponse($operationName, $this->getOperationsClient(), $options); + $operation->reload(); + return $operation; + } + + /** + * Formats a string containing the fully-qualified path to represent a product_set + * resource. + * + * @param string $project + * @param string $location + * @param string $productSet + * + * @return string The formatted product_set resource. + */ + public static function productSetName(string $project, string $location, string $productSet): string + { + return self::getPathTemplate('productSet')->render([ + 'project' => $project, + 'location' => $location, + 'product_set' => $productSet, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - productSet: projects/{project}/locations/{location}/productSets/{product_set} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'vision.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * } + * + * @throws ValidationException + */ + public function __construct(array $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + $this->operationsClient = $this->createOperationsClient($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Run asynchronous image detection and annotation for a list of generic + * files, such as PDF files, which may contain multiple pages and multiple + * images per page. Progress and results can be retrieved through the + * `google.longrunning.Operations` interface. + * `Operation.metadata` contains `OperationMetadata` (metadata). + * `Operation.response` contains `AsyncBatchAnnotateFilesResponse` (results). + * + * The async variant is {@see self::asyncBatchAnnotateFilesAsync()} . + * + * @param AsyncBatchAnnotateFilesRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function asyncBatchAnnotateFiles(AsyncBatchAnnotateFilesRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('AsyncBatchAnnotateFiles', $request, $callOptions)->wait(); + } + + /** + * Run asynchronous image detection and annotation for a list of images. + * + * Progress and results can be retrieved through the + * `google.longrunning.Operations` interface. + * `Operation.metadata` contains `OperationMetadata` (metadata). + * `Operation.response` contains `AsyncBatchAnnotateImagesResponse` (results). + * + * This service will write image annotation outputs to json files in customer + * GCS bucket, each json file containing BatchAnnotateImagesResponse proto. + * + * The async variant is {@see self::asyncBatchAnnotateImagesAsync()} . + * + * @param AsyncBatchAnnotateImagesRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function asyncBatchAnnotateImages(AsyncBatchAnnotateImagesRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('AsyncBatchAnnotateImages', $request, $callOptions)->wait(); + } + + /** + * Service that performs image detection and annotation for a batch of files. + * Now only "application/pdf", "image/tiff" and "image/gif" are supported. + * + * This service will extract at most 5 (customers can specify which 5 in + * AnnotateFileRequest.pages) frames (gif) or pages (pdf or tiff) from each + * file provided and perform detection and annotation for each image + * extracted. + * + * The async variant is {@see self::batchAnnotateFilesAsync()} . + * + * @param BatchAnnotateFilesRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return BatchAnnotateFilesResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function batchAnnotateFiles(BatchAnnotateFilesRequest $request, array $callOptions = []): BatchAnnotateFilesResponse + { + return $this->startApiCall('BatchAnnotateFiles', $request, $callOptions)->wait(); + } + + /** + * Run image detection and annotation for a batch of images. + * + * The async variant is {@see self::batchAnnotateImagesAsync()} . + * + * @param BatchAnnotateImagesRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return BatchAnnotateImagesResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function batchAnnotateImages(BatchAnnotateImagesRequest $request, array $callOptions = []): BatchAnnotateImagesResponse + { + return $this->startApiCall('BatchAnnotateImages', $request, $callOptions)->wait(); + } +} diff --git a/Vision/src/V1/Client/BaseClient/ProductSearchBaseClient.php b/Vision/src/V1/Client/BaseClient/ProductSearchBaseClient.php new file mode 100644 index 000000000000..39749869dae0 --- /dev/null +++ b/Vision/src/V1/Client/BaseClient/ProductSearchBaseClient.php @@ -0,0 +1,945 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/product_search_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/product_search_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/product_search_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/product_search_rest_client_config.php', + ], + ], + ]; + } + + /** + * Return an OperationsClient object with the same endpoint as $this. + * + * @return OperationsClient + */ + public function getOperationsClient() + { + return $this->operationsClient; + } + + /** + * Resume an existing long running operation that was previously started by a long + * running API method. If $methodName is not provided, or does not match a long + * running API method, then the operation can still be resumed, but the + * OperationResponse object will not deserialize the final response. + * + * @param string $operationName The name of the long running operation + * @param string $methodName The name of the method used to start the operation + * + * @return OperationResponse + */ + public function resumeOperation($operationName, $methodName = null) + { + $options = isset($this->descriptors[$methodName]['longRunning']) ? $this->descriptors[$methodName]['longRunning'] : []; + $operation = new OperationResponse($operationName, $this->getOperationsClient(), $options); + $operation->reload(); + return $operation; + } + + /** + * Formats a string containing the fully-qualified path to represent a location + * resource. + * + * @param string $project + * @param string $location + * + * @return string The formatted location resource. + */ + public static function locationName(string $project, string $location): string + { + return self::getPathTemplate('location')->render([ + 'project' => $project, + 'location' => $location, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a product + * resource. + * + * @param string $project + * @param string $location + * @param string $product + * + * @return string The formatted product resource. + */ + public static function productName(string $project, string $location, string $product): string + { + return self::getPathTemplate('product')->render([ + 'project' => $project, + 'location' => $location, + 'product' => $product, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a product_set + * resource. + * + * @param string $project + * @param string $location + * @param string $productSet + * + * @return string The formatted product_set resource. + */ + public static function productSetName(string $project, string $location, string $productSet): string + { + return self::getPathTemplate('productSet')->render([ + 'project' => $project, + 'location' => $location, + 'product_set' => $productSet, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * reference_image resource. + * + * @param string $project + * @param string $location + * @param string $product + * @param string $referenceImage + * + * @return string The formatted reference_image resource. + */ + public static function referenceImageName(string $project, string $location, string $product, string $referenceImage): string + { + return self::getPathTemplate('referenceImage')->render([ + 'project' => $project, + 'location' => $location, + 'product' => $product, + 'reference_image' => $referenceImage, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - location: projects/{project}/locations/{location} + * - product: projects/{project}/locations/{location}/products/{product} + * - productSet: projects/{project}/locations/{location}/productSets/{product_set} + * - referenceImage: projects/{project}/locations/{location}/products/{product}/referenceImages/{reference_image} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'vision.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * } + * + * @throws ValidationException + */ + public function __construct(array $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + $this->operationsClient = $this->createOperationsClient($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Adds a Product to the specified ProductSet. If the Product is already + * present, no change is made. + * + * One Product can be added to at most 100 ProductSets. + * + * Possible errors: + * + * * Returns NOT_FOUND if the Product or the ProductSet doesn't exist. + * + * The async variant is {@see self::addProductToProductSetAsync()} . + * + * @param AddProductToProductSetRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @throws ApiException Thrown if the API call fails. + */ + public function addProductToProductSet(AddProductToProductSetRequest $request, array $callOptions = []): void + { + $this->startApiCall('AddProductToProductSet', $request, $callOptions)->wait(); + } + + /** + * Creates and returns a new product resource. + * + * Possible errors: + * + * * Returns INVALID_ARGUMENT if display_name is missing or longer than 4096 + * characters. + * * Returns INVALID_ARGUMENT if description is longer than 4096 characters. + * * Returns INVALID_ARGUMENT if product_category is missing or invalid. + * + * The async variant is {@see self::createProductAsync()} . + * + * @param CreateProductRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Product + * + * @throws ApiException Thrown if the API call fails. + */ + public function createProduct(CreateProductRequest $request, array $callOptions = []): Product + { + return $this->startApiCall('CreateProduct', $request, $callOptions)->wait(); + } + + /** + * Creates and returns a new ProductSet resource. + * + * Possible errors: + * + * * Returns INVALID_ARGUMENT if display_name is missing, or is longer than + * 4096 characters. + * + * The async variant is {@see self::createProductSetAsync()} . + * + * @param CreateProductSetRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return ProductSet + * + * @throws ApiException Thrown if the API call fails. + */ + public function createProductSet(CreateProductSetRequest $request, array $callOptions = []): ProductSet + { + return $this->startApiCall('CreateProductSet', $request, $callOptions)->wait(); + } + + /** + * Creates and returns a new ReferenceImage resource. + * + * The `bounding_poly` field is optional. If `bounding_poly` is not specified, + * the system will try to detect regions of interest in the image that are + * compatible with the product_category on the parent product. If it is + * specified, detection is ALWAYS skipped. The system converts polygons into + * non-rotated rectangles. + * + * Note that the pipeline will resize the image if the image resolution is too + * large to process (above 50MP). + * + * Possible errors: + * + * * Returns INVALID_ARGUMENT if the image_uri is missing or longer than 4096 + * characters. + * * Returns INVALID_ARGUMENT if the product does not exist. + * * Returns INVALID_ARGUMENT if bounding_poly is not provided, and nothing + * compatible with the parent product's product_category is detected. + * * Returns INVALID_ARGUMENT if bounding_poly contains more than 10 polygons. + * + * The async variant is {@see self::createReferenceImageAsync()} . + * + * @param CreateReferenceImageRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return ReferenceImage + * + * @throws ApiException Thrown if the API call fails. + */ + public function createReferenceImage(CreateReferenceImageRequest $request, array $callOptions = []): ReferenceImage + { + return $this->startApiCall('CreateReferenceImage', $request, $callOptions)->wait(); + } + + /** + * Permanently deletes a product and its reference images. + * + * Metadata of the product and all its images will be deleted right away, but + * search queries against ProductSets containing the product may still work + * until all related caches are refreshed. + * + * The async variant is {@see self::deleteProductAsync()} . + * + * @param DeleteProductRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteProduct(DeleteProductRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeleteProduct', $request, $callOptions)->wait(); + } + + /** + * Permanently deletes a ProductSet. Products and ReferenceImages in the + * ProductSet are not deleted. + * + * The actual image files are not deleted from Google Cloud Storage. + * + * The async variant is {@see self::deleteProductSetAsync()} . + * + * @param DeleteProductSetRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteProductSet(DeleteProductSetRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeleteProductSet', $request, $callOptions)->wait(); + } + + /** + * Permanently deletes a reference image. + * + * The image metadata will be deleted right away, but search queries + * against ProductSets containing the image may still work until all related + * caches are refreshed. + * + * The actual image files are not deleted from Google Cloud Storage. + * + * The async variant is {@see self::deleteReferenceImageAsync()} . + * + * @param DeleteReferenceImageRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteReferenceImage(DeleteReferenceImageRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeleteReferenceImage', $request, $callOptions)->wait(); + } + + /** + * Gets information associated with a Product. + * + * Possible errors: + * + * * Returns NOT_FOUND if the Product does not exist. + * + * The async variant is {@see self::getProductAsync()} . + * + * @param GetProductRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Product + * + * @throws ApiException Thrown if the API call fails. + */ + public function getProduct(GetProductRequest $request, array $callOptions = []): Product + { + return $this->startApiCall('GetProduct', $request, $callOptions)->wait(); + } + + /** + * Gets information associated with a ProductSet. + * + * Possible errors: + * + * * Returns NOT_FOUND if the ProductSet does not exist. + * + * The async variant is {@see self::getProductSetAsync()} . + * + * @param GetProductSetRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return ProductSet + * + * @throws ApiException Thrown if the API call fails. + */ + public function getProductSet(GetProductSetRequest $request, array $callOptions = []): ProductSet + { + return $this->startApiCall('GetProductSet', $request, $callOptions)->wait(); + } + + /** + * Gets information associated with a ReferenceImage. + * + * Possible errors: + * + * * Returns NOT_FOUND if the specified image does not exist. + * + * The async variant is {@see self::getReferenceImageAsync()} . + * + * @param GetReferenceImageRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return ReferenceImage + * + * @throws ApiException Thrown if the API call fails. + */ + public function getReferenceImage(GetReferenceImageRequest $request, array $callOptions = []): ReferenceImage + { + return $this->startApiCall('GetReferenceImage', $request, $callOptions)->wait(); + } + + /** + * Asynchronous API that imports a list of reference images to specified + * product sets based on a list of image information. + * + * The [google.longrunning.Operation][google.longrunning.Operation] API can be used to keep track of the + * progress and results of the request. + * `Operation.metadata` contains `BatchOperationMetadata`. (progress) + * `Operation.response` contains `ImportProductSetsResponse`. (results) + * + * The input source of this method is a csv file on Google Cloud Storage. + * For the format of the csv file please see + * [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1.ImportProductSetsGcsSource.csv_file_uri]. + * + * The async variant is {@see self::importProductSetsAsync()} . + * + * @param ImportProductSetsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function importProductSets(ImportProductSetsRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('ImportProductSets', $request, $callOptions)->wait(); + } + + /** + * Lists ProductSets in an unspecified order. + * + * Possible errors: + * + * * Returns INVALID_ARGUMENT if page_size is greater than 100, or less + * than 1. + * + * The async variant is {@see self::listProductSetsAsync()} . + * + * @param ListProductSetsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listProductSets(ListProductSetsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListProductSets', $request, $callOptions); + } + + /** + * Lists products in an unspecified order. + * + * Possible errors: + * + * * Returns INVALID_ARGUMENT if page_size is greater than 100 or less than 1. + * + * The async variant is {@see self::listProductsAsync()} . + * + * @param ListProductsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listProducts(ListProductsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListProducts', $request, $callOptions); + } + + /** + * Lists the Products in a ProductSet, in an unspecified order. If the + * ProductSet does not exist, the products field of the response will be + * empty. + * + * Possible errors: + * + * * Returns INVALID_ARGUMENT if page_size is greater than 100 or less than 1. + * + * The async variant is {@see self::listProductsInProductSetAsync()} . + * + * @param ListProductsInProductSetRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listProductsInProductSet(ListProductsInProductSetRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListProductsInProductSet', $request, $callOptions); + } + + /** + * Lists reference images. + * + * Possible errors: + * + * * Returns NOT_FOUND if the parent product does not exist. + * * Returns INVALID_ARGUMENT if the page_size is greater than 100, or less + * than 1. + * + * The async variant is {@see self::listReferenceImagesAsync()} . + * + * @param ListReferenceImagesRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listReferenceImages(ListReferenceImagesRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListReferenceImages', $request, $callOptions); + } + + /** + * Asynchronous API to delete all Products in a ProductSet or all Products + * that are in no ProductSet. + * + * If a Product is a member of the specified ProductSet in addition to other + * ProductSets, the Product will still be deleted. + * + * It is recommended to not delete the specified ProductSet until after this + * operation has completed. It is also recommended to not add any of the + * Products involved in the batch delete to a new ProductSet while this + * operation is running because those Products may still end up deleted. + * + * It's not possible to undo the PurgeProducts operation. Therefore, it is + * recommended to keep the csv files used in ImportProductSets (if that was + * how you originally built the Product Set) before starting PurgeProducts, in + * case you need to re-import the data after deletion. + * + * If the plan is to purge all of the Products from a ProductSet and then + * re-use the empty ProductSet to re-import new Products into the empty + * ProductSet, you must wait until the PurgeProducts operation has finished + * for that ProductSet. + * + * The [google.longrunning.Operation][google.longrunning.Operation] API can be used to keep track of the + * progress and results of the request. + * `Operation.metadata` contains `BatchOperationMetadata`. (progress) + * + * The async variant is {@see self::purgeProductsAsync()} . + * + * @param PurgeProductsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function purgeProducts(PurgeProductsRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('PurgeProducts', $request, $callOptions)->wait(); + } + + /** + * Removes a Product from the specified ProductSet. + * + * The async variant is {@see self::removeProductFromProductSetAsync()} . + * + * @param RemoveProductFromProductSetRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @throws ApiException Thrown if the API call fails. + */ + public function removeProductFromProductSet(RemoveProductFromProductSetRequest $request, array $callOptions = []): void + { + $this->startApiCall('RemoveProductFromProductSet', $request, $callOptions)->wait(); + } + + /** + * Makes changes to a Product resource. + * Only the `display_name`, `description`, and `labels` fields can be updated + * right now. + * + * If labels are updated, the change will not be reflected in queries until + * the next index time. + * + * Possible errors: + * + * * Returns NOT_FOUND if the Product does not exist. + * * Returns INVALID_ARGUMENT if display_name is present in update_mask but is + * missing from the request or longer than 4096 characters. + * * Returns INVALID_ARGUMENT if description is present in update_mask but is + * longer than 4096 characters. + * * Returns INVALID_ARGUMENT if product_category is present in update_mask. + * + * The async variant is {@see self::updateProductAsync()} . + * + * @param UpdateProductRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Product + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateProduct(UpdateProductRequest $request, array $callOptions = []): Product + { + return $this->startApiCall('UpdateProduct', $request, $callOptions)->wait(); + } + + /** + * Makes changes to a ProductSet resource. + * Only display_name can be updated currently. + * + * Possible errors: + * + * * Returns NOT_FOUND if the ProductSet does not exist. + * * Returns INVALID_ARGUMENT if display_name is present in update_mask but + * missing from the request or longer than 4096 characters. + * + * The async variant is {@see self::updateProductSetAsync()} . + * + * @param UpdateProductSetRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return ProductSet + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateProductSet(UpdateProductSetRequest $request, array $callOptions = []): ProductSet + { + return $this->startApiCall('UpdateProductSet', $request, $callOptions)->wait(); + } +} diff --git a/Vision/src/V1/Client/ImageAnnotatorClient.php b/Vision/src/V1/Client/ImageAnnotatorClient.php new file mode 100644 index 000000000000..1f37298a8baa --- /dev/null +++ b/Vision/src/V1/Client/ImageAnnotatorClient.php @@ -0,0 +1,40 @@ +setParent($parent) + ->setProduct($product) + ->setProductId($productId); + } + /** * Constructor. * diff --git a/Vision/src/V1/CreateProductSetRequest.php b/Vision/src/V1/CreateProductSetRequest.php index b7878ac8d789..adafbbe77f3c 100644 --- a/Vision/src/V1/CreateProductSetRequest.php +++ b/Vision/src/V1/CreateProductSetRequest.php @@ -38,6 +38,29 @@ class CreateProductSetRequest extends \Google\Protobuf\Internal\Message */ private $product_set_id = ''; + /** + * @param string $parent Required. The project in which the ProductSet should be created. + * + * Format is `projects/PROJECT_ID/locations/LOC_ID`. Please see + * {@see ProductSearchClient::locationName()} for help formatting this field. + * @param \Google\Cloud\Vision\V1\ProductSet $productSet Required. The ProductSet to create. + * @param string $productSetId A user-supplied resource id for this ProductSet. If set, the server will + * attempt to use this value as the resource id. If it is already in use, an + * error is returned with code ALREADY_EXISTS. Must be at most 128 characters + * long. It cannot contain the character `/`. + * + * @return \Google\Cloud\Vision\V1\CreateProductSetRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\Vision\V1\ProductSet $productSet, string $productSetId): self + { + return (new self()) + ->setParent($parent) + ->setProductSet($productSet) + ->setProductSetId($productSetId); + } + /** * Constructor. * diff --git a/Vision/src/V1/CreateReferenceImageRequest.php b/Vision/src/V1/CreateReferenceImageRequest.php index 35e737c8ad18..76bcdc313cac 100644 --- a/Vision/src/V1/CreateReferenceImageRequest.php +++ b/Vision/src/V1/CreateReferenceImageRequest.php @@ -40,6 +40,31 @@ class CreateReferenceImageRequest extends \Google\Protobuf\Internal\Message */ private $reference_image_id = ''; + /** + * @param string $parent Required. Resource name of the product in which to create the reference image. + * + * Format is + * `projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`. Please see + * {@see ProductSearchClient::productName()} for help formatting this field. + * @param \Google\Cloud\Vision\V1\ReferenceImage $referenceImage Required. The reference image to create. + * If an image ID is specified, it is ignored. + * @param string $referenceImageId A user-supplied resource id for the ReferenceImage to be added. If set, + * the server will attempt to use this value as the resource id. If it is + * already in use, an error is returned with code ALREADY_EXISTS. Must be at + * most 128 characters long. It cannot contain the character `/`. + * + * @return \Google\Cloud\Vision\V1\CreateReferenceImageRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\Vision\V1\ReferenceImage $referenceImage, string $referenceImageId): self + { + return (new self()) + ->setParent($parent) + ->setReferenceImage($referenceImage) + ->setReferenceImageId($referenceImageId); + } + /** * Constructor. * diff --git a/Vision/src/V1/DeleteProductRequest.php b/Vision/src/V1/DeleteProductRequest.php index 1c6cb0e02bc6..c7f5c0686c6f 100644 --- a/Vision/src/V1/DeleteProductRequest.php +++ b/Vision/src/V1/DeleteProductRequest.php @@ -24,6 +24,23 @@ class DeleteProductRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Resource name of product to delete. + * + * Format is: + * `projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID` + * Please see {@see ProductSearchClient::productName()} for help formatting this field. + * + * @return \Google\Cloud\Vision\V1\DeleteProductRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/Vision/src/V1/DeleteProductSetRequest.php b/Vision/src/V1/DeleteProductSetRequest.php index d811b9cba94c..89ebe692cf0b 100644 --- a/Vision/src/V1/DeleteProductSetRequest.php +++ b/Vision/src/V1/DeleteProductSetRequest.php @@ -24,6 +24,23 @@ class DeleteProductSetRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Resource name of the ProductSet to delete. + * + * Format is: + * `projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID` + * Please see {@see ProductSearchClient::productSetName()} for help formatting this field. + * + * @return \Google\Cloud\Vision\V1\DeleteProductSetRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/Vision/src/V1/DeleteReferenceImageRequest.php b/Vision/src/V1/DeleteReferenceImageRequest.php index db12966022eb..6d82ad8850a5 100644 --- a/Vision/src/V1/DeleteReferenceImageRequest.php +++ b/Vision/src/V1/DeleteReferenceImageRequest.php @@ -24,6 +24,23 @@ class DeleteReferenceImageRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The resource name of the reference image to delete. + * + * Format is: + * `projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID` + * Please see {@see ProductSearchClient::referenceImageName()} for help formatting this field. + * + * @return \Google\Cloud\Vision\V1\DeleteReferenceImageRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/Vision/src/V1/GetProductRequest.php b/Vision/src/V1/GetProductRequest.php index 470e31545a69..5f55af3f8a06 100644 --- a/Vision/src/V1/GetProductRequest.php +++ b/Vision/src/V1/GetProductRequest.php @@ -24,6 +24,23 @@ class GetProductRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Resource name of the Product to get. + * + * Format is: + * `projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID` + * Please see {@see ProductSearchClient::productName()} for help formatting this field. + * + * @return \Google\Cloud\Vision\V1\GetProductRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/Vision/src/V1/GetProductSetRequest.php b/Vision/src/V1/GetProductSetRequest.php index 5f2e334ab531..62de33b462da 100644 --- a/Vision/src/V1/GetProductSetRequest.php +++ b/Vision/src/V1/GetProductSetRequest.php @@ -24,6 +24,23 @@ class GetProductSetRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Resource name of the ProductSet to get. + * + * Format is: + * `projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID` + * Please see {@see ProductSearchClient::productSetName()} for help formatting this field. + * + * @return \Google\Cloud\Vision\V1\GetProductSetRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/Vision/src/V1/GetReferenceImageRequest.php b/Vision/src/V1/GetReferenceImageRequest.php index dbe3f1225fa6..6ef7a5082beb 100644 --- a/Vision/src/V1/GetReferenceImageRequest.php +++ b/Vision/src/V1/GetReferenceImageRequest.php @@ -24,6 +24,23 @@ class GetReferenceImageRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. The resource name of the ReferenceImage to get. + * + * Format is: + * `projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID`. Please see + * {@see ProductSearchClient::referenceImageName()} for help formatting this field. + * + * @return \Google\Cloud\Vision\V1\GetReferenceImageRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/Vision/src/V1/ImportProductSetsRequest.php b/Vision/src/V1/ImportProductSetsRequest.php index 3b02a3df7834..c8ec7ccbd47a 100644 --- a/Vision/src/V1/ImportProductSetsRequest.php +++ b/Vision/src/V1/ImportProductSetsRequest.php @@ -29,6 +29,24 @@ class ImportProductSetsRequest extends \Google\Protobuf\Internal\Message */ private $input_config = null; + /** + * @param string $parent Required. The project in which the ProductSets should be imported. + * + * Format is `projects/PROJECT_ID/locations/LOC_ID`. Please see + * {@see ProductSearchClient::locationName()} for help formatting this field. + * @param \Google\Cloud\Vision\V1\ImportProductSetsInputConfig $inputConfig Required. The input content for the list of requests. + * + * @return \Google\Cloud\Vision\V1\ImportProductSetsRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\Vision\V1\ImportProductSetsInputConfig $inputConfig): self + { + return (new self()) + ->setParent($parent) + ->setInputConfig($inputConfig); + } + /** * Constructor. * diff --git a/Vision/src/V1/ListProductSetsRequest.php b/Vision/src/V1/ListProductSetsRequest.php index acc48a20c9c6..87bb3be3bb0f 100644 --- a/Vision/src/V1/ListProductSetsRequest.php +++ b/Vision/src/V1/ListProductSetsRequest.php @@ -35,6 +35,22 @@ class ListProductSetsRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Required. The project from which ProductSets should be listed. + * + * Format is `projects/PROJECT_ID/locations/LOC_ID`. Please see + * {@see ProductSearchClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\Vision\V1\ListProductSetsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/Vision/src/V1/ListProductsInProductSetRequest.php b/Vision/src/V1/ListProductsInProductSetRequest.php index 5ba960cd9e35..1694201f0a84 100644 --- a/Vision/src/V1/ListProductsInProductSetRequest.php +++ b/Vision/src/V1/ListProductsInProductSetRequest.php @@ -36,6 +36,23 @@ class ListProductsInProductSetRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $name Required. The ProductSet resource for which to retrieve Products. + * + * Format is: + * `projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID` + * Please see {@see ProductSearchClient::productSetName()} for help formatting this field. + * + * @return \Google\Cloud\Vision\V1\ListProductsInProductSetRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/Vision/src/V1/ListProductsRequest.php b/Vision/src/V1/ListProductsRequest.php index 1f59758c3c1f..feec3e8e5c58 100644 --- a/Vision/src/V1/ListProductsRequest.php +++ b/Vision/src/V1/ListProductsRequest.php @@ -36,6 +36,23 @@ class ListProductsRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Required. The project OR ProductSet from which Products should be listed. + * + * Format: + * `projects/PROJECT_ID/locations/LOC_ID` + * Please see {@see ProductSearchClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\Vision\V1\ListProductsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/Vision/src/V1/ListReferenceImagesRequest.php b/Vision/src/V1/ListReferenceImagesRequest.php index 4dec2658f247..75417445e135 100644 --- a/Vision/src/V1/ListReferenceImagesRequest.php +++ b/Vision/src/V1/ListReferenceImagesRequest.php @@ -38,6 +38,23 @@ class ListReferenceImagesRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Required. Resource name of the product containing the reference images. + * + * Format is + * `projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`. Please see + * {@see ProductSearchClient::productName()} for help formatting this field. + * + * @return \Google\Cloud\Vision\V1\ListReferenceImagesRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/Vision/src/V1/PurgeProductsRequest.php b/Vision/src/V1/PurgeProductsRequest.php index 7430e5eec76e..e1e229f645ea 100644 --- a/Vision/src/V1/PurgeProductsRequest.php +++ b/Vision/src/V1/PurgeProductsRequest.php @@ -31,6 +31,22 @@ class PurgeProductsRequest extends \Google\Protobuf\Internal\Message private $force = false; protected $target; + /** + * @param string $parent Required. The project and location in which the Products should be deleted. + * + * Format is `projects/PROJECT_ID/locations/LOC_ID`. Please see + * {@see ProductSearchClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\Vision\V1\PurgeProductsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/Vision/src/V1/RemoveProductFromProductSetRequest.php b/Vision/src/V1/RemoveProductFromProductSetRequest.php index db0e08f4fb14..4d8ebd638c24 100644 --- a/Vision/src/V1/RemoveProductFromProductSetRequest.php +++ b/Vision/src/V1/RemoveProductFromProductSetRequest.php @@ -32,6 +32,29 @@ class RemoveProductFromProductSetRequest extends \Google\Protobuf\Internal\Messa */ private $product = ''; + /** + * @param string $name Required. The resource name for the ProductSet to modify. + * + * Format is: + * `projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID` + * Please see {@see ProductSearchClient::productSetName()} for help formatting this field. + * @param string $product Required. The resource name for the Product to be removed from this ProductSet. + * + * Format is: + * `projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID` + * Please see {@see ProductSearchClient::productName()} for help formatting this field. + * + * @return \Google\Cloud\Vision\V1\RemoveProductFromProductSetRequest + * + * @experimental + */ + public static function build(string $name, string $product): self + { + return (new self()) + ->setName($name) + ->setProduct($product); + } + /** * Constructor. * diff --git a/Vision/src/V1/UpdateProductRequest.php b/Vision/src/V1/UpdateProductRequest.php index 64a6a9115b3e..febfeeb880da 100644 --- a/Vision/src/V1/UpdateProductRequest.php +++ b/Vision/src/V1/UpdateProductRequest.php @@ -33,6 +33,26 @@ class UpdateProductRequest extends \Google\Protobuf\Internal\Message */ private $update_mask = null; + /** + * @param \Google\Cloud\Vision\V1\Product $product Required. The Product resource which replaces the one on the server. + * product.name is immutable. + * @param \Google\Protobuf\FieldMask $updateMask The [FieldMask][google.protobuf.FieldMask] that specifies which fields + * to update. + * If update_mask isn't specified, all mutable fields are to be updated. + * Valid mask paths include `product_labels`, `display_name`, and + * `description`. + * + * @return \Google\Cloud\Vision\V1\UpdateProductRequest + * + * @experimental + */ + public static function build(\Google\Cloud\Vision\V1\Product $product, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setProduct($product) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/Vision/src/V1/UpdateProductSetRequest.php b/Vision/src/V1/UpdateProductSetRequest.php index 709b67e0b499..db231b5ec775 100644 --- a/Vision/src/V1/UpdateProductSetRequest.php +++ b/Vision/src/V1/UpdateProductSetRequest.php @@ -31,6 +31,24 @@ class UpdateProductSetRequest extends \Google\Protobuf\Internal\Message */ private $update_mask = null; + /** + * @param \Google\Cloud\Vision\V1\ProductSet $productSet Required. The ProductSet resource which replaces the one on the server. + * @param \Google\Protobuf\FieldMask $updateMask The [FieldMask][google.protobuf.FieldMask] that specifies which fields to + * update. + * If update_mask isn't specified, all mutable fields are to be updated. + * Valid mask path is `display_name`. + * + * @return \Google\Cloud\Vision\V1\UpdateProductSetRequest + * + * @experimental + */ + public static function build(\Google\Cloud\Vision\V1\ProductSet $productSet, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setProductSet($productSet) + ->setUpdateMask($updateMask); + } + /** * Constructor. * diff --git a/Vision/src/V1/resources/image_annotator_descriptor_config.php b/Vision/src/V1/resources/image_annotator_descriptor_config.php index 91b6cbda0e1a..05ecadd575c1 100644 --- a/Vision/src/V1/resources/image_annotator_descriptor_config.php +++ b/Vision/src/V1/resources/image_annotator_descriptor_config.php @@ -12,6 +12,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'AsyncBatchAnnotateImages' => [ 'longRunning' => [ @@ -22,6 +31,42 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'BatchAnnotateFiles' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Vision\V1\BatchAnnotateFilesResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'BatchAnnotateImages' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Vision\V1\BatchAnnotateImagesResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'templateMap' => [ + 'productSet' => 'projects/{project}/locations/{location}/productSets/{product_set}', ], ], ], diff --git a/Vision/src/V1/resources/product_search_descriptor_config.php b/Vision/src/V1/resources/product_search_descriptor_config.php index 3aadd4e46b91..62781007ff5c 100644 --- a/Vision/src/V1/resources/product_search_descriptor_config.php +++ b/Vision/src/V1/resources/product_search_descriptor_config.php @@ -12,6 +12,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'PurgeProducts' => [ 'longRunning' => [ @@ -22,6 +31,135 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'AddProductToProductSet' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'CreateProduct' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Vision\V1\Product', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'CreateProductSet' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Vision\V1\ProductSet', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'CreateReferenceImage' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Vision\V1\ReferenceImage', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'DeleteProduct' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'DeleteProductSet' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'DeleteReferenceImage' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetProduct' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Vision\V1\Product', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetProductSet' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Vision\V1\ProductSet', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetReferenceImage' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Vision\V1\ReferenceImage', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ListProductSets' => [ 'pageStreaming' => [ @@ -32,6 +170,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getProductSets', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Vision\V1\ListProductSetsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListProducts' => [ 'pageStreaming' => [ @@ -42,6 +190,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getProducts', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Vision\V1\ListProductsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListProductsInProductSet' => [ 'pageStreaming' => [ @@ -52,6 +210,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getProducts', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Vision\V1\ListProductsInProductSetResponse', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ListReferenceImages' => [ 'pageStreaming' => [ @@ -62,6 +230,60 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getReferenceImages', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Vision\V1\ListReferenceImagesResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'RemoveProductFromProductSet' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'UpdateProduct' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Vision\V1\Product', + 'headerParams' => [ + [ + 'keyName' => 'product.name', + 'fieldAccessors' => [ + 'getProduct', + 'getName', + ], + ], + ], + ], + 'UpdateProductSet' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Vision\V1\ProductSet', + 'headerParams' => [ + [ + 'keyName' => 'product_set.name', + 'fieldAccessors' => [ + 'getProductSet', + 'getName', + ], + ], + ], + ], + 'templateMap' => [ + 'location' => 'projects/{project}/locations/{location}', + 'product' => 'projects/{project}/locations/{location}/products/{product}', + 'productSet' => 'projects/{project}/locations/{location}/productSets/{product_set}', + 'referenceImage' => 'projects/{project}/locations/{location}/products/{product}/referenceImages/{reference_image}', ], ], ], diff --git a/Vision/tests/Unit/V1/Client/ImageAnnotatorClientTest.php b/Vision/tests/Unit/V1/Client/ImageAnnotatorClientTest.php new file mode 100644 index 000000000000..2778ff0e51bb --- /dev/null +++ b/Vision/tests/Unit/V1/Client/ImageAnnotatorClientTest.php @@ -0,0 +1,509 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return ImageAnnotatorClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new ImageAnnotatorClient($options); + } + + /** @test */ + public function asyncBatchAnnotateFilesTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/asyncBatchAnnotateFilesTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new AsyncBatchAnnotateFilesResponse(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/asyncBatchAnnotateFilesTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $requests = []; + $request = (new AsyncBatchAnnotateFilesRequest()) + ->setRequests($requests); + $response = $gapicClient->asyncBatchAnnotateFiles($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vision.v1.ImageAnnotator/AsyncBatchAnnotateFiles', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getRequests(); + $this->assertProtobufEquals($requests, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/asyncBatchAnnotateFilesTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function asyncBatchAnnotateFilesExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/asyncBatchAnnotateFilesTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $requests = []; + $request = (new AsyncBatchAnnotateFilesRequest()) + ->setRequests($requests); + $response = $gapicClient->asyncBatchAnnotateFiles($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/asyncBatchAnnotateFilesTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function asyncBatchAnnotateImagesTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/asyncBatchAnnotateImagesTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new AsyncBatchAnnotateImagesResponse(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/asyncBatchAnnotateImagesTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $requests = []; + $outputConfig = new OutputConfig(); + $request = (new AsyncBatchAnnotateImagesRequest()) + ->setRequests($requests) + ->setOutputConfig($outputConfig); + $response = $gapicClient->asyncBatchAnnotateImages($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vision.v1.ImageAnnotator/AsyncBatchAnnotateImages', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getRequests(); + $this->assertProtobufEquals($requests, $actualValue); + $actualValue = $actualApiRequestObject->getOutputConfig(); + $this->assertProtobufEquals($outputConfig, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/asyncBatchAnnotateImagesTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function asyncBatchAnnotateImagesExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/asyncBatchAnnotateImagesTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $requests = []; + $outputConfig = new OutputConfig(); + $request = (new AsyncBatchAnnotateImagesRequest()) + ->setRequests($requests) + ->setOutputConfig($outputConfig); + $response = $gapicClient->asyncBatchAnnotateImages($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/asyncBatchAnnotateImagesTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function batchAnnotateFilesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new BatchAnnotateFilesResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $requests = []; + $request = (new BatchAnnotateFilesRequest()) + ->setRequests($requests); + $response = $gapicClient->batchAnnotateFiles($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vision.v1.ImageAnnotator/BatchAnnotateFiles', $actualFuncCall); + $actualValue = $actualRequestObject->getRequests(); + $this->assertProtobufEquals($requests, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function batchAnnotateFilesExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $requests = []; + $request = (new BatchAnnotateFilesRequest()) + ->setRequests($requests); + try { + $gapicClient->batchAnnotateFiles($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function batchAnnotateImagesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new BatchAnnotateImagesResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $requests = []; + $request = (new BatchAnnotateImagesRequest()) + ->setRequests($requests); + $response = $gapicClient->batchAnnotateImages($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vision.v1.ImageAnnotator/BatchAnnotateImages', $actualFuncCall); + $actualValue = $actualRequestObject->getRequests(); + $this->assertProtobufEquals($requests, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function batchAnnotateImagesExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $requests = []; + $request = (new BatchAnnotateImagesRequest()) + ->setRequests($requests); + try { + $gapicClient->batchAnnotateImages($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function asyncBatchAnnotateFilesAsyncTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/asyncBatchAnnotateFilesTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new AsyncBatchAnnotateFilesResponse(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/asyncBatchAnnotateFilesTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $requests = []; + $request = (new AsyncBatchAnnotateFilesRequest()) + ->setRequests($requests); + $response = $gapicClient->asyncBatchAnnotateFilesAsync($request)->wait(); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vision.v1.ImageAnnotator/AsyncBatchAnnotateFiles', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getRequests(); + $this->assertProtobufEquals($requests, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/asyncBatchAnnotateFilesTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } +} diff --git a/Vision/tests/Unit/V1/Client/ProductSearchClientTest.php b/Vision/tests/Unit/V1/Client/ProductSearchClientTest.php new file mode 100644 index 000000000000..783e73837e72 --- /dev/null +++ b/Vision/tests/Unit/V1/Client/ProductSearchClientTest.php @@ -0,0 +1,1540 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return ProductSearchClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new ProductSearchClient($options); + } + + /** @test */ + public function addProductToProductSetTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->productSetName('[PROJECT]', '[LOCATION]', '[PRODUCT_SET]'); + $formattedProduct = $gapicClient->productName('[PROJECT]', '[LOCATION]', '[PRODUCT]'); + $request = (new AddProductToProductSetRequest()) + ->setName($formattedName) + ->setProduct($formattedProduct); + $gapicClient->addProductToProductSet($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vision.v1.ProductSearch/AddProductToProductSet', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $actualValue = $actualRequestObject->getProduct(); + $this->assertProtobufEquals($formattedProduct, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function addProductToProductSetExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->productSetName('[PROJECT]', '[LOCATION]', '[PRODUCT_SET]'); + $formattedProduct = $gapicClient->productName('[PROJECT]', '[LOCATION]', '[PRODUCT]'); + $request = (new AddProductToProductSetRequest()) + ->setName($formattedName) + ->setProduct($formattedProduct); + try { + $gapicClient->addProductToProductSet($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createProductTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $productCategory = 'productCategory-1607451058'; + $expectedResponse = new Product(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setProductCategory($productCategory); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $product = new Product(); + $request = (new CreateProductRequest()) + ->setParent($formattedParent) + ->setProduct($product); + $response = $gapicClient->createProduct($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vision.v1.ProductSearch/CreateProduct', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getProduct(); + $this->assertProtobufEquals($product, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createProductExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $product = new Product(); + $request = (new CreateProductRequest()) + ->setParent($formattedParent) + ->setProduct($product); + try { + $gapicClient->createProduct($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createProductSetTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $expectedResponse = new ProductSet(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $productSet = new ProductSet(); + $request = (new CreateProductSetRequest()) + ->setParent($formattedParent) + ->setProductSet($productSet); + $response = $gapicClient->createProductSet($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vision.v1.ProductSearch/CreateProductSet', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getProductSet(); + $this->assertProtobufEquals($productSet, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createProductSetExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $productSet = new ProductSet(); + $request = (new CreateProductSetRequest()) + ->setParent($formattedParent) + ->setProductSet($productSet); + try { + $gapicClient->createProductSet($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createReferenceImageTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $uri = 'uri116076'; + $expectedResponse = new ReferenceImage(); + $expectedResponse->setName($name); + $expectedResponse->setUri($uri); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->productName('[PROJECT]', '[LOCATION]', '[PRODUCT]'); + $referenceImage = new ReferenceImage(); + $referenceImageUri = 'referenceImageUri-707360132'; + $referenceImage->setUri($referenceImageUri); + $request = (new CreateReferenceImageRequest()) + ->setParent($formattedParent) + ->setReferenceImage($referenceImage); + $response = $gapicClient->createReferenceImage($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vision.v1.ProductSearch/CreateReferenceImage', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getReferenceImage(); + $this->assertProtobufEquals($referenceImage, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createReferenceImageExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->productName('[PROJECT]', '[LOCATION]', '[PRODUCT]'); + $referenceImage = new ReferenceImage(); + $referenceImageUri = 'referenceImageUri-707360132'; + $referenceImage->setUri($referenceImageUri); + $request = (new CreateReferenceImageRequest()) + ->setParent($formattedParent) + ->setReferenceImage($referenceImage); + try { + $gapicClient->createReferenceImage($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteProductTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->productName('[PROJECT]', '[LOCATION]', '[PRODUCT]'); + $request = (new DeleteProductRequest()) + ->setName($formattedName); + $gapicClient->deleteProduct($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vision.v1.ProductSearch/DeleteProduct', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteProductExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->productName('[PROJECT]', '[LOCATION]', '[PRODUCT]'); + $request = (new DeleteProductRequest()) + ->setName($formattedName); + try { + $gapicClient->deleteProduct($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteProductSetTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->productSetName('[PROJECT]', '[LOCATION]', '[PRODUCT_SET]'); + $request = (new DeleteProductSetRequest()) + ->setName($formattedName); + $gapicClient->deleteProductSet($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vision.v1.ProductSearch/DeleteProductSet', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteProductSetExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->productSetName('[PROJECT]', '[LOCATION]', '[PRODUCT_SET]'); + $request = (new DeleteProductSetRequest()) + ->setName($formattedName); + try { + $gapicClient->deleteProductSet($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteReferenceImageTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->referenceImageName('[PROJECT]', '[LOCATION]', '[PRODUCT]', '[REFERENCE_IMAGE]'); + $request = (new DeleteReferenceImageRequest()) + ->setName($formattedName); + $gapicClient->deleteReferenceImage($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vision.v1.ProductSearch/DeleteReferenceImage', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteReferenceImageExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->referenceImageName('[PROJECT]', '[LOCATION]', '[PRODUCT]', '[REFERENCE_IMAGE]'); + $request = (new DeleteReferenceImageRequest()) + ->setName($formattedName); + try { + $gapicClient->deleteReferenceImage($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getProductTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $productCategory = 'productCategory-1607451058'; + $expectedResponse = new Product(); + $expectedResponse->setName($name2); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setProductCategory($productCategory); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->productName('[PROJECT]', '[LOCATION]', '[PRODUCT]'); + $request = (new GetProductRequest()) + ->setName($formattedName); + $response = $gapicClient->getProduct($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vision.v1.ProductSearch/GetProduct', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getProductExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->productName('[PROJECT]', '[LOCATION]', '[PRODUCT]'); + $request = (new GetProductRequest()) + ->setName($formattedName); + try { + $gapicClient->getProduct($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getProductSetTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $displayName = 'displayName1615086568'; + $expectedResponse = new ProductSet(); + $expectedResponse->setName($name2); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->productSetName('[PROJECT]', '[LOCATION]', '[PRODUCT_SET]'); + $request = (new GetProductSetRequest()) + ->setName($formattedName); + $response = $gapicClient->getProductSet($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vision.v1.ProductSearch/GetProductSet', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getProductSetExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->productSetName('[PROJECT]', '[LOCATION]', '[PRODUCT_SET]'); + $request = (new GetProductSetRequest()) + ->setName($formattedName); + try { + $gapicClient->getProductSet($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getReferenceImageTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $uri = 'uri116076'; + $expectedResponse = new ReferenceImage(); + $expectedResponse->setName($name2); + $expectedResponse->setUri($uri); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->referenceImageName('[PROJECT]', '[LOCATION]', '[PRODUCT]', '[REFERENCE_IMAGE]'); + $request = (new GetReferenceImageRequest()) + ->setName($formattedName); + $response = $gapicClient->getReferenceImage($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vision.v1.ProductSearch/GetReferenceImage', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getReferenceImageExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->referenceImageName('[PROJECT]', '[LOCATION]', '[PRODUCT]', '[REFERENCE_IMAGE]'); + $request = (new GetReferenceImageRequest()) + ->setName($formattedName); + try { + $gapicClient->getReferenceImage($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function importProductSetsTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/importProductSetsTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new ImportProductSetsResponse(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/importProductSetsTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $inputConfig = new ImportProductSetsInputConfig(); + $request = (new ImportProductSetsRequest()) + ->setParent($formattedParent) + ->setInputConfig($inputConfig); + $response = $gapicClient->importProductSets($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vision.v1.ProductSearch/ImportProductSets', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getInputConfig(); + $this->assertProtobufEquals($inputConfig, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/importProductSetsTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function importProductSetsExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/importProductSetsTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $inputConfig = new ImportProductSetsInputConfig(); + $request = (new ImportProductSetsRequest()) + ->setParent($formattedParent) + ->setInputConfig($inputConfig); + $response = $gapicClient->importProductSets($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/importProductSetsTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function listProductSetsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $productSetsElement = new ProductSet(); + $productSets = [ + $productSetsElement, + ]; + $expectedResponse = new ListProductSetsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setProductSets($productSets); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListProductSetsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listProductSets($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getProductSets()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vision.v1.ProductSearch/ListProductSets', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listProductSetsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListProductSetsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listProductSets($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listProductsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $productsElement = new Product(); + $products = [ + $productsElement, + ]; + $expectedResponse = new ListProductsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setProducts($products); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListProductsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listProducts($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getProducts()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vision.v1.ProductSearch/ListProducts', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listProductsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListProductsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listProducts($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listProductsInProductSetTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $productsElement = new Product(); + $products = [ + $productsElement, + ]; + $expectedResponse = new ListProductsInProductSetResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setProducts($products); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->productSetName('[PROJECT]', '[LOCATION]', '[PRODUCT_SET]'); + $request = (new ListProductsInProductSetRequest()) + ->setName($formattedName); + $response = $gapicClient->listProductsInProductSet($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getProducts()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vision.v1.ProductSearch/ListProductsInProductSet', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listProductsInProductSetExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->productSetName('[PROJECT]', '[LOCATION]', '[PRODUCT_SET]'); + $request = (new ListProductsInProductSetRequest()) + ->setName($formattedName); + try { + $gapicClient->listProductsInProductSet($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listReferenceImagesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $pageSize2 = 1024500956; + $nextPageToken = ''; + $referenceImagesElement = new ReferenceImage(); + $referenceImages = [ + $referenceImagesElement, + ]; + $expectedResponse = new ListReferenceImagesResponse(); + $expectedResponse->setPageSize($pageSize2); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setReferenceImages($referenceImages); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->productName('[PROJECT]', '[LOCATION]', '[PRODUCT]'); + $request = (new ListReferenceImagesRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listReferenceImages($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getReferenceImages()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vision.v1.ProductSearch/ListReferenceImages', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listReferenceImagesExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->productName('[PROJECT]', '[LOCATION]', '[PRODUCT]'); + $request = (new ListReferenceImagesRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listReferenceImages($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function purgeProductsTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/purgeProductsTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/purgeProductsTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new PurgeProductsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->purgeProducts($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vision.v1.ProductSearch/PurgeProducts', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/purgeProductsTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function purgeProductsExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/purgeProductsTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new PurgeProductsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->purgeProducts($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/purgeProductsTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function removeProductFromProductSetTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->productSetName('[PROJECT]', '[LOCATION]', '[PRODUCT_SET]'); + $formattedProduct = $gapicClient->productName('[PROJECT]', '[LOCATION]', '[PRODUCT]'); + $request = (new RemoveProductFromProductSetRequest()) + ->setName($formattedName) + ->setProduct($formattedProduct); + $gapicClient->removeProductFromProductSet($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vision.v1.ProductSearch/RemoveProductFromProductSet', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $actualValue = $actualRequestObject->getProduct(); + $this->assertProtobufEquals($formattedProduct, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function removeProductFromProductSetExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->productSetName('[PROJECT]', '[LOCATION]', '[PRODUCT_SET]'); + $formattedProduct = $gapicClient->productName('[PROJECT]', '[LOCATION]', '[PRODUCT]'); + $request = (new RemoveProductFromProductSetRequest()) + ->setName($formattedName) + ->setProduct($formattedProduct); + try { + $gapicClient->removeProductFromProductSet($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateProductTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $description = 'description-1724546052'; + $productCategory = 'productCategory-1607451058'; + $expectedResponse = new Product(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setDescription($description); + $expectedResponse->setProductCategory($productCategory); + $transport->addResponse($expectedResponse); + // Mock request + $product = new Product(); + $request = (new UpdateProductRequest()) + ->setProduct($product); + $response = $gapicClient->updateProduct($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vision.v1.ProductSearch/UpdateProduct', $actualFuncCall); + $actualValue = $actualRequestObject->getProduct(); + $this->assertProtobufEquals($product, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateProductExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $product = new Product(); + $request = (new UpdateProductRequest()) + ->setProduct($product); + try { + $gapicClient->updateProduct($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateProductSetTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $expectedResponse = new ProductSet(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $transport->addResponse($expectedResponse); + // Mock request + $productSet = new ProductSet(); + $request = (new UpdateProductSetRequest()) + ->setProductSet($productSet); + $response = $gapicClient->updateProductSet($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vision.v1.ProductSearch/UpdateProductSet', $actualFuncCall); + $actualValue = $actualRequestObject->getProductSet(); + $this->assertProtobufEquals($productSet, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateProductSetExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $productSet = new ProductSet(); + $request = (new UpdateProductSetRequest()) + ->setProductSet($productSet); + try { + $gapicClient->updateProductSet($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function addProductToProductSetAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->productSetName('[PROJECT]', '[LOCATION]', '[PRODUCT_SET]'); + $formattedProduct = $gapicClient->productName('[PROJECT]', '[LOCATION]', '[PRODUCT]'); + $request = (new AddProductToProductSetRequest()) + ->setName($formattedName) + ->setProduct($formattedProduct); + $gapicClient->addProductToProductSetAsync($request)->wait(); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vision.v1.ProductSearch/AddProductToProductSet', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $actualValue = $actualRequestObject->getProduct(); + $this->assertProtobufEquals($formattedProduct, $actualValue); + $this->assertTrue($transport->isExhausted()); + } +} diff --git a/VpcAccess/src/V1/Client/BaseClient/VpcAccessServiceBaseClient.php b/VpcAccess/src/V1/Client/BaseClient/VpcAccessServiceBaseClient.php new file mode 100644 index 000000000000..bfeaaac097f7 --- /dev/null +++ b/VpcAccess/src/V1/Client/BaseClient/VpcAccessServiceBaseClient.php @@ -0,0 +1,398 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/vpc_access_service_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/vpc_access_service_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/vpc_access_service_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/vpc_access_service_rest_client_config.php', + ], + ], + ]; + } + + /** + * Return an OperationsClient object with the same endpoint as $this. + * + * @return OperationsClient + */ + public function getOperationsClient() + { + return $this->operationsClient; + } + + /** + * Resume an existing long running operation that was previously started by a long + * running API method. If $methodName is not provided, or does not match a long + * running API method, then the operation can still be resumed, but the + * OperationResponse object will not deserialize the final response. + * + * @param string $operationName The name of the long running operation + * @param string $methodName The name of the method used to start the operation + * + * @return OperationResponse + */ + public function resumeOperation($operationName, $methodName = null) + { + $options = isset($this->descriptors[$methodName]['longRunning']) ? $this->descriptors[$methodName]['longRunning'] : []; + $operation = new OperationResponse($operationName, $this->getOperationsClient(), $options); + $operation->reload(); + return $operation; + } + + /** + * Formats a string containing the fully-qualified path to represent a connector + * resource. + * + * @param string $project + * @param string $location + * @param string $connector + * + * @return string The formatted connector resource. + */ + public static function connectorName(string $project, string $location, string $connector): string + { + return self::getPathTemplate('connector')->render([ + 'project' => $project, + 'location' => $location, + 'connector' => $connector, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a location + * resource. + * + * @param string $project + * @param string $location + * + * @return string The formatted location resource. + */ + public static function locationName(string $project, string $location): string + { + return self::getPathTemplate('location')->render([ + 'project' => $project, + 'location' => $location, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - connector: projects/{project}/locations/{location}/connectors/{connector} + * - location: projects/{project}/locations/{location} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'vpcaccess.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * } + * + * @throws ValidationException + */ + public function __construct(array $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + $this->operationsClient = $this->createOperationsClient($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Creates a Serverless VPC Access connector, returns an operation. + * + * The async variant is {@see self::createConnectorAsync()} . + * + * @param CreateConnectorRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function createConnector(CreateConnectorRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateConnector', $request, $callOptions)->wait(); + } + + /** + * Deletes a Serverless VPC Access connector. Returns NOT_FOUND if the + * resource does not exist. + * + * The async variant is {@see self::deleteConnectorAsync()} . + * + * @param DeleteConnectorRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteConnector(DeleteConnectorRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteConnector', $request, $callOptions)->wait(); + } + + /** + * Gets a Serverless VPC Access connector. Returns NOT_FOUND if the resource + * does not exist. + * + * The async variant is {@see self::getConnectorAsync()} . + * + * @param GetConnectorRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Connector + * + * @throws ApiException Thrown if the API call fails. + */ + public function getConnector(GetConnectorRequest $request, array $callOptions = []): Connector + { + return $this->startApiCall('GetConnector', $request, $callOptions)->wait(); + } + + /** + * Lists Serverless VPC Access connectors. + * + * The async variant is {@see self::listConnectorsAsync()} . + * + * @param ListConnectorsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listConnectors(ListConnectorsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListConnectors', $request, $callOptions); + } + + /** + * Lists information about the supported locations for this service. + * + * The async variant is {@see self::listLocationsAsync()} . + * + * @param ListLocationsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listLocations(ListLocationsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListLocations', $request, $callOptions); + } +} diff --git a/VpcAccess/src/V1/Client/VpcAccessServiceClient.php b/VpcAccess/src/V1/Client/VpcAccessServiceClient.php new file mode 100644 index 000000000000..7c6a17daa2fc --- /dev/null +++ b/VpcAccess/src/V1/Client/VpcAccessServiceClient.php @@ -0,0 +1,40 @@ +setParent($parent) + ->setConnectorId($connectorId) + ->setConnector($connector); + } + /** * Constructor. * diff --git a/VpcAccess/src/V1/DeleteConnectorRequest.php b/VpcAccess/src/V1/DeleteConnectorRequest.php index 16954fd458e7..fb81852e3e40 100644 --- a/VpcAccess/src/V1/DeleteConnectorRequest.php +++ b/VpcAccess/src/V1/DeleteConnectorRequest.php @@ -22,6 +22,20 @@ class DeleteConnectorRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Name of a Serverless VPC Access connector to delete. Please see + * {@see VpcAccessServiceClient::connectorName()} for help formatting this field. + * + * @return \Google\Cloud\VpcAccess\V1\DeleteConnectorRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VpcAccess/src/V1/GetConnectorRequest.php b/VpcAccess/src/V1/GetConnectorRequest.php index 0481910aa5d7..1c1587bbf048 100644 --- a/VpcAccess/src/V1/GetConnectorRequest.php +++ b/VpcAccess/src/V1/GetConnectorRequest.php @@ -22,6 +22,20 @@ class GetConnectorRequest extends \Google\Protobuf\Internal\Message */ private $name = ''; + /** + * @param string $name Required. Name of a Serverless VPC Access connector to get. Please see + * {@see VpcAccessServiceClient::connectorName()} for help formatting this field. + * + * @return \Google\Cloud\VpcAccess\V1\GetConnectorRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + /** * Constructor. * diff --git a/VpcAccess/src/V1/ListConnectorsRequest.php b/VpcAccess/src/V1/ListConnectorsRequest.php index d1925a466fc3..7f9fc3f4c24f 100644 --- a/VpcAccess/src/V1/ListConnectorsRequest.php +++ b/VpcAccess/src/V1/ListConnectorsRequest.php @@ -34,6 +34,20 @@ class ListConnectorsRequest extends \Google\Protobuf\Internal\Message */ private $page_token = ''; + /** + * @param string $parent Required. The project and location from which the routes should be listed. Please see + * {@see VpcAccessServiceClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\VpcAccess\V1\ListConnectorsRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + /** * Constructor. * diff --git a/VpcAccess/src/V1/resources/vpc_access_service_descriptor_config.php b/VpcAccess/src/V1/resources/vpc_access_service_descriptor_config.php index 0ea85b60905b..d7820fe3a3fb 100644 --- a/VpcAccess/src/V1/resources/vpc_access_service_descriptor_config.php +++ b/VpcAccess/src/V1/resources/vpc_access_service_descriptor_config.php @@ -12,6 +12,15 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'DeleteConnector' => [ 'longRunning' => [ @@ -22,6 +31,27 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetConnector' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\VpcAccess\V1\Connector', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], ], 'ListConnectors' => [ 'pageStreaming' => [ @@ -32,6 +62,16 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getConnectors', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\VpcAccess\V1\ListConnectorsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], ], 'ListLocations' => [ 'pageStreaming' => [ @@ -42,8 +82,22 @@ 'responsePageTokenGetMethod' => 'getNextPageToken', 'resourcesGetMethod' => 'getLocations', ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Location\ListLocationsResponse', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], 'interfaceOverride' => 'google.cloud.location.Locations', ], + 'templateMap' => [ + 'connector' => 'projects/{project}/locations/{location}/connectors/{connector}', + 'location' => 'projects/{project}/locations/{location}', + ], ], ], ]; diff --git a/VpcAccess/tests/Unit/V1/Client/VpcAccessServiceClientTest.php b/VpcAccess/tests/Unit/V1/Client/VpcAccessServiceClientTest.php new file mode 100644 index 000000000000..8a9300b77463 --- /dev/null +++ b/VpcAccess/tests/Unit/V1/Client/VpcAccessServiceClientTest.php @@ -0,0 +1,646 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return VpcAccessServiceClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new VpcAccessServiceClient($options); + } + + /** @test */ + public function createConnectorTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createConnectorTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $network = 'network1843485230'; + $ipCidrRange = 'ipCidrRange-2049366326'; + $minThroughput = 2064735799; + $maxThroughput = 1407819749; + $machineType = 'machineType1838323762'; + $minInstances = 1491624145; + $maxInstances = 330682013; + $expectedResponse = new Connector(); + $expectedResponse->setName($name); + $expectedResponse->setNetwork($network); + $expectedResponse->setIpCidrRange($ipCidrRange); + $expectedResponse->setMinThroughput($minThroughput); + $expectedResponse->setMaxThroughput($maxThroughput); + $expectedResponse->setMachineType($machineType); + $expectedResponse->setMinInstances($minInstances); + $expectedResponse->setMaxInstances($maxInstances); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createConnectorTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $connectorId = 'connectorId1928724045'; + $connector = new Connector(); + $request = (new CreateConnectorRequest()) + ->setParent($formattedParent) + ->setConnectorId($connectorId) + ->setConnector($connector); + $response = $gapicClient->createConnector($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vpcaccess.v1.VpcAccessService/CreateConnector', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getConnectorId(); + $this->assertProtobufEquals($connectorId, $actualValue); + $actualValue = $actualApiRequestObject->getConnector(); + $this->assertProtobufEquals($connector, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createConnectorTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function createConnectorExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createConnectorTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $connectorId = 'connectorId1928724045'; + $connector = new Connector(); + $request = (new CreateConnectorRequest()) + ->setParent($formattedParent) + ->setConnectorId($connectorId) + ->setConnector($connector); + $response = $gapicClient->createConnector($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createConnectorTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteConnectorTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteConnectorTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $expectedResponse = new GPBEmpty(); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteConnectorTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->connectorName('[PROJECT]', '[LOCATION]', '[CONNECTOR]'); + $request = (new DeleteConnectorRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteConnector($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vpcaccess.v1.VpcAccessService/DeleteConnector', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteConnectorTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteConnectorExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deleteConnectorTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->connectorName('[PROJECT]', '[LOCATION]', '[CONNECTOR]'); + $request = (new DeleteConnectorRequest()) + ->setName($formattedName); + $response = $gapicClient->deleteConnector($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteConnectorTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function getConnectorTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $network = 'network1843485230'; + $ipCidrRange = 'ipCidrRange-2049366326'; + $minThroughput = 2064735799; + $maxThroughput = 1407819749; + $machineType = 'machineType1838323762'; + $minInstances = 1491624145; + $maxInstances = 330682013; + $expectedResponse = new Connector(); + $expectedResponse->setName($name2); + $expectedResponse->setNetwork($network); + $expectedResponse->setIpCidrRange($ipCidrRange); + $expectedResponse->setMinThroughput($minThroughput); + $expectedResponse->setMaxThroughput($maxThroughput); + $expectedResponse->setMachineType($machineType); + $expectedResponse->setMinInstances($minInstances); + $expectedResponse->setMaxInstances($maxInstances); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->connectorName('[PROJECT]', '[LOCATION]', '[CONNECTOR]'); + $request = (new GetConnectorRequest()) + ->setName($formattedName); + $response = $gapicClient->getConnector($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vpcaccess.v1.VpcAccessService/GetConnector', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getConnectorExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->connectorName('[PROJECT]', '[LOCATION]', '[CONNECTOR]'); + $request = (new GetConnectorRequest()) + ->setName($formattedName); + try { + $gapicClient->getConnector($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listConnectorsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $connectorsElement = new Connector(); + $connectors = [ + $connectorsElement, + ]; + $expectedResponse = new ListConnectorsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setConnectors($connectors); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListConnectorsRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listConnectors($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getConnectors()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vpcaccess.v1.VpcAccessService/ListConnectors', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listConnectorsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListConnectorsRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listConnectors($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLocationsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $locationsElement = new Location(); + $locations = [ + $locationsElement, + ]; + $expectedResponse = new ListLocationsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setLocations($locations); + $transport->addResponse($expectedResponse); + $request = new ListLocationsRequest(); + $response = $gapicClient->listLocations($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getLocations()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.location.Locations/ListLocations', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listLocationsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new ListLocationsRequest(); + try { + $gapicClient->listLocations($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createConnectorAsyncTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/createConnectorTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $network = 'network1843485230'; + $ipCidrRange = 'ipCidrRange-2049366326'; + $minThroughput = 2064735799; + $maxThroughput = 1407819749; + $machineType = 'machineType1838323762'; + $minInstances = 1491624145; + $maxInstances = 330682013; + $expectedResponse = new Connector(); + $expectedResponse->setName($name); + $expectedResponse->setNetwork($network); + $expectedResponse->setIpCidrRange($ipCidrRange); + $expectedResponse->setMinThroughput($minThroughput); + $expectedResponse->setMaxThroughput($maxThroughput); + $expectedResponse->setMachineType($machineType); + $expectedResponse->setMinInstances($minInstances); + $expectedResponse->setMaxInstances($maxInstances); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createConnectorTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $connectorId = 'connectorId1928724045'; + $connector = new Connector(); + $request = (new CreateConnectorRequest()) + ->setParent($formattedParent) + ->setConnectorId($connectorId) + ->setConnector($connector); + $response = $gapicClient->createConnectorAsync($request)->wait(); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.vpcaccess.v1.VpcAccessService/CreateConnector', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getConnectorId(); + $this->assertProtobufEquals($connectorId, $actualValue); + $actualValue = $actualApiRequestObject->getConnector(); + $this->assertProtobufEquals($connector, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createConnectorTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } +} diff --git a/WebRisk/src/V1/Client/BaseClient/WebRiskServiceBaseClient.php b/WebRisk/src/V1/Client/BaseClient/WebRiskServiceBaseClient.php new file mode 100644 index 000000000000..fb5c20769a59 --- /dev/null +++ b/WebRisk/src/V1/Client/BaseClient/WebRiskServiceBaseClient.php @@ -0,0 +1,403 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/web_risk_service_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/web_risk_service_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/web_risk_service_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/web_risk_service_rest_client_config.php', + ], + ], + ]; + } + + /** + * Return an OperationsClient object with the same endpoint as $this. + * + * @return OperationsClient + */ + public function getOperationsClient() + { + return $this->operationsClient; + } + + /** + * Resume an existing long running operation that was previously started by a long + * running API method. If $methodName is not provided, or does not match a long + * running API method, then the operation can still be resumed, but the + * OperationResponse object will not deserialize the final response. + * + * @param string $operationName The name of the long running operation + * @param string $methodName The name of the method used to start the operation + * + * @return OperationResponse + */ + public function resumeOperation($operationName, $methodName = null) + { + $options = isset($this->descriptors[$methodName]['longRunning']) ? $this->descriptors[$methodName]['longRunning'] : []; + $operation = new OperationResponse($operationName, $this->getOperationsClient(), $options); + $operation->reload(); + return $operation; + } + + /** + * Formats a string containing the fully-qualified path to represent a project + * resource. + * + * @param string $project + * + * @return string The formatted project resource. + */ + public static function projectName(string $project): string + { + return self::getPathTemplate('project')->render([ + 'project' => $project, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - project: projects/{project} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'webrisk.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * } + * + * @throws ValidationException + */ + public function __construct(array $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + $this->operationsClient = $this->createOperationsClient($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Gets the most recent threat list diffs. These diffs should be applied to + * a local database of hashes to keep it up-to-date. If the local database is + * empty or excessively out-of-date, a complete snapshot of the database will + * be returned. This Method only updates a single ThreatList at a time. To + * update multiple ThreatList databases, this method needs to be called once + * for each list. + * + * The async variant is {@see self::computeThreatListDiffAsync()} . + * + * @param ComputeThreatListDiffRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return ComputeThreatListDiffResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function computeThreatListDiff(ComputeThreatListDiffRequest $request, array $callOptions = []): ComputeThreatListDiffResponse + { + return $this->startApiCall('ComputeThreatListDiff', $request, $callOptions)->wait(); + } + + /** + * Creates a Submission of a URI suspected of containing phishing content to + * be reviewed. If the result verifies the existence of malicious phishing + * content, the site will be added to the [Google's Social Engineering + * lists](https://support.google.com/webmasters/answer/6350487/) in order to + * protect users that could get exposed to this threat in the future. Only + * allowlisted projects can use this method during Early Access. Please reach + * out to Sales or your customer engineer to obtain access. + * + * The async variant is {@see self::createSubmissionAsync()} . + * + * @param CreateSubmissionRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Submission + * + * @throws ApiException Thrown if the API call fails. + */ + public function createSubmission(CreateSubmissionRequest $request, array $callOptions = []): Submission + { + return $this->startApiCall('CreateSubmission', $request, $callOptions)->wait(); + } + + /** + * Gets the full hashes that match the requested hash prefix. + * This is used after a hash prefix is looked up in a threatList + * and there is a match. The client side threatList only holds partial hashes + * so the client must query this method to determine if there is a full + * hash match of a threat. + * + * The async variant is {@see self::searchHashesAsync()} . + * + * @param SearchHashesRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return SearchHashesResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function searchHashes(SearchHashesRequest $request, array $callOptions = []): SearchHashesResponse + { + return $this->startApiCall('SearchHashes', $request, $callOptions)->wait(); + } + + /** + * This method is used to check whether a URI is on a given threatList. + * Multiple threatLists may be searched in a single query. + * The response will list all requested threatLists the URI was found to + * match. If the URI is not found on any of the requested ThreatList an + * empty response will be returned. + * + * The async variant is {@see self::searchUrisAsync()} . + * + * @param SearchUrisRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return SearchUrisResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function searchUris(SearchUrisRequest $request, array $callOptions = []): SearchUrisResponse + { + return $this->startApiCall('SearchUris', $request, $callOptions)->wait(); + } + + /** + * Submits a URI suspected of containing malicious content to be reviewed. + * Returns a google.longrunning.Operation which, once the review is complete, + * is updated with its result. You can use the [Pub/Sub API] + * (https://cloud.google.com/pubsub) to receive notifications for the returned + * Operation. If the result verifies the existence of malicious content, the + * site will be added to the [Google's Social Engineering lists] + * (https://support.google.com/webmasters/answer/6350487/) in order to + * protect users that could get exposed to this threat in the future. Only + * allowlisted projects can use this method during Early Access. Please reach + * out to Sales or your customer engineer to obtain access. + * + * The async variant is {@see self::submitUriAsync()} . + * + * @param SubmitUriRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function submitUri(SubmitUriRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('SubmitUri', $request, $callOptions)->wait(); + } +} diff --git a/WebRisk/src/V1/Client/WebRiskServiceClient.php b/WebRisk/src/V1/Client/WebRiskServiceClient.php new file mode 100644 index 000000000000..521b57ce5bc2 --- /dev/null +++ b/WebRisk/src/V1/Client/WebRiskServiceClient.php @@ -0,0 +1,40 @@ +setThreatType($threatType) + ->setVersionToken($versionToken) + ->setConstraints($constraints); + } + /** * Constructor. * diff --git a/WebRisk/src/V1/CreateSubmissionRequest.php b/WebRisk/src/V1/CreateSubmissionRequest.php index d6cdfb3d5c81..d92be7b35781 100644 --- a/WebRisk/src/V1/CreateSubmissionRequest.php +++ b/WebRisk/src/V1/CreateSubmissionRequest.php @@ -29,6 +29,23 @@ class CreateSubmissionRequest extends \Google\Protobuf\Internal\Message */ private $submission = null; + /** + * @param string $parent Required. The name of the project that is making the submission. This + * string is in the format "projects/{project_number}". Please see + * {@see WebRiskServiceClient::projectName()} for help formatting this field. + * @param \Google\Cloud\WebRisk\V1\Submission $submission Required. The submission that contains the content of the phishing report. + * + * @return \Google\Cloud\WebRisk\V1\CreateSubmissionRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\WebRisk\V1\Submission $submission): self + { + return (new self()) + ->setParent($parent) + ->setSubmission($submission); + } + /** * Constructor. * diff --git a/WebRisk/src/V1/SearchHashesRequest.php b/WebRisk/src/V1/SearchHashesRequest.php index a29e79cec05f..cc89da297737 100644 --- a/WebRisk/src/V1/SearchHashesRequest.php +++ b/WebRisk/src/V1/SearchHashesRequest.php @@ -32,6 +32,26 @@ class SearchHashesRequest extends \Google\Protobuf\Internal\Message */ private $threat_types; + /** + * @param string $hashPrefix A hash prefix, consisting of the most significant 4-32 bytes of a SHA256 + * hash. For JSON requests, this field is base64-encoded. + * Note that if this parameter is provided by a URI, it must be encoded using + * the web safe base64 variant (RFC 4648). + * @param int[] $threatTypes Required. The ThreatLists to search in. Multiple ThreatLists may be + * specified. + * For allowed values, use constants defined on {@see \Google\Cloud\WebRisk\V1\ThreatType} + * + * @return \Google\Cloud\WebRisk\V1\SearchHashesRequest + * + * @experimental + */ + public static function build(string $hashPrefix, array $threatTypes): self + { + return (new self()) + ->setHashPrefix($hashPrefix) + ->setThreatTypes($threatTypes); + } + /** * Constructor. * diff --git a/WebRisk/src/V1/SearchUrisRequest.php b/WebRisk/src/V1/SearchUrisRequest.php index 9a893fc3d873..bed3dfb1ac6d 100644 --- a/WebRisk/src/V1/SearchUrisRequest.php +++ b/WebRisk/src/V1/SearchUrisRequest.php @@ -29,6 +29,23 @@ class SearchUrisRequest extends \Google\Protobuf\Internal\Message */ private $threat_types; + /** + * @param string $uri Required. The URI to be checked for matches. + * @param int[] $threatTypes Required. The ThreatLists to search in. Multiple ThreatLists may be + * specified. + * For allowed values, use constants defined on {@see \Google\Cloud\WebRisk\V1\ThreatType} + * + * @return \Google\Cloud\WebRisk\V1\SearchUrisRequest + * + * @experimental + */ + public static function build(string $uri, array $threatTypes): self + { + return (new self()) + ->setUri($uri) + ->setThreatTypes($threatTypes); + } + /** * Constructor. * diff --git a/WebRisk/src/V1/resources/web_risk_service_descriptor_config.php b/WebRisk/src/V1/resources/web_risk_service_descriptor_config.php index 1b17faa7eafe..1eb7f1427c23 100644 --- a/WebRisk/src/V1/resources/web_risk_service_descriptor_config.php +++ b/WebRisk/src/V1/resources/web_risk_service_descriptor_config.php @@ -12,6 +12,42 @@ 'maxPollDelayMillis' => '5000', 'totalPollTimeoutMillis' => '300000', ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'ComputeThreatListDiff' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\WebRisk\V1\ComputeThreatListDiffResponse', + ], + 'CreateSubmission' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\WebRisk\V1\Submission', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'SearchHashes' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\WebRisk\V1\SearchHashesResponse', + ], + 'SearchUris' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\WebRisk\V1\SearchUrisResponse', + ], + 'templateMap' => [ + 'project' => 'projects/{project}', ], ], ], diff --git a/WebRisk/tests/Unit/V1/Client/WebRiskServiceClientTest.php b/WebRisk/tests/Unit/V1/Client/WebRiskServiceClientTest.php new file mode 100644 index 000000000000..e722ac66e5b0 --- /dev/null +++ b/WebRisk/tests/Unit/V1/Client/WebRiskServiceClientTest.php @@ -0,0 +1,515 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return WebRiskServiceClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new WebRiskServiceClient($options); + } + + /** @test */ + public function computeThreatListDiffTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $newVersionToken = '115'; + $expectedResponse = new ComputeThreatListDiffResponse(); + $expectedResponse->setNewVersionToken($newVersionToken); + $transport->addResponse($expectedResponse); + // Mock request + $threatType = ThreatType::THREAT_TYPE_UNSPECIFIED; + $constraints = new Constraints(); + $request = (new ComputeThreatListDiffRequest()) + ->setThreatType($threatType) + ->setConstraints($constraints); + $response = $gapicClient->computeThreatListDiff($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.webrisk.v1.WebRiskService/ComputeThreatListDiff', $actualFuncCall); + $actualValue = $actualRequestObject->getThreatType(); + $this->assertProtobufEquals($threatType, $actualValue); + $actualValue = $actualRequestObject->getConstraints(); + $this->assertProtobufEquals($constraints, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function computeThreatListDiffExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $threatType = ThreatType::THREAT_TYPE_UNSPECIFIED; + $constraints = new Constraints(); + $request = (new ComputeThreatListDiffRequest()) + ->setThreatType($threatType) + ->setConstraints($constraints); + try { + $gapicClient->computeThreatListDiff($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createSubmissionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $uri = 'uri116076'; + $expectedResponse = new Submission(); + $expectedResponse->setUri($uri); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->projectName('[PROJECT]'); + $submission = new Submission(); + $submissionUri = 'submissionUri-1560297856'; + $submission->setUri($submissionUri); + $request = (new CreateSubmissionRequest()) + ->setParent($formattedParent) + ->setSubmission($submission); + $response = $gapicClient->createSubmission($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.webrisk.v1.WebRiskService/CreateSubmission', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getSubmission(); + $this->assertProtobufEquals($submission, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createSubmissionExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->projectName('[PROJECT]'); + $submission = new Submission(); + $submissionUri = 'submissionUri-1560297856'; + $submission->setUri($submissionUri); + $request = (new CreateSubmissionRequest()) + ->setParent($formattedParent) + ->setSubmission($submission); + try { + $gapicClient->createSubmission($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function searchHashesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new SearchHashesResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $threatTypes = []; + $request = (new SearchHashesRequest()) + ->setThreatTypes($threatTypes); + $response = $gapicClient->searchHashes($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.webrisk.v1.WebRiskService/SearchHashes', $actualFuncCall); + $actualValue = $actualRequestObject->getThreatTypes(); + $this->assertProtobufEquals($threatTypes, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function searchHashesExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $threatTypes = []; + $request = (new SearchHashesRequest()) + ->setThreatTypes($threatTypes); + try { + $gapicClient->searchHashes($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function searchUrisTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new SearchUrisResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $uri = 'uri116076'; + $threatTypes = []; + $request = (new SearchUrisRequest()) + ->setUri($uri) + ->setThreatTypes($threatTypes); + $response = $gapicClient->searchUris($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.webrisk.v1.WebRiskService/SearchUris', $actualFuncCall); + $actualValue = $actualRequestObject->getUri(); + $this->assertProtobufEquals($uri, $actualValue); + $actualValue = $actualRequestObject->getThreatTypes(); + $this->assertProtobufEquals($threatTypes, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function searchUrisExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $uri = 'uri116076'; + $threatTypes = []; + $request = (new SearchUrisRequest()) + ->setUri($uri) + ->setThreatTypes($threatTypes); + try { + $gapicClient->searchUris($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function submitUriTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/submitUriTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $uri = 'uri116076'; + $expectedResponse = new Submission(); + $expectedResponse->setUri($uri); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/submitUriTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->projectName('[PROJECT]'); + $submission = new Submission(); + $submissionUri = 'submissionUri-1560297856'; + $submission->setUri($submissionUri); + $request = (new SubmitUriRequest()) + ->setParent($formattedParent) + ->setSubmission($submission); + $response = $gapicClient->submitUri($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.webrisk.v1.WebRiskService/SubmitUri', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getSubmission(); + $this->assertProtobufEquals($submission, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/submitUriTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function submitUriExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/submitUriTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->projectName('[PROJECT]'); + $submission = new Submission(); + $submissionUri = 'submissionUri-1560297856'; + $submission->setUri($submissionUri); + $request = (new SubmitUriRequest()) + ->setParent($formattedParent) + ->setSubmission($submission); + $response = $gapicClient->submitUri($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/submitUriTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function computeThreatListDiffAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $newVersionToken = '115'; + $expectedResponse = new ComputeThreatListDiffResponse(); + $expectedResponse->setNewVersionToken($newVersionToken); + $transport->addResponse($expectedResponse); + // Mock request + $threatType = ThreatType::THREAT_TYPE_UNSPECIFIED; + $constraints = new Constraints(); + $request = (new ComputeThreatListDiffRequest()) + ->setThreatType($threatType) + ->setConstraints($constraints); + $response = $gapicClient->computeThreatListDiffAsync($request)->wait(); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.webrisk.v1.WebRiskService/ComputeThreatListDiff', $actualFuncCall); + $actualValue = $actualRequestObject->getThreatType(); + $this->assertProtobufEquals($threatType, $actualValue); + $actualValue = $actualRequestObject->getConstraints(); + $this->assertProtobufEquals($constraints, $actualValue); + $this->assertTrue($transport->isExhausted()); + } +} diff --git a/WebSecurityScanner/metadata/V1/CrawledUrl.php b/WebSecurityScanner/metadata/V1/CrawledUrl.php new file mode 100644 index 000000000000..7abf286dcd09 --- /dev/null +++ b/WebSecurityScanner/metadata/V1/CrawledUrl.php @@ -0,0 +1,32 @@ +internalAddGeneratedFile( + ' +� +4google/cloud/websecurityscanner/v1/crawled_url.proto"google.cloud.websecurityscanner.v1"< + +CrawledUrl + http_method (  +url (  +body ( B� +&com.google.cloud.websecurityscanner.v1BCrawledUrlProtoPZVcloud.google.com/go/websecurityscanner/apiv1/websecurityscannerpb;websecurityscannerpb�"Google.Cloud.WebSecurityScanner.V1�"Google\\Cloud\\WebSecurityScanner\\V1�%Google::Cloud::WebSecurityScanner::V1bproto3' + , true); + + static::$is_initialized = true; + } +} + diff --git a/WebSecurityScanner/metadata/V1/Finding.php b/WebSecurityScanner/metadata/V1/Finding.php new file mode 100644 index 000000000000..18c485bde73d Binary files /dev/null and b/WebSecurityScanner/metadata/V1/Finding.php differ diff --git a/WebSecurityScanner/metadata/V1/FindingAddon.php b/WebSecurityScanner/metadata/V1/FindingAddon.php new file mode 100644 index 000000000000..c02f052dabd6 Binary files /dev/null and b/WebSecurityScanner/metadata/V1/FindingAddon.php differ diff --git a/WebSecurityScanner/metadata/V1/FindingTypeStats.php b/WebSecurityScanner/metadata/V1/FindingTypeStats.php new file mode 100644 index 000000000000..5adf798d2118 --- /dev/null +++ b/WebSecurityScanner/metadata/V1/FindingTypeStats.php @@ -0,0 +1,30 @@ +internalAddGeneratedFile( + ' +� +;google/cloud/websecurityscanner/v1/finding_type_stats.proto"google.cloud.websecurityscanner.v1"? +FindingTypeStats + finding_type (  + finding_count (B� +&com.google.cloud.websecurityscanner.v1BFindingTypeStatsProtoPZVcloud.google.com/go/websecurityscanner/apiv1/websecurityscannerpb;websecurityscannerpb�"Google.Cloud.WebSecurityScanner.V1�"Google\\Cloud\\WebSecurityScanner\\V1�%Google::Cloud::WebSecurityScanner::V1bproto3' + , true); + + static::$is_initialized = true; + } +} + diff --git a/WebSecurityScanner/metadata/V1/ScanConfig.php b/WebSecurityScanner/metadata/V1/ScanConfig.php new file mode 100644 index 000000000000..c76e4b19e970 Binary files /dev/null and b/WebSecurityScanner/metadata/V1/ScanConfig.php differ diff --git a/WebSecurityScanner/metadata/V1/ScanConfigError.php b/WebSecurityScanner/metadata/V1/ScanConfigError.php new file mode 100644 index 000000000000..b7027109c6ef Binary files /dev/null and b/WebSecurityScanner/metadata/V1/ScanConfigError.php differ diff --git a/WebSecurityScanner/metadata/V1/ScanRun.php b/WebSecurityScanner/metadata/V1/ScanRun.php new file mode 100644 index 000000000000..26b7e2bce31e Binary files /dev/null and b/WebSecurityScanner/metadata/V1/ScanRun.php differ diff --git a/WebSecurityScanner/metadata/V1/ScanRunErrorTrace.php b/WebSecurityScanner/metadata/V1/ScanRunErrorTrace.php new file mode 100644 index 000000000000..40fb8ea299f6 Binary files /dev/null and b/WebSecurityScanner/metadata/V1/ScanRunErrorTrace.php differ diff --git a/WebSecurityScanner/metadata/V1/ScanRunLog.php b/WebSecurityScanner/metadata/V1/ScanRunLog.php new file mode 100644 index 000000000000..1a1d25862ccf --- /dev/null +++ b/WebSecurityScanner/metadata/V1/ScanRunLog.php @@ -0,0 +1,39 @@ +internalAddGeneratedFile( + ' +� +5google/cloud/websecurityscanner/v1/scan_run_log.proto"google.cloud.websecurityscanner.v1=google/cloud/websecurityscanner/v1/scan_run_error_trace.proto"� + +ScanRunLog +summary (  +name ( S +execution_state (2:.google.cloud.websecurityscanner.v1.ScanRun.ExecutionStateM + result_state (27.google.cloud.websecurityscanner.v1.ScanRun.ResultState +urls_crawled_count ( +urls_tested_count ( + has_findings (J + error_trace ( 25.google.cloud.websecurityscanner.v1.ScanRunErrorTraceB� +&com.google.cloud.websecurityscanner.v1BScanRunLogProtoPZVcloud.google.com/go/websecurityscanner/apiv1/websecurityscannerpb;websecurityscannerpb�"Google.Cloud.WebSecurityScanner.V1�"Google\\Cloud\\WebSecurityScanner\\V1�%Google::Cloud::WebSecurityScanner::V1bproto3' + , true); + + static::$is_initialized = true; + } +} + diff --git a/WebSecurityScanner/metadata/V1/ScanRunWarningTrace.php b/WebSecurityScanner/metadata/V1/ScanRunWarningTrace.php new file mode 100644 index 000000000000..186f828d82ce Binary files /dev/null and b/WebSecurityScanner/metadata/V1/ScanRunWarningTrace.php differ diff --git a/WebSecurityScanner/metadata/V1/WebSecurityScanner.php b/WebSecurityScanner/metadata/V1/WebSecurityScanner.php new file mode 100644 index 000000000000..a95d6eef8c5e --- /dev/null +++ b/WebSecurityScanner/metadata/V1/WebSecurityScanner.php @@ -0,0 +1,107 @@ +internalAddGeneratedFile( + ' +�$ +=google/cloud/websecurityscanner/v1/web_security_scanner.proto"google.cloud.websecurityscanner.v1google/api/client.proto4google/cloud/websecurityscanner/v1/crawled_url.proto0google/cloud/websecurityscanner/v1/finding.proto;google/cloud/websecurityscanner/v1/finding_type_stats.proto4google/cloud/websecurityscanner/v1/scan_config.proto1google/cloud/websecurityscanner/v1/scan_run.protogoogle/protobuf/empty.proto google/protobuf/field_mask.proto"n +CreateScanConfigRequest +parent ( C + scan_config ( 2..google.cloud.websecurityscanner.v1.ScanConfig"\' +DeleteScanConfigRequest +name ( "$ +GetScanConfigRequest +name ( "O +ListScanConfigsRequest +parent (  + +page_token (  + page_size ("� +UpdateScanConfigRequestC + scan_config ( 2..google.cloud.websecurityscanner.v1.ScanConfig/ + update_mask ( 2.google.protobuf.FieldMask"x +ListScanConfigsResponseD + scan_configs ( 2..google.cloud.websecurityscanner.v1.ScanConfig +next_page_token ( "# +StartScanRunRequest +name ( "! +GetScanRunRequest +name ( "L +ListScanRunsRequest +parent (  + +page_token (  + page_size ("o +ListScanRunsResponse> + scan_runs ( 2+.google.cloud.websecurityscanner.v1.ScanRun +next_page_token ( "" +StopScanRunRequest +name ( "O +ListCrawledUrlsRequest +parent (  + +page_token (  + page_size ("x +ListCrawledUrlsResponseD + crawled_urls ( 2..google.cloud.websecurityscanner.v1.CrawledUrl +next_page_token ( "! +GetFindingRequest +name ( "\\ +ListFindingsRequest +parent (  +filter (  + +page_token (  + page_size ("n +ListFindingsResponse= +findings ( 2+.google.cloud.websecurityscanner.v1.Finding +next_page_token ( "- +ListFindingTypeStatsRequest +parent ( "p +ListFindingTypeStatsResponseP +finding_type_stats ( 24.google.cloud.websecurityscanner.v1.FindingTypeStats2� +WebSecurityScanner� +CreateScanConfig;.google.cloud.websecurityscanner.v1.CreateScanConfigRequest..google.cloud.websecurityscanner.v1.ScanConfig"8���2"#/v1/{parent=projects/*}/scanConfigs: scan_config� +DeleteScanConfig;.google.cloud.websecurityscanner.v1.DeleteScanConfigRequest.google.protobuf.Empty"+���%*#/v1/{name=projects/*/scanConfigs/*}� + GetScanConfig8.google.cloud.websecurityscanner.v1.GetScanConfigRequest..google.cloud.websecurityscanner.v1.ScanConfig"+���%#/v1/{name=projects/*/scanConfigs/*}� +ListScanConfigs:.google.cloud.websecurityscanner.v1.ListScanConfigsRequest;.google.cloud.websecurityscanner.v1.ListScanConfigsResponse"+���%#/v1/{parent=projects/*}/scanConfigs� +UpdateScanConfig;.google.cloud.websecurityscanner.v1.UpdateScanConfigRequest..google.cloud.websecurityscanner.v1.ScanConfig"D���>2//v1/{scan_config.name=projects/*/scanConfigs/*}: scan_config� + StartScanRun7.google.cloud.websecurityscanner.v1.StartScanRunRequest+.google.cloud.websecurityscanner.v1.ScanRun"4���.")/v1/{name=projects/*/scanConfigs/*}:start:*� + +GetScanRun5.google.cloud.websecurityscanner.v1.GetScanRunRequest+.google.cloud.websecurityscanner.v1.ScanRun"6���0./v1/{name=projects/*/scanConfigs/*/scanRuns/*}� + ListScanRuns7.google.cloud.websecurityscanner.v1.ListScanRunsRequest8.google.cloud.websecurityscanner.v1.ListScanRunsResponse"6���0./v1/{parent=projects/*/scanConfigs/*}/scanRuns� + StopScanRun6.google.cloud.websecurityscanner.v1.StopScanRunRequest+.google.cloud.websecurityscanner.v1.ScanRun">���8"3/v1/{name=projects/*/scanConfigs/*/scanRuns/*}:stop:*� +ListCrawledUrls:.google.cloud.websecurityscanner.v1.ListCrawledUrlsRequest;.google.cloud.websecurityscanner.v1.ListCrawledUrlsResponse"D���>createScanConfig($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); + } catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); + } +} +// [END websecurityscanner_v1_generated_WebSecurityScanner_CreateScanConfig_sync] diff --git a/WebSecurityScanner/samples/V1/WebSecurityScannerClient/delete_scan_config.php b/WebSecurityScanner/samples/V1/WebSecurityScannerClient/delete_scan_config.php new file mode 100644 index 000000000000..f76539ef65e2 --- /dev/null +++ b/WebSecurityScanner/samples/V1/WebSecurityScannerClient/delete_scan_config.php @@ -0,0 +1,55 @@ +deleteScanConfig($request); + printf('Call completed successfully.' . PHP_EOL); + } catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); + } +} +// [END websecurityscanner_v1_generated_WebSecurityScanner_DeleteScanConfig_sync] diff --git a/WebSecurityScanner/samples/V1/WebSecurityScannerClient/get_finding.php b/WebSecurityScanner/samples/V1/WebSecurityScannerClient/get_finding.php new file mode 100644 index 000000000000..18cc2c9645fe --- /dev/null +++ b/WebSecurityScanner/samples/V1/WebSecurityScannerClient/get_finding.php @@ -0,0 +1,57 @@ +getFinding($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); + } catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); + } +} +// [END websecurityscanner_v1_generated_WebSecurityScanner_GetFinding_sync] diff --git a/WebSecurityScanner/samples/V1/WebSecurityScannerClient/get_scan_config.php b/WebSecurityScanner/samples/V1/WebSecurityScannerClient/get_scan_config.php new file mode 100644 index 000000000000..72439093c3b6 --- /dev/null +++ b/WebSecurityScanner/samples/V1/WebSecurityScannerClient/get_scan_config.php @@ -0,0 +1,57 @@ +getScanConfig($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); + } catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); + } +} +// [END websecurityscanner_v1_generated_WebSecurityScanner_GetScanConfig_sync] diff --git a/WebSecurityScanner/samples/V1/WebSecurityScannerClient/get_scan_run.php b/WebSecurityScanner/samples/V1/WebSecurityScannerClient/get_scan_run.php new file mode 100644 index 000000000000..b97d23c7bcfd --- /dev/null +++ b/WebSecurityScanner/samples/V1/WebSecurityScannerClient/get_scan_run.php @@ -0,0 +1,57 @@ +getScanRun($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); + } catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); + } +} +// [END websecurityscanner_v1_generated_WebSecurityScanner_GetScanRun_sync] diff --git a/WebSecurityScanner/samples/V1/WebSecurityScannerClient/list_crawled_urls.php b/WebSecurityScanner/samples/V1/WebSecurityScannerClient/list_crawled_urls.php new file mode 100644 index 000000000000..7895459f9c35 --- /dev/null +++ b/WebSecurityScanner/samples/V1/WebSecurityScannerClient/list_crawled_urls.php @@ -0,0 +1,62 @@ +listCrawledUrls($request); + + /** @var CrawledUrl $element */ + foreach ($response as $element) { + printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString()); + } + } catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); + } +} +// [END websecurityscanner_v1_generated_WebSecurityScanner_ListCrawledUrls_sync] diff --git a/WebSecurityScanner/samples/V1/WebSecurityScannerClient/list_finding_type_stats.php b/WebSecurityScanner/samples/V1/WebSecurityScannerClient/list_finding_type_stats.php new file mode 100644 index 000000000000..72c5a32679f4 --- /dev/null +++ b/WebSecurityScanner/samples/V1/WebSecurityScannerClient/list_finding_type_stats.php @@ -0,0 +1,57 @@ +listFindingTypeStats($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); + } catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); + } +} +// [END websecurityscanner_v1_generated_WebSecurityScanner_ListFindingTypeStats_sync] diff --git a/WebSecurityScanner/samples/V1/WebSecurityScannerClient/list_findings.php b/WebSecurityScanner/samples/V1/WebSecurityScannerClient/list_findings.php new file mode 100644 index 000000000000..d632f0d11d20 --- /dev/null +++ b/WebSecurityScanner/samples/V1/WebSecurityScannerClient/list_findings.php @@ -0,0 +1,62 @@ +listFindings($request); + + /** @var Finding $element */ + foreach ($response as $element) { + printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString()); + } + } catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); + } +} +// [END websecurityscanner_v1_generated_WebSecurityScanner_ListFindings_sync] diff --git a/WebSecurityScanner/samples/V1/WebSecurityScannerClient/list_scan_configs.php b/WebSecurityScanner/samples/V1/WebSecurityScannerClient/list_scan_configs.php new file mode 100644 index 000000000000..e9f801bf1636 --- /dev/null +++ b/WebSecurityScanner/samples/V1/WebSecurityScannerClient/list_scan_configs.php @@ -0,0 +1,62 @@ +listScanConfigs($request); + + /** @var ScanConfig $element */ + foreach ($response as $element) { + printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString()); + } + } catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); + } +} +// [END websecurityscanner_v1_generated_WebSecurityScanner_ListScanConfigs_sync] diff --git a/WebSecurityScanner/samples/V1/WebSecurityScannerClient/list_scan_runs.php b/WebSecurityScanner/samples/V1/WebSecurityScannerClient/list_scan_runs.php new file mode 100644 index 000000000000..5dc4bb0a91ac --- /dev/null +++ b/WebSecurityScanner/samples/V1/WebSecurityScannerClient/list_scan_runs.php @@ -0,0 +1,63 @@ +listScanRuns($request); + + /** @var ScanRun $element */ + foreach ($response as $element) { + printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString()); + } + } catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); + } +} +// [END websecurityscanner_v1_generated_WebSecurityScanner_ListScanRuns_sync] diff --git a/WebSecurityScanner/samples/V1/WebSecurityScannerClient/start_scan_run.php b/WebSecurityScanner/samples/V1/WebSecurityScannerClient/start_scan_run.php new file mode 100644 index 000000000000..50f53abd904b --- /dev/null +++ b/WebSecurityScanner/samples/V1/WebSecurityScannerClient/start_scan_run.php @@ -0,0 +1,57 @@ +startScanRun($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); + } catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); + } +} +// [END websecurityscanner_v1_generated_WebSecurityScanner_StartScanRun_sync] diff --git a/WebSecurityScanner/samples/V1/WebSecurityScannerClient/stop_scan_run.php b/WebSecurityScanner/samples/V1/WebSecurityScannerClient/stop_scan_run.php new file mode 100644 index 000000000000..580dfda0283b --- /dev/null +++ b/WebSecurityScanner/samples/V1/WebSecurityScannerClient/stop_scan_run.php @@ -0,0 +1,57 @@ +stopScanRun($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); + } catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); + } +} +// [END websecurityscanner_v1_generated_WebSecurityScanner_StopScanRun_sync] diff --git a/WebSecurityScanner/samples/V1/WebSecurityScannerClient/update_scan_config.php b/WebSecurityScanner/samples/V1/WebSecurityScannerClient/update_scan_config.php new file mode 100644 index 000000000000..357512c8c83b --- /dev/null +++ b/WebSecurityScanner/samples/V1/WebSecurityScannerClient/update_scan_config.php @@ -0,0 +1,57 @@ +updateScanConfig($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); + } catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); + } +} +// [END websecurityscanner_v1_generated_WebSecurityScanner_UpdateScanConfig_sync] diff --git a/WebSecurityScanner/src/V1/Client/BaseClient/WebSecurityScannerBaseClient.php b/WebSecurityScanner/src/V1/Client/BaseClient/WebSecurityScannerBaseClient.php new file mode 100644 index 000000000000..b8394c87a495 --- /dev/null +++ b/WebSecurityScanner/src/V1/Client/BaseClient/WebSecurityScannerBaseClient.php @@ -0,0 +1,503 @@ + self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../../resources/web_security_scanner_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../../resources/web_security_scanner_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../../resources/web_security_scanner_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../../resources/web_security_scanner_rest_client_config.php', + ], + ], + ]; + } + + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'websecurityscanner.googleapis.com:443'. + * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials + * The credentials to be used by the client to authorize API calls. This option + * accepts either a path to a credentials file, or a decoded credentials file as a + * PHP array. + * *Advanced usage*: In addition, this option can also accept a pre-constructed + * {@see \Google\Auth\FetchAuthTokenInterface} object or + * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these + * objects are provided, any settings in $credentialsConfig will be ignored. + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * } + * + * @throws ValidationException + */ + public function __construct(array $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Creates a new ScanConfig. + * + * The async variant is {@see self::createScanConfigAsync()} . + * + * @param CreateScanConfigRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return ScanConfig + * + * @throws ApiException Thrown if the API call fails. + */ + public function createScanConfig(CreateScanConfigRequest $request, array $callOptions = []): ScanConfig + { + return $this->startApiCall('CreateScanConfig', $request, $callOptions)->wait(); + } + + /** + * Deletes an existing ScanConfig and its child resources. + * + * The async variant is {@see self::deleteScanConfigAsync()} . + * + * @param DeleteScanConfigRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteScanConfig(DeleteScanConfigRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeleteScanConfig', $request, $callOptions)->wait(); + } + + /** + * Gets a Finding. + * + * The async variant is {@see self::getFindingAsync()} . + * + * @param GetFindingRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Finding + * + * @throws ApiException Thrown if the API call fails. + */ + public function getFinding(GetFindingRequest $request, array $callOptions = []): Finding + { + return $this->startApiCall('GetFinding', $request, $callOptions)->wait(); + } + + /** + * Gets a ScanConfig. + * + * The async variant is {@see self::getScanConfigAsync()} . + * + * @param GetScanConfigRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return ScanConfig + * + * @throws ApiException Thrown if the API call fails. + */ + public function getScanConfig(GetScanConfigRequest $request, array $callOptions = []): ScanConfig + { + return $this->startApiCall('GetScanConfig', $request, $callOptions)->wait(); + } + + /** + * Gets a ScanRun. + * + * The async variant is {@see self::getScanRunAsync()} . + * + * @param GetScanRunRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return ScanRun + * + * @throws ApiException Thrown if the API call fails. + */ + public function getScanRun(GetScanRunRequest $request, array $callOptions = []): ScanRun + { + return $this->startApiCall('GetScanRun', $request, $callOptions)->wait(); + } + + /** + * List CrawledUrls under a given ScanRun. + * + * The async variant is {@see self::listCrawledUrlsAsync()} . + * + * @param ListCrawledUrlsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listCrawledUrls(ListCrawledUrlsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListCrawledUrls', $request, $callOptions); + } + + /** + * List all FindingTypeStats under a given ScanRun. + * + * The async variant is {@see self::listFindingTypeStatsAsync()} . + * + * @param ListFindingTypeStatsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return ListFindingTypeStatsResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listFindingTypeStats(ListFindingTypeStatsRequest $request, array $callOptions = []): ListFindingTypeStatsResponse + { + return $this->startApiCall('ListFindingTypeStats', $request, $callOptions)->wait(); + } + + /** + * List Findings under a given ScanRun. + * + * The async variant is {@see self::listFindingsAsync()} . + * + * @param ListFindingsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listFindings(ListFindingsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListFindings', $request, $callOptions); + } + + /** + * Lists ScanConfigs under a given project. + * + * The async variant is {@see self::listScanConfigsAsync()} . + * + * @param ListScanConfigsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listScanConfigs(ListScanConfigsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListScanConfigs', $request, $callOptions); + } + + /** + * Lists ScanRuns under a given ScanConfig, in descending order of ScanRun + * stop time. + * + * The async variant is {@see self::listScanRunsAsync()} . + * + * @param ListScanRunsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listScanRuns(ListScanRunsRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListScanRuns', $request, $callOptions); + } + + /** + * Start a ScanRun according to the given ScanConfig. + * + * The async variant is {@see self::startScanRunAsync()} . + * + * @param StartScanRunRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return ScanRun + * + * @throws ApiException Thrown if the API call fails. + */ + public function startScanRun(StartScanRunRequest $request, array $callOptions = []): ScanRun + { + return $this->startApiCall('StartScanRun', $request, $callOptions)->wait(); + } + + /** + * Stops a ScanRun. The stopped ScanRun is returned. + * + * The async variant is {@see self::stopScanRunAsync()} . + * + * @param StopScanRunRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return ScanRun + * + * @throws ApiException Thrown if the API call fails. + */ + public function stopScanRun(StopScanRunRequest $request, array $callOptions = []): ScanRun + { + return $this->startApiCall('StopScanRun', $request, $callOptions)->wait(); + } + + /** + * Updates a ScanConfig. This method support partial update of a ScanConfig. + * + * The async variant is {@see self::updateScanConfigAsync()} . + * + * @param UpdateScanConfigRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return ScanConfig + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateScanConfig(UpdateScanConfigRequest $request, array $callOptions = []): ScanConfig + { + return $this->startApiCall('UpdateScanConfig', $request, $callOptions)->wait(); + } +} diff --git a/WebSecurityScanner/src/V1/Client/WebSecurityScannerClient.php b/WebSecurityScanner/src/V1/Client/WebSecurityScannerClient.php new file mode 100644 index 000000000000..1bb8668679a7 --- /dev/null +++ b/WebSecurityScanner/src/V1/Client/WebSecurityScannerClient.php @@ -0,0 +1,40 @@ +google.cloud.websecurityscanner.v1.CrawledUrl + */ +class CrawledUrl extends \Google\Protobuf\Internal\Message +{ + /** + * Output only. The http method of the request that was used to visit the URL, in + * uppercase. + * + * Generated from protobuf field string http_method = 1; + */ + private $http_method = ''; + /** + * Output only. The URL that was crawled. + * + * Generated from protobuf field string url = 2; + */ + private $url = ''; + /** + * Output only. The body of the request that was used to visit the URL. + * + * Generated from protobuf field string body = 3; + */ + private $body = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $http_method + * Output only. The http method of the request that was used to visit the URL, in + * uppercase. + * @type string $url + * Output only. The URL that was crawled. + * @type string $body + * Output only. The body of the request that was used to visit the URL. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\CrawledUrl::initOnce(); + parent::__construct($data); + } + + /** + * Output only. The http method of the request that was used to visit the URL, in + * uppercase. + * + * Generated from protobuf field string http_method = 1; + * @return string + */ + public function getHttpMethod() + { + return $this->http_method; + } + + /** + * Output only. The http method of the request that was used to visit the URL, in + * uppercase. + * + * Generated from protobuf field string http_method = 1; + * @param string $var + * @return $this + */ + public function setHttpMethod($var) + { + GPBUtil::checkString($var, True); + $this->http_method = $var; + + return $this; + } + + /** + * Output only. The URL that was crawled. + * + * Generated from protobuf field string url = 2; + * @return string + */ + public function getUrl() + { + return $this->url; + } + + /** + * Output only. The URL that was crawled. + * + * Generated from protobuf field string url = 2; + * @param string $var + * @return $this + */ + public function setUrl($var) + { + GPBUtil::checkString($var, True); + $this->url = $var; + + return $this; + } + + /** + * Output only. The body of the request that was used to visit the URL. + * + * Generated from protobuf field string body = 3; + * @return string + */ + public function getBody() + { + return $this->body; + } + + /** + * Output only. The body of the request that was used to visit the URL. + * + * Generated from protobuf field string body = 3; + * @param string $var + * @return $this + */ + public function setBody($var) + { + GPBUtil::checkString($var, True); + $this->body = $var; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/CreateScanConfigRequest.php b/WebSecurityScanner/src/V1/CreateScanConfigRequest.php new file mode 100644 index 000000000000..7304c81603fd --- /dev/null +++ b/WebSecurityScanner/src/V1/CreateScanConfigRequest.php @@ -0,0 +1,115 @@ +google.cloud.websecurityscanner.v1.CreateScanConfigRequest + */ +class CreateScanConfigRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The parent resource name where the scan is created, which should be a + * project resource name in the format 'projects/{projectId}'. + * + * Generated from protobuf field string parent = 1; + */ + private $parent = ''; + /** + * Required. The ScanConfig to be created. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfig scan_config = 2; + */ + private $scan_config = null; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $parent + * Required. The parent resource name where the scan is created, which should be a + * project resource name in the format 'projects/{projectId}'. + * @type \Google\Cloud\WebSecurityScanner\V1\ScanConfig $scan_config + * Required. The ScanConfig to be created. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\WebSecurityScanner::initOnce(); + parent::__construct($data); + } + + /** + * Required. The parent resource name where the scan is created, which should be a + * project resource name in the format 'projects/{projectId}'. + * + * Generated from protobuf field string parent = 1; + * @return string + */ + public function getParent() + { + return $this->parent; + } + + /** + * Required. The parent resource name where the scan is created, which should be a + * project resource name in the format 'projects/{projectId}'. + * + * Generated from protobuf field string parent = 1; + * @param string $var + * @return $this + */ + public function setParent($var) + { + GPBUtil::checkString($var, True); + $this->parent = $var; + + return $this; + } + + /** + * Required. The ScanConfig to be created. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfig scan_config = 2; + * @return \Google\Cloud\WebSecurityScanner\V1\ScanConfig|null + */ + public function getScanConfig() + { + return $this->scan_config; + } + + public function hasScanConfig() + { + return isset($this->scan_config); + } + + public function clearScanConfig() + { + unset($this->scan_config); + } + + /** + * Required. The ScanConfig to be created. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfig scan_config = 2; + * @param \Google\Cloud\WebSecurityScanner\V1\ScanConfig $var + * @return $this + */ + public function setScanConfig($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\WebSecurityScanner\V1\ScanConfig::class); + $this->scan_config = $var; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/DeleteScanConfigRequest.php b/WebSecurityScanner/src/V1/DeleteScanConfigRequest.php new file mode 100644 index 000000000000..a80b0a779f66 --- /dev/null +++ b/WebSecurityScanner/src/V1/DeleteScanConfigRequest.php @@ -0,0 +1,71 @@ +google.cloud.websecurityscanner.v1.DeleteScanConfigRequest + */ +class DeleteScanConfigRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The resource name of the ScanConfig to be deleted. The name follows the + * format of 'projects/{projectId}/scanConfigs/{scanConfigId}'. + * + * Generated from protobuf field string name = 1; + */ + private $name = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * Required. The resource name of the ScanConfig to be deleted. The name follows the + * format of 'projects/{projectId}/scanConfigs/{scanConfigId}'. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\WebSecurityScanner::initOnce(); + parent::__construct($data); + } + + /** + * Required. The resource name of the ScanConfig to be deleted. The name follows the + * format of 'projects/{projectId}/scanConfigs/{scanConfigId}'. + * + * Generated from protobuf field string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Required. The resource name of the ScanConfig to be deleted. The name follows the + * format of 'projects/{projectId}/scanConfigs/{scanConfigId}'. + * + * Generated from protobuf field string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/Finding.php b/WebSecurityScanner/src/V1/Finding.php new file mode 100644 index 000000000000..c9d0c46bdd6c --- /dev/null +++ b/WebSecurityScanner/src/V1/Finding.php @@ -0,0 +1,764 @@ +google.cloud.websecurityscanner.v1.Finding + */ +class Finding extends \Google\Protobuf\Internal\Message +{ + /** + * Output only. The resource name of the Finding. The name follows the format of + * 'projects/{projectId}/scanConfigs/{scanConfigId}/scanruns/{scanRunId}/findings/{findingId}'. + * The finding IDs are generated by the system. + * + * Generated from protobuf field string name = 1; + */ + private $name = ''; + /** + * Output only. The type of the Finding. + * Detailed and up-to-date information on findings can be found here: + * https://cloud.google.com/security-command-center/docs/how-to-remediate-web-security-scanner-findings + * + * Generated from protobuf field string finding_type = 2; + */ + private $finding_type = ''; + /** + * Output only. The severity level of the reported vulnerability. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.Finding.Severity severity = 17 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + private $severity = 0; + /** + * Output only. The http method of the request that triggered the vulnerability, in + * uppercase. + * + * Generated from protobuf field string http_method = 3; + */ + private $http_method = ''; + /** + * Output only. The URL produced by the server-side fuzzer and used in the request that + * triggered the vulnerability. + * + * Generated from protobuf field string fuzzed_url = 4; + */ + private $fuzzed_url = ''; + /** + * Output only. The body of the request that triggered the vulnerability. + * + * Generated from protobuf field string body = 5; + */ + private $body = ''; + /** + * Output only. The description of the vulnerability. + * + * Generated from protobuf field string description = 6; + */ + private $description = ''; + /** + * Output only. The URL containing human-readable payload that user can leverage to + * reproduce the vulnerability. + * + * Generated from protobuf field string reproduction_url = 7; + */ + private $reproduction_url = ''; + /** + * Output only. If the vulnerability was originated from nested IFrame, the immediate + * parent IFrame is reported. + * + * Generated from protobuf field string frame_url = 8; + */ + private $frame_url = ''; + /** + * Output only. The URL where the browser lands when the vulnerability is detected. + * + * Generated from protobuf field string final_url = 9; + */ + private $final_url = ''; + /** + * Output only. The tracking ID uniquely identifies a vulnerability instance across + * multiple ScanRuns. + * + * Generated from protobuf field string tracking_id = 10; + */ + private $tracking_id = ''; + /** + * Output only. An addon containing information reported for a vulnerability with an HTML + * form, if any. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.Form form = 16; + */ + private $form = null; + /** + * Output only. An addon containing information about outdated libraries. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.OutdatedLibrary outdated_library = 11; + */ + private $outdated_library = null; + /** + * Output only. An addon containing detailed information regarding any resource causing the + * vulnerability such as JavaScript sources, image, audio files, etc. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ViolatingResource violating_resource = 12; + */ + private $violating_resource = null; + /** + * Output only. An addon containing information about vulnerable or missing HTTP headers. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.VulnerableHeaders vulnerable_headers = 15; + */ + private $vulnerable_headers = null; + /** + * Output only. An addon containing information about request parameters which were found + * to be vulnerable. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.VulnerableParameters vulnerable_parameters = 13; + */ + private $vulnerable_parameters = null; + /** + * Output only. An addon containing information reported for an XSS, if any. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.Xss xss = 14; + */ + private $xss = null; + /** + * Output only. An addon containing information reported for an XXE, if any. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.Xxe xxe = 18 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + private $xxe = null; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * Output only. The resource name of the Finding. The name follows the format of + * 'projects/{projectId}/scanConfigs/{scanConfigId}/scanruns/{scanRunId}/findings/{findingId}'. + * The finding IDs are generated by the system. + * @type string $finding_type + * Output only. The type of the Finding. + * Detailed and up-to-date information on findings can be found here: + * https://cloud.google.com/security-command-center/docs/how-to-remediate-web-security-scanner-findings + * @type int $severity + * Output only. The severity level of the reported vulnerability. + * @type string $http_method + * Output only. The http method of the request that triggered the vulnerability, in + * uppercase. + * @type string $fuzzed_url + * Output only. The URL produced by the server-side fuzzer and used in the request that + * triggered the vulnerability. + * @type string $body + * Output only. The body of the request that triggered the vulnerability. + * @type string $description + * Output only. The description of the vulnerability. + * @type string $reproduction_url + * Output only. The URL containing human-readable payload that user can leverage to + * reproduce the vulnerability. + * @type string $frame_url + * Output only. If the vulnerability was originated from nested IFrame, the immediate + * parent IFrame is reported. + * @type string $final_url + * Output only. The URL where the browser lands when the vulnerability is detected. + * @type string $tracking_id + * Output only. The tracking ID uniquely identifies a vulnerability instance across + * multiple ScanRuns. + * @type \Google\Cloud\WebSecurityScanner\V1\Form $form + * Output only. An addon containing information reported for a vulnerability with an HTML + * form, if any. + * @type \Google\Cloud\WebSecurityScanner\V1\OutdatedLibrary $outdated_library + * Output only. An addon containing information about outdated libraries. + * @type \Google\Cloud\WebSecurityScanner\V1\ViolatingResource $violating_resource + * Output only. An addon containing detailed information regarding any resource causing the + * vulnerability such as JavaScript sources, image, audio files, etc. + * @type \Google\Cloud\WebSecurityScanner\V1\VulnerableHeaders $vulnerable_headers + * Output only. An addon containing information about vulnerable or missing HTTP headers. + * @type \Google\Cloud\WebSecurityScanner\V1\VulnerableParameters $vulnerable_parameters + * Output only. An addon containing information about request parameters which were found + * to be vulnerable. + * @type \Google\Cloud\WebSecurityScanner\V1\Xss $xss + * Output only. An addon containing information reported for an XSS, if any. + * @type \Google\Cloud\WebSecurityScanner\V1\Xxe $xxe + * Output only. An addon containing information reported for an XXE, if any. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\Finding::initOnce(); + parent::__construct($data); + } + + /** + * Output only. The resource name of the Finding. The name follows the format of + * 'projects/{projectId}/scanConfigs/{scanConfigId}/scanruns/{scanRunId}/findings/{findingId}'. + * The finding IDs are generated by the system. + * + * Generated from protobuf field string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Output only. The resource name of the Finding. The name follows the format of + * 'projects/{projectId}/scanConfigs/{scanConfigId}/scanruns/{scanRunId}/findings/{findingId}'. + * The finding IDs are generated by the system. + * + * Generated from protobuf field string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * Output only. The type of the Finding. + * Detailed and up-to-date information on findings can be found here: + * https://cloud.google.com/security-command-center/docs/how-to-remediate-web-security-scanner-findings + * + * Generated from protobuf field string finding_type = 2; + * @return string + */ + public function getFindingType() + { + return $this->finding_type; + } + + /** + * Output only. The type of the Finding. + * Detailed and up-to-date information on findings can be found here: + * https://cloud.google.com/security-command-center/docs/how-to-remediate-web-security-scanner-findings + * + * Generated from protobuf field string finding_type = 2; + * @param string $var + * @return $this + */ + public function setFindingType($var) + { + GPBUtil::checkString($var, True); + $this->finding_type = $var; + + return $this; + } + + /** + * Output only. The severity level of the reported vulnerability. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.Finding.Severity severity = 17 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return int + */ + public function getSeverity() + { + return $this->severity; + } + + /** + * Output only. The severity level of the reported vulnerability. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.Finding.Severity severity = 17 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param int $var + * @return $this + */ + public function setSeverity($var) + { + GPBUtil::checkEnum($var, \Google\Cloud\WebSecurityScanner\V1\Finding\Severity::class); + $this->severity = $var; + + return $this; + } + + /** + * Output only. The http method of the request that triggered the vulnerability, in + * uppercase. + * + * Generated from protobuf field string http_method = 3; + * @return string + */ + public function getHttpMethod() + { + return $this->http_method; + } + + /** + * Output only. The http method of the request that triggered the vulnerability, in + * uppercase. + * + * Generated from protobuf field string http_method = 3; + * @param string $var + * @return $this + */ + public function setHttpMethod($var) + { + GPBUtil::checkString($var, True); + $this->http_method = $var; + + return $this; + } + + /** + * Output only. The URL produced by the server-side fuzzer and used in the request that + * triggered the vulnerability. + * + * Generated from protobuf field string fuzzed_url = 4; + * @return string + */ + public function getFuzzedUrl() + { + return $this->fuzzed_url; + } + + /** + * Output only. The URL produced by the server-side fuzzer and used in the request that + * triggered the vulnerability. + * + * Generated from protobuf field string fuzzed_url = 4; + * @param string $var + * @return $this + */ + public function setFuzzedUrl($var) + { + GPBUtil::checkString($var, True); + $this->fuzzed_url = $var; + + return $this; + } + + /** + * Output only. The body of the request that triggered the vulnerability. + * + * Generated from protobuf field string body = 5; + * @return string + */ + public function getBody() + { + return $this->body; + } + + /** + * Output only. The body of the request that triggered the vulnerability. + * + * Generated from protobuf field string body = 5; + * @param string $var + * @return $this + */ + public function setBody($var) + { + GPBUtil::checkString($var, True); + $this->body = $var; + + return $this; + } + + /** + * Output only. The description of the vulnerability. + * + * Generated from protobuf field string description = 6; + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * Output only. The description of the vulnerability. + * + * Generated from protobuf field string description = 6; + * @param string $var + * @return $this + */ + public function setDescription($var) + { + GPBUtil::checkString($var, True); + $this->description = $var; + + return $this; + } + + /** + * Output only. The URL containing human-readable payload that user can leverage to + * reproduce the vulnerability. + * + * Generated from protobuf field string reproduction_url = 7; + * @return string + */ + public function getReproductionUrl() + { + return $this->reproduction_url; + } + + /** + * Output only. The URL containing human-readable payload that user can leverage to + * reproduce the vulnerability. + * + * Generated from protobuf field string reproduction_url = 7; + * @param string $var + * @return $this + */ + public function setReproductionUrl($var) + { + GPBUtil::checkString($var, True); + $this->reproduction_url = $var; + + return $this; + } + + /** + * Output only. If the vulnerability was originated from nested IFrame, the immediate + * parent IFrame is reported. + * + * Generated from protobuf field string frame_url = 8; + * @return string + */ + public function getFrameUrl() + { + return $this->frame_url; + } + + /** + * Output only. If the vulnerability was originated from nested IFrame, the immediate + * parent IFrame is reported. + * + * Generated from protobuf field string frame_url = 8; + * @param string $var + * @return $this + */ + public function setFrameUrl($var) + { + GPBUtil::checkString($var, True); + $this->frame_url = $var; + + return $this; + } + + /** + * Output only. The URL where the browser lands when the vulnerability is detected. + * + * Generated from protobuf field string final_url = 9; + * @return string + */ + public function getFinalUrl() + { + return $this->final_url; + } + + /** + * Output only. The URL where the browser lands when the vulnerability is detected. + * + * Generated from protobuf field string final_url = 9; + * @param string $var + * @return $this + */ + public function setFinalUrl($var) + { + GPBUtil::checkString($var, True); + $this->final_url = $var; + + return $this; + } + + /** + * Output only. The tracking ID uniquely identifies a vulnerability instance across + * multiple ScanRuns. + * + * Generated from protobuf field string tracking_id = 10; + * @return string + */ + public function getTrackingId() + { + return $this->tracking_id; + } + + /** + * Output only. The tracking ID uniquely identifies a vulnerability instance across + * multiple ScanRuns. + * + * Generated from protobuf field string tracking_id = 10; + * @param string $var + * @return $this + */ + public function setTrackingId($var) + { + GPBUtil::checkString($var, True); + $this->tracking_id = $var; + + return $this; + } + + /** + * Output only. An addon containing information reported for a vulnerability with an HTML + * form, if any. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.Form form = 16; + * @return \Google\Cloud\WebSecurityScanner\V1\Form|null + */ + public function getForm() + { + return $this->form; + } + + public function hasForm() + { + return isset($this->form); + } + + public function clearForm() + { + unset($this->form); + } + + /** + * Output only. An addon containing information reported for a vulnerability with an HTML + * form, if any. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.Form form = 16; + * @param \Google\Cloud\WebSecurityScanner\V1\Form $var + * @return $this + */ + public function setForm($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\WebSecurityScanner\V1\Form::class); + $this->form = $var; + + return $this; + } + + /** + * Output only. An addon containing information about outdated libraries. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.OutdatedLibrary outdated_library = 11; + * @return \Google\Cloud\WebSecurityScanner\V1\OutdatedLibrary|null + */ + public function getOutdatedLibrary() + { + return $this->outdated_library; + } + + public function hasOutdatedLibrary() + { + return isset($this->outdated_library); + } + + public function clearOutdatedLibrary() + { + unset($this->outdated_library); + } + + /** + * Output only. An addon containing information about outdated libraries. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.OutdatedLibrary outdated_library = 11; + * @param \Google\Cloud\WebSecurityScanner\V1\OutdatedLibrary $var + * @return $this + */ + public function setOutdatedLibrary($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\WebSecurityScanner\V1\OutdatedLibrary::class); + $this->outdated_library = $var; + + return $this; + } + + /** + * Output only. An addon containing detailed information regarding any resource causing the + * vulnerability such as JavaScript sources, image, audio files, etc. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ViolatingResource violating_resource = 12; + * @return \Google\Cloud\WebSecurityScanner\V1\ViolatingResource|null + */ + public function getViolatingResource() + { + return $this->violating_resource; + } + + public function hasViolatingResource() + { + return isset($this->violating_resource); + } + + public function clearViolatingResource() + { + unset($this->violating_resource); + } + + /** + * Output only. An addon containing detailed information regarding any resource causing the + * vulnerability such as JavaScript sources, image, audio files, etc. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ViolatingResource violating_resource = 12; + * @param \Google\Cloud\WebSecurityScanner\V1\ViolatingResource $var + * @return $this + */ + public function setViolatingResource($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\WebSecurityScanner\V1\ViolatingResource::class); + $this->violating_resource = $var; + + return $this; + } + + /** + * Output only. An addon containing information about vulnerable or missing HTTP headers. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.VulnerableHeaders vulnerable_headers = 15; + * @return \Google\Cloud\WebSecurityScanner\V1\VulnerableHeaders|null + */ + public function getVulnerableHeaders() + { + return $this->vulnerable_headers; + } + + public function hasVulnerableHeaders() + { + return isset($this->vulnerable_headers); + } + + public function clearVulnerableHeaders() + { + unset($this->vulnerable_headers); + } + + /** + * Output only. An addon containing information about vulnerable or missing HTTP headers. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.VulnerableHeaders vulnerable_headers = 15; + * @param \Google\Cloud\WebSecurityScanner\V1\VulnerableHeaders $var + * @return $this + */ + public function setVulnerableHeaders($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\WebSecurityScanner\V1\VulnerableHeaders::class); + $this->vulnerable_headers = $var; + + return $this; + } + + /** + * Output only. An addon containing information about request parameters which were found + * to be vulnerable. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.VulnerableParameters vulnerable_parameters = 13; + * @return \Google\Cloud\WebSecurityScanner\V1\VulnerableParameters|null + */ + public function getVulnerableParameters() + { + return $this->vulnerable_parameters; + } + + public function hasVulnerableParameters() + { + return isset($this->vulnerable_parameters); + } + + public function clearVulnerableParameters() + { + unset($this->vulnerable_parameters); + } + + /** + * Output only. An addon containing information about request parameters which were found + * to be vulnerable. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.VulnerableParameters vulnerable_parameters = 13; + * @param \Google\Cloud\WebSecurityScanner\V1\VulnerableParameters $var + * @return $this + */ + public function setVulnerableParameters($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\WebSecurityScanner\V1\VulnerableParameters::class); + $this->vulnerable_parameters = $var; + + return $this; + } + + /** + * Output only. An addon containing information reported for an XSS, if any. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.Xss xss = 14; + * @return \Google\Cloud\WebSecurityScanner\V1\Xss|null + */ + public function getXss() + { + return $this->xss; + } + + public function hasXss() + { + return isset($this->xss); + } + + public function clearXss() + { + unset($this->xss); + } + + /** + * Output only. An addon containing information reported for an XSS, if any. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.Xss xss = 14; + * @param \Google\Cloud\WebSecurityScanner\V1\Xss $var + * @return $this + */ + public function setXss($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\WebSecurityScanner\V1\Xss::class); + $this->xss = $var; + + return $this; + } + + /** + * Output only. An addon containing information reported for an XXE, if any. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.Xxe xxe = 18 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return \Google\Cloud\WebSecurityScanner\V1\Xxe|null + */ + public function getXxe() + { + return $this->xxe; + } + + public function hasXxe() + { + return isset($this->xxe); + } + + public function clearXxe() + { + unset($this->xxe); + } + + /** + * Output only. An addon containing information reported for an XXE, if any. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.Xxe xxe = 18 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param \Google\Cloud\WebSecurityScanner\V1\Xxe $var + * @return $this + */ + public function setXxe($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\WebSecurityScanner\V1\Xxe::class); + $this->xxe = $var; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/Finding/Severity.php b/WebSecurityScanner/src/V1/Finding/Severity.php new file mode 100644 index 000000000000..1618f553f0d7 --- /dev/null +++ b/WebSecurityScanner/src/V1/Finding/Severity.php @@ -0,0 +1,76 @@ +google.cloud.websecurityscanner.v1.Finding.Severity + */ +class Severity +{ + /** + * No severity specified. The default value. + * + * Generated from protobuf enum SEVERITY_UNSPECIFIED = 0; + */ + const SEVERITY_UNSPECIFIED = 0; + /** + * Critical severity. + * + * Generated from protobuf enum CRITICAL = 1; + */ + const CRITICAL = 1; + /** + * High severity. + * + * Generated from protobuf enum HIGH = 2; + */ + const HIGH = 2; + /** + * Medium severity. + * + * Generated from protobuf enum MEDIUM = 3; + */ + const MEDIUM = 3; + /** + * Low severity. + * + * Generated from protobuf enum LOW = 4; + */ + const LOW = 4; + + private static $valueToName = [ + self::SEVERITY_UNSPECIFIED => 'SEVERITY_UNSPECIFIED', + self::CRITICAL => 'CRITICAL', + self::HIGH => 'HIGH', + self::MEDIUM => 'MEDIUM', + self::LOW => 'LOW', + ]; + + public static function name($value) + { + if (!isset(self::$valueToName[$value])) { + throw new UnexpectedValueException(sprintf( + 'Enum %s has no name defined for value %s', __CLASS__, $value)); + } + return self::$valueToName[$value]; + } + + + public static function value($name) + { + $const = __CLASS__ . '::' . strtoupper($name); + if (!defined($const)) { + throw new UnexpectedValueException(sprintf( + 'Enum %s has no value defined for name %s', __CLASS__, $name)); + } + return constant($const); + } +} + + diff --git a/WebSecurityScanner/src/V1/FindingTypeStats.php b/WebSecurityScanner/src/V1/FindingTypeStats.php new file mode 100644 index 000000000000..18e81a062c50 --- /dev/null +++ b/WebSecurityScanner/src/V1/FindingTypeStats.php @@ -0,0 +1,102 @@ +google.cloud.websecurityscanner.v1.FindingTypeStats + */ +class FindingTypeStats extends \Google\Protobuf\Internal\Message +{ + /** + * Output only. The finding type associated with the stats. + * + * Generated from protobuf field string finding_type = 1; + */ + private $finding_type = ''; + /** + * Output only. The count of findings belonging to this finding type. + * + * Generated from protobuf field int32 finding_count = 2; + */ + private $finding_count = 0; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $finding_type + * Output only. The finding type associated with the stats. + * @type int $finding_count + * Output only. The count of findings belonging to this finding type. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\FindingTypeStats::initOnce(); + parent::__construct($data); + } + + /** + * Output only. The finding type associated with the stats. + * + * Generated from protobuf field string finding_type = 1; + * @return string + */ + public function getFindingType() + { + return $this->finding_type; + } + + /** + * Output only. The finding type associated with the stats. + * + * Generated from protobuf field string finding_type = 1; + * @param string $var + * @return $this + */ + public function setFindingType($var) + { + GPBUtil::checkString($var, True); + $this->finding_type = $var; + + return $this; + } + + /** + * Output only. The count of findings belonging to this finding type. + * + * Generated from protobuf field int32 finding_count = 2; + * @return int + */ + public function getFindingCount() + { + return $this->finding_count; + } + + /** + * Output only. The count of findings belonging to this finding type. + * + * Generated from protobuf field int32 finding_count = 2; + * @param int $var + * @return $this + */ + public function setFindingCount($var) + { + GPBUtil::checkInt32($var); + $this->finding_count = $var; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/Form.php b/WebSecurityScanner/src/V1/Form.php new file mode 100644 index 000000000000..9f1711502a2e --- /dev/null +++ b/WebSecurityScanner/src/V1/Form.php @@ -0,0 +1,101 @@ +google.cloud.websecurityscanner.v1.Form + */ +class Form extends \Google\Protobuf\Internal\Message +{ + /** + * ! The URI where to send the form when it's submitted. + * + * Generated from protobuf field string action_uri = 1; + */ + private $action_uri = ''; + /** + * ! The names of form fields related to the vulnerability. + * + * Generated from protobuf field repeated string fields = 2; + */ + private $fields; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $action_uri + * ! The URI where to send the form when it's submitted. + * @type array|\Google\Protobuf\Internal\RepeatedField $fields + * ! The names of form fields related to the vulnerability. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\FindingAddon::initOnce(); + parent::__construct($data); + } + + /** + * ! The URI where to send the form when it's submitted. + * + * Generated from protobuf field string action_uri = 1; + * @return string + */ + public function getActionUri() + { + return $this->action_uri; + } + + /** + * ! The URI where to send the form when it's submitted. + * + * Generated from protobuf field string action_uri = 1; + * @param string $var + * @return $this + */ + public function setActionUri($var) + { + GPBUtil::checkString($var, True); + $this->action_uri = $var; + + return $this; + } + + /** + * ! The names of form fields related to the vulnerability. + * + * Generated from protobuf field repeated string fields = 2; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getFields() + { + return $this->fields; + } + + /** + * ! The names of form fields related to the vulnerability. + * + * Generated from protobuf field repeated string fields = 2; + * @param array|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setFields($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING); + $this->fields = $arr; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/GetFindingRequest.php b/WebSecurityScanner/src/V1/GetFindingRequest.php new file mode 100644 index 000000000000..74716b561f83 --- /dev/null +++ b/WebSecurityScanner/src/V1/GetFindingRequest.php @@ -0,0 +1,75 @@ +google.cloud.websecurityscanner.v1.GetFindingRequest + */ +class GetFindingRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The resource name of the Finding to be returned. The name follows the + * format of + * 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}/findings/{findingId}'. + * + * Generated from protobuf field string name = 1; + */ + private $name = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * Required. The resource name of the Finding to be returned. The name follows the + * format of + * 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}/findings/{findingId}'. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\WebSecurityScanner::initOnce(); + parent::__construct($data); + } + + /** + * Required. The resource name of the Finding to be returned. The name follows the + * format of + * 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}/findings/{findingId}'. + * + * Generated from protobuf field string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Required. The resource name of the Finding to be returned. The name follows the + * format of + * 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}/findings/{findingId}'. + * + * Generated from protobuf field string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/GetScanConfigRequest.php b/WebSecurityScanner/src/V1/GetScanConfigRequest.php new file mode 100644 index 000000000000..994c1d2d73ae --- /dev/null +++ b/WebSecurityScanner/src/V1/GetScanConfigRequest.php @@ -0,0 +1,71 @@ +google.cloud.websecurityscanner.v1.GetScanConfigRequest + */ +class GetScanConfigRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The resource name of the ScanConfig to be returned. The name follows the + * format of 'projects/{projectId}/scanConfigs/{scanConfigId}'. + * + * Generated from protobuf field string name = 1; + */ + private $name = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * Required. The resource name of the ScanConfig to be returned. The name follows the + * format of 'projects/{projectId}/scanConfigs/{scanConfigId}'. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\WebSecurityScanner::initOnce(); + parent::__construct($data); + } + + /** + * Required. The resource name of the ScanConfig to be returned. The name follows the + * format of 'projects/{projectId}/scanConfigs/{scanConfigId}'. + * + * Generated from protobuf field string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Required. The resource name of the ScanConfig to be returned. The name follows the + * format of 'projects/{projectId}/scanConfigs/{scanConfigId}'. + * + * Generated from protobuf field string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/GetScanRunRequest.php b/WebSecurityScanner/src/V1/GetScanRunRequest.php new file mode 100644 index 000000000000..6fe198582180 --- /dev/null +++ b/WebSecurityScanner/src/V1/GetScanRunRequest.php @@ -0,0 +1,75 @@ +google.cloud.websecurityscanner.v1.GetScanRunRequest + */ +class GetScanRunRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The resource name of the ScanRun to be returned. The name follows the + * format of + * 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. + * + * Generated from protobuf field string name = 1; + */ + private $name = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * Required. The resource name of the ScanRun to be returned. The name follows the + * format of + * 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\WebSecurityScanner::initOnce(); + parent::__construct($data); + } + + /** + * Required. The resource name of the ScanRun to be returned. The name follows the + * format of + * 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. + * + * Generated from protobuf field string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Required. The resource name of the ScanRun to be returned. The name follows the + * format of + * 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. + * + * Generated from protobuf field string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/ListCrawledUrlsRequest.php b/WebSecurityScanner/src/V1/ListCrawledUrlsRequest.php new file mode 100644 index 000000000000..b9fcb855a282 --- /dev/null +++ b/WebSecurityScanner/src/V1/ListCrawledUrlsRequest.php @@ -0,0 +1,159 @@ +google.cloud.websecurityscanner.v1.ListCrawledUrlsRequest + */ +class ListCrawledUrlsRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The parent resource name, which should be a scan run resource name in the + * format + * 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. + * + * Generated from protobuf field string parent = 1; + */ + private $parent = ''; + /** + * A token identifying a page of results to be returned. This should be a + * `next_page_token` value returned from a previous List request. + * If unspecified, the first page of results is returned. + * + * Generated from protobuf field string page_token = 2; + */ + private $page_token = ''; + /** + * The maximum number of CrawledUrls to return, can be limited by server. + * If not specified or not positive, the implementation will select a + * reasonable value. + * + * Generated from protobuf field int32 page_size = 3; + */ + private $page_size = 0; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $parent + * Required. The parent resource name, which should be a scan run resource name in the + * format + * 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. + * @type string $page_token + * A token identifying a page of results to be returned. This should be a + * `next_page_token` value returned from a previous List request. + * If unspecified, the first page of results is returned. + * @type int $page_size + * The maximum number of CrawledUrls to return, can be limited by server. + * If not specified or not positive, the implementation will select a + * reasonable value. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\WebSecurityScanner::initOnce(); + parent::__construct($data); + } + + /** + * Required. The parent resource name, which should be a scan run resource name in the + * format + * 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. + * + * Generated from protobuf field string parent = 1; + * @return string + */ + public function getParent() + { + return $this->parent; + } + + /** + * Required. The parent resource name, which should be a scan run resource name in the + * format + * 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. + * + * Generated from protobuf field string parent = 1; + * @param string $var + * @return $this + */ + public function setParent($var) + { + GPBUtil::checkString($var, True); + $this->parent = $var; + + return $this; + } + + /** + * A token identifying a page of results to be returned. This should be a + * `next_page_token` value returned from a previous List request. + * If unspecified, the first page of results is returned. + * + * Generated from protobuf field string page_token = 2; + * @return string + */ + public function getPageToken() + { + return $this->page_token; + } + + /** + * A token identifying a page of results to be returned. This should be a + * `next_page_token` value returned from a previous List request. + * If unspecified, the first page of results is returned. + * + * Generated from protobuf field string page_token = 2; + * @param string $var + * @return $this + */ + public function setPageToken($var) + { + GPBUtil::checkString($var, True); + $this->page_token = $var; + + return $this; + } + + /** + * The maximum number of CrawledUrls to return, can be limited by server. + * If not specified or not positive, the implementation will select a + * reasonable value. + * + * Generated from protobuf field int32 page_size = 3; + * @return int + */ + public function getPageSize() + { + return $this->page_size; + } + + /** + * The maximum number of CrawledUrls to return, can be limited by server. + * If not specified or not positive, the implementation will select a + * reasonable value. + * + * Generated from protobuf field int32 page_size = 3; + * @param int $var + * @return $this + */ + public function setPageSize($var) + { + GPBUtil::checkInt32($var); + $this->page_size = $var; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/ListCrawledUrlsResponse.php b/WebSecurityScanner/src/V1/ListCrawledUrlsResponse.php new file mode 100644 index 000000000000..334c23bc2075 --- /dev/null +++ b/WebSecurityScanner/src/V1/ListCrawledUrlsResponse.php @@ -0,0 +1,105 @@ +google.cloud.websecurityscanner.v1.ListCrawledUrlsResponse + */ +class ListCrawledUrlsResponse extends \Google\Protobuf\Internal\Message +{ + /** + * The list of CrawledUrls returned. + * + * Generated from protobuf field repeated .google.cloud.websecurityscanner.v1.CrawledUrl crawled_urls = 1; + */ + private $crawled_urls; + /** + * Token to retrieve the next page of results, or empty if there are no + * more results in the list. + * + * Generated from protobuf field string next_page_token = 2; + */ + private $next_page_token = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type array<\Google\Cloud\WebSecurityScanner\V1\CrawledUrl>|\Google\Protobuf\Internal\RepeatedField $crawled_urls + * The list of CrawledUrls returned. + * @type string $next_page_token + * Token to retrieve the next page of results, or empty if there are no + * more results in the list. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\WebSecurityScanner::initOnce(); + parent::__construct($data); + } + + /** + * The list of CrawledUrls returned. + * + * Generated from protobuf field repeated .google.cloud.websecurityscanner.v1.CrawledUrl crawled_urls = 1; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getCrawledUrls() + { + return $this->crawled_urls; + } + + /** + * The list of CrawledUrls returned. + * + * Generated from protobuf field repeated .google.cloud.websecurityscanner.v1.CrawledUrl crawled_urls = 1; + * @param array<\Google\Cloud\WebSecurityScanner\V1\CrawledUrl>|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setCrawledUrls($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\WebSecurityScanner\V1\CrawledUrl::class); + $this->crawled_urls = $arr; + + return $this; + } + + /** + * Token to retrieve the next page of results, or empty if there are no + * more results in the list. + * + * Generated from protobuf field string next_page_token = 2; + * @return string + */ + public function getNextPageToken() + { + return $this->next_page_token; + } + + /** + * Token to retrieve the next page of results, or empty if there are no + * more results in the list. + * + * Generated from protobuf field string next_page_token = 2; + * @param string $var + * @return $this + */ + public function setNextPageToken($var) + { + GPBUtil::checkString($var, True); + $this->next_page_token = $var; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/ListFindingTypeStatsRequest.php b/WebSecurityScanner/src/V1/ListFindingTypeStatsRequest.php new file mode 100644 index 000000000000..b5a85a275f4c --- /dev/null +++ b/WebSecurityScanner/src/V1/ListFindingTypeStatsRequest.php @@ -0,0 +1,75 @@ +google.cloud.websecurityscanner.v1.ListFindingTypeStatsRequest + */ +class ListFindingTypeStatsRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The parent resource name, which should be a scan run resource name in the + * format + * 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. + * + * Generated from protobuf field string parent = 1; + */ + private $parent = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $parent + * Required. The parent resource name, which should be a scan run resource name in the + * format + * 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\WebSecurityScanner::initOnce(); + parent::__construct($data); + } + + /** + * Required. The parent resource name, which should be a scan run resource name in the + * format + * 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. + * + * Generated from protobuf field string parent = 1; + * @return string + */ + public function getParent() + { + return $this->parent; + } + + /** + * Required. The parent resource name, which should be a scan run resource name in the + * format + * 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. + * + * Generated from protobuf field string parent = 1; + * @param string $var + * @return $this + */ + public function setParent($var) + { + GPBUtil::checkString($var, True); + $this->parent = $var; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/ListFindingTypeStatsResponse.php b/WebSecurityScanner/src/V1/ListFindingTypeStatsResponse.php new file mode 100644 index 000000000000..68c1c6ea8191 --- /dev/null +++ b/WebSecurityScanner/src/V1/ListFindingTypeStatsResponse.php @@ -0,0 +1,67 @@ +google.cloud.websecurityscanner.v1.ListFindingTypeStatsResponse + */ +class ListFindingTypeStatsResponse extends \Google\Protobuf\Internal\Message +{ + /** + * The list of FindingTypeStats returned. + * + * Generated from protobuf field repeated .google.cloud.websecurityscanner.v1.FindingTypeStats finding_type_stats = 1; + */ + private $finding_type_stats; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type array<\Google\Cloud\WebSecurityScanner\V1\FindingTypeStats>|\Google\Protobuf\Internal\RepeatedField $finding_type_stats + * The list of FindingTypeStats returned. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\WebSecurityScanner::initOnce(); + parent::__construct($data); + } + + /** + * The list of FindingTypeStats returned. + * + * Generated from protobuf field repeated .google.cloud.websecurityscanner.v1.FindingTypeStats finding_type_stats = 1; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getFindingTypeStats() + { + return $this->finding_type_stats; + } + + /** + * The list of FindingTypeStats returned. + * + * Generated from protobuf field repeated .google.cloud.websecurityscanner.v1.FindingTypeStats finding_type_stats = 1; + * @param array<\Google\Cloud\WebSecurityScanner\V1\FindingTypeStats>|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setFindingTypeStats($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\WebSecurityScanner\V1\FindingTypeStats::class); + $this->finding_type_stats = $arr; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/ListFindingsRequest.php b/WebSecurityScanner/src/V1/ListFindingsRequest.php new file mode 100644 index 000000000000..6da53e2b0844 --- /dev/null +++ b/WebSecurityScanner/src/V1/ListFindingsRequest.php @@ -0,0 +1,205 @@ +google.cloud.websecurityscanner.v1.ListFindingsRequest + */ +class ListFindingsRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The parent resource name, which should be a scan run resource name in the + * format + * 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. + * + * Generated from protobuf field string parent = 1; + */ + private $parent = ''; + /** + * The filter expression. The expression must be in the format: + * . + * Supported field: 'finding_type'. + * Supported operator: '='. + * + * Generated from protobuf field string filter = 2; + */ + private $filter = ''; + /** + * A token identifying a page of results to be returned. This should be a + * `next_page_token` value returned from a previous List request. + * If unspecified, the first page of results is returned. + * + * Generated from protobuf field string page_token = 3; + */ + private $page_token = ''; + /** + * The maximum number of Findings to return, can be limited by server. + * If not specified or not positive, the implementation will select a + * reasonable value. + * + * Generated from protobuf field int32 page_size = 4; + */ + private $page_size = 0; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $parent + * Required. The parent resource name, which should be a scan run resource name in the + * format + * 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. + * @type string $filter + * The filter expression. The expression must be in the format: + * . + * Supported field: 'finding_type'. + * Supported operator: '='. + * @type string $page_token + * A token identifying a page of results to be returned. This should be a + * `next_page_token` value returned from a previous List request. + * If unspecified, the first page of results is returned. + * @type int $page_size + * The maximum number of Findings to return, can be limited by server. + * If not specified or not positive, the implementation will select a + * reasonable value. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\WebSecurityScanner::initOnce(); + parent::__construct($data); + } + + /** + * Required. The parent resource name, which should be a scan run resource name in the + * format + * 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. + * + * Generated from protobuf field string parent = 1; + * @return string + */ + public function getParent() + { + return $this->parent; + } + + /** + * Required. The parent resource name, which should be a scan run resource name in the + * format + * 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. + * + * Generated from protobuf field string parent = 1; + * @param string $var + * @return $this + */ + public function setParent($var) + { + GPBUtil::checkString($var, True); + $this->parent = $var; + + return $this; + } + + /** + * The filter expression. The expression must be in the format: + * . + * Supported field: 'finding_type'. + * Supported operator: '='. + * + * Generated from protobuf field string filter = 2; + * @return string + */ + public function getFilter() + { + return $this->filter; + } + + /** + * The filter expression. The expression must be in the format: + * . + * Supported field: 'finding_type'. + * Supported operator: '='. + * + * Generated from protobuf field string filter = 2; + * @param string $var + * @return $this + */ + public function setFilter($var) + { + GPBUtil::checkString($var, True); + $this->filter = $var; + + return $this; + } + + /** + * A token identifying a page of results to be returned. This should be a + * `next_page_token` value returned from a previous List request. + * If unspecified, the first page of results is returned. + * + * Generated from protobuf field string page_token = 3; + * @return string + */ + public function getPageToken() + { + return $this->page_token; + } + + /** + * A token identifying a page of results to be returned. This should be a + * `next_page_token` value returned from a previous List request. + * If unspecified, the first page of results is returned. + * + * Generated from protobuf field string page_token = 3; + * @param string $var + * @return $this + */ + public function setPageToken($var) + { + GPBUtil::checkString($var, True); + $this->page_token = $var; + + return $this; + } + + /** + * The maximum number of Findings to return, can be limited by server. + * If not specified or not positive, the implementation will select a + * reasonable value. + * + * Generated from protobuf field int32 page_size = 4; + * @return int + */ + public function getPageSize() + { + return $this->page_size; + } + + /** + * The maximum number of Findings to return, can be limited by server. + * If not specified or not positive, the implementation will select a + * reasonable value. + * + * Generated from protobuf field int32 page_size = 4; + * @param int $var + * @return $this + */ + public function setPageSize($var) + { + GPBUtil::checkInt32($var); + $this->page_size = $var; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/ListFindingsResponse.php b/WebSecurityScanner/src/V1/ListFindingsResponse.php new file mode 100644 index 000000000000..651fc29b6b1d --- /dev/null +++ b/WebSecurityScanner/src/V1/ListFindingsResponse.php @@ -0,0 +1,105 @@ +google.cloud.websecurityscanner.v1.ListFindingsResponse + */ +class ListFindingsResponse extends \Google\Protobuf\Internal\Message +{ + /** + * The list of Findings returned. + * + * Generated from protobuf field repeated .google.cloud.websecurityscanner.v1.Finding findings = 1; + */ + private $findings; + /** + * Token to retrieve the next page of results, or empty if there are no + * more results in the list. + * + * Generated from protobuf field string next_page_token = 2; + */ + private $next_page_token = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type array<\Google\Cloud\WebSecurityScanner\V1\Finding>|\Google\Protobuf\Internal\RepeatedField $findings + * The list of Findings returned. + * @type string $next_page_token + * Token to retrieve the next page of results, or empty if there are no + * more results in the list. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\WebSecurityScanner::initOnce(); + parent::__construct($data); + } + + /** + * The list of Findings returned. + * + * Generated from protobuf field repeated .google.cloud.websecurityscanner.v1.Finding findings = 1; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getFindings() + { + return $this->findings; + } + + /** + * The list of Findings returned. + * + * Generated from protobuf field repeated .google.cloud.websecurityscanner.v1.Finding findings = 1; + * @param array<\Google\Cloud\WebSecurityScanner\V1\Finding>|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setFindings($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\WebSecurityScanner\V1\Finding::class); + $this->findings = $arr; + + return $this; + } + + /** + * Token to retrieve the next page of results, or empty if there are no + * more results in the list. + * + * Generated from protobuf field string next_page_token = 2; + * @return string + */ + public function getNextPageToken() + { + return $this->next_page_token; + } + + /** + * Token to retrieve the next page of results, or empty if there are no + * more results in the list. + * + * Generated from protobuf field string next_page_token = 2; + * @param string $var + * @return $this + */ + public function setNextPageToken($var) + { + GPBUtil::checkString($var, True); + $this->next_page_token = $var; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/ListScanConfigsRequest.php b/WebSecurityScanner/src/V1/ListScanConfigsRequest.php new file mode 100644 index 000000000000..966bce32086f --- /dev/null +++ b/WebSecurityScanner/src/V1/ListScanConfigsRequest.php @@ -0,0 +1,155 @@ +google.cloud.websecurityscanner.v1.ListScanConfigsRequest + */ +class ListScanConfigsRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The parent resource name, which should be a project resource name in the + * format 'projects/{projectId}'. + * + * Generated from protobuf field string parent = 1; + */ + private $parent = ''; + /** + * A token identifying a page of results to be returned. This should be a + * `next_page_token` value returned from a previous List request. + * If unspecified, the first page of results is returned. + * + * Generated from protobuf field string page_token = 2; + */ + private $page_token = ''; + /** + * The maximum number of ScanConfigs to return, can be limited by server. + * If not specified or not positive, the implementation will select a + * reasonable value. + * + * Generated from protobuf field int32 page_size = 3; + */ + private $page_size = 0; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $parent + * Required. The parent resource name, which should be a project resource name in the + * format 'projects/{projectId}'. + * @type string $page_token + * A token identifying a page of results to be returned. This should be a + * `next_page_token` value returned from a previous List request. + * If unspecified, the first page of results is returned. + * @type int $page_size + * The maximum number of ScanConfigs to return, can be limited by server. + * If not specified or not positive, the implementation will select a + * reasonable value. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\WebSecurityScanner::initOnce(); + parent::__construct($data); + } + + /** + * Required. The parent resource name, which should be a project resource name in the + * format 'projects/{projectId}'. + * + * Generated from protobuf field string parent = 1; + * @return string + */ + public function getParent() + { + return $this->parent; + } + + /** + * Required. The parent resource name, which should be a project resource name in the + * format 'projects/{projectId}'. + * + * Generated from protobuf field string parent = 1; + * @param string $var + * @return $this + */ + public function setParent($var) + { + GPBUtil::checkString($var, True); + $this->parent = $var; + + return $this; + } + + /** + * A token identifying a page of results to be returned. This should be a + * `next_page_token` value returned from a previous List request. + * If unspecified, the first page of results is returned. + * + * Generated from protobuf field string page_token = 2; + * @return string + */ + public function getPageToken() + { + return $this->page_token; + } + + /** + * A token identifying a page of results to be returned. This should be a + * `next_page_token` value returned from a previous List request. + * If unspecified, the first page of results is returned. + * + * Generated from protobuf field string page_token = 2; + * @param string $var + * @return $this + */ + public function setPageToken($var) + { + GPBUtil::checkString($var, True); + $this->page_token = $var; + + return $this; + } + + /** + * The maximum number of ScanConfigs to return, can be limited by server. + * If not specified or not positive, the implementation will select a + * reasonable value. + * + * Generated from protobuf field int32 page_size = 3; + * @return int + */ + public function getPageSize() + { + return $this->page_size; + } + + /** + * The maximum number of ScanConfigs to return, can be limited by server. + * If not specified or not positive, the implementation will select a + * reasonable value. + * + * Generated from protobuf field int32 page_size = 3; + * @param int $var + * @return $this + */ + public function setPageSize($var) + { + GPBUtil::checkInt32($var); + $this->page_size = $var; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/ListScanConfigsResponse.php b/WebSecurityScanner/src/V1/ListScanConfigsResponse.php new file mode 100644 index 000000000000..e035a6058910 --- /dev/null +++ b/WebSecurityScanner/src/V1/ListScanConfigsResponse.php @@ -0,0 +1,105 @@ +google.cloud.websecurityscanner.v1.ListScanConfigsResponse + */ +class ListScanConfigsResponse extends \Google\Protobuf\Internal\Message +{ + /** + * The list of ScanConfigs returned. + * + * Generated from protobuf field repeated .google.cloud.websecurityscanner.v1.ScanConfig scan_configs = 1; + */ + private $scan_configs; + /** + * Token to retrieve the next page of results, or empty if there are no + * more results in the list. + * + * Generated from protobuf field string next_page_token = 2; + */ + private $next_page_token = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type array<\Google\Cloud\WebSecurityScanner\V1\ScanConfig>|\Google\Protobuf\Internal\RepeatedField $scan_configs + * The list of ScanConfigs returned. + * @type string $next_page_token + * Token to retrieve the next page of results, or empty if there are no + * more results in the list. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\WebSecurityScanner::initOnce(); + parent::__construct($data); + } + + /** + * The list of ScanConfigs returned. + * + * Generated from protobuf field repeated .google.cloud.websecurityscanner.v1.ScanConfig scan_configs = 1; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getScanConfigs() + { + return $this->scan_configs; + } + + /** + * The list of ScanConfigs returned. + * + * Generated from protobuf field repeated .google.cloud.websecurityscanner.v1.ScanConfig scan_configs = 1; + * @param array<\Google\Cloud\WebSecurityScanner\V1\ScanConfig>|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setScanConfigs($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\WebSecurityScanner\V1\ScanConfig::class); + $this->scan_configs = $arr; + + return $this; + } + + /** + * Token to retrieve the next page of results, or empty if there are no + * more results in the list. + * + * Generated from protobuf field string next_page_token = 2; + * @return string + */ + public function getNextPageToken() + { + return $this->next_page_token; + } + + /** + * Token to retrieve the next page of results, or empty if there are no + * more results in the list. + * + * Generated from protobuf field string next_page_token = 2; + * @param string $var + * @return $this + */ + public function setNextPageToken($var) + { + GPBUtil::checkString($var, True); + $this->next_page_token = $var; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/ListScanRunsRequest.php b/WebSecurityScanner/src/V1/ListScanRunsRequest.php new file mode 100644 index 000000000000..9f6f1296801f --- /dev/null +++ b/WebSecurityScanner/src/V1/ListScanRunsRequest.php @@ -0,0 +1,155 @@ +google.cloud.websecurityscanner.v1.ListScanRunsRequest + */ +class ListScanRunsRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The parent resource name, which should be a scan resource name in the + * format 'projects/{projectId}/scanConfigs/{scanConfigId}'. + * + * Generated from protobuf field string parent = 1; + */ + private $parent = ''; + /** + * A token identifying a page of results to be returned. This should be a + * `next_page_token` value returned from a previous List request. + * If unspecified, the first page of results is returned. + * + * Generated from protobuf field string page_token = 2; + */ + private $page_token = ''; + /** + * The maximum number of ScanRuns to return, can be limited by server. + * If not specified or not positive, the implementation will select a + * reasonable value. + * + * Generated from protobuf field int32 page_size = 3; + */ + private $page_size = 0; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $parent + * Required. The parent resource name, which should be a scan resource name in the + * format 'projects/{projectId}/scanConfigs/{scanConfigId}'. + * @type string $page_token + * A token identifying a page of results to be returned. This should be a + * `next_page_token` value returned from a previous List request. + * If unspecified, the first page of results is returned. + * @type int $page_size + * The maximum number of ScanRuns to return, can be limited by server. + * If not specified or not positive, the implementation will select a + * reasonable value. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\WebSecurityScanner::initOnce(); + parent::__construct($data); + } + + /** + * Required. The parent resource name, which should be a scan resource name in the + * format 'projects/{projectId}/scanConfigs/{scanConfigId}'. + * + * Generated from protobuf field string parent = 1; + * @return string + */ + public function getParent() + { + return $this->parent; + } + + /** + * Required. The parent resource name, which should be a scan resource name in the + * format 'projects/{projectId}/scanConfigs/{scanConfigId}'. + * + * Generated from protobuf field string parent = 1; + * @param string $var + * @return $this + */ + public function setParent($var) + { + GPBUtil::checkString($var, True); + $this->parent = $var; + + return $this; + } + + /** + * A token identifying a page of results to be returned. This should be a + * `next_page_token` value returned from a previous List request. + * If unspecified, the first page of results is returned. + * + * Generated from protobuf field string page_token = 2; + * @return string + */ + public function getPageToken() + { + return $this->page_token; + } + + /** + * A token identifying a page of results to be returned. This should be a + * `next_page_token` value returned from a previous List request. + * If unspecified, the first page of results is returned. + * + * Generated from protobuf field string page_token = 2; + * @param string $var + * @return $this + */ + public function setPageToken($var) + { + GPBUtil::checkString($var, True); + $this->page_token = $var; + + return $this; + } + + /** + * The maximum number of ScanRuns to return, can be limited by server. + * If not specified or not positive, the implementation will select a + * reasonable value. + * + * Generated from protobuf field int32 page_size = 3; + * @return int + */ + public function getPageSize() + { + return $this->page_size; + } + + /** + * The maximum number of ScanRuns to return, can be limited by server. + * If not specified or not positive, the implementation will select a + * reasonable value. + * + * Generated from protobuf field int32 page_size = 3; + * @param int $var + * @return $this + */ + public function setPageSize($var) + { + GPBUtil::checkInt32($var); + $this->page_size = $var; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/ListScanRunsResponse.php b/WebSecurityScanner/src/V1/ListScanRunsResponse.php new file mode 100644 index 000000000000..a83a4bfa935c --- /dev/null +++ b/WebSecurityScanner/src/V1/ListScanRunsResponse.php @@ -0,0 +1,105 @@ +google.cloud.websecurityscanner.v1.ListScanRunsResponse + */ +class ListScanRunsResponse extends \Google\Protobuf\Internal\Message +{ + /** + * The list of ScanRuns returned. + * + * Generated from protobuf field repeated .google.cloud.websecurityscanner.v1.ScanRun scan_runs = 1; + */ + private $scan_runs; + /** + * Token to retrieve the next page of results, or empty if there are no + * more results in the list. + * + * Generated from protobuf field string next_page_token = 2; + */ + private $next_page_token = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type array<\Google\Cloud\WebSecurityScanner\V1\ScanRun>|\Google\Protobuf\Internal\RepeatedField $scan_runs + * The list of ScanRuns returned. + * @type string $next_page_token + * Token to retrieve the next page of results, or empty if there are no + * more results in the list. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\WebSecurityScanner::initOnce(); + parent::__construct($data); + } + + /** + * The list of ScanRuns returned. + * + * Generated from protobuf field repeated .google.cloud.websecurityscanner.v1.ScanRun scan_runs = 1; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getScanRuns() + { + return $this->scan_runs; + } + + /** + * The list of ScanRuns returned. + * + * Generated from protobuf field repeated .google.cloud.websecurityscanner.v1.ScanRun scan_runs = 1; + * @param array<\Google\Cloud\WebSecurityScanner\V1\ScanRun>|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setScanRuns($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\WebSecurityScanner\V1\ScanRun::class); + $this->scan_runs = $arr; + + return $this; + } + + /** + * Token to retrieve the next page of results, or empty if there are no + * more results in the list. + * + * Generated from protobuf field string next_page_token = 2; + * @return string + */ + public function getNextPageToken() + { + return $this->next_page_token; + } + + /** + * Token to retrieve the next page of results, or empty if there are no + * more results in the list. + * + * Generated from protobuf field string next_page_token = 2; + * @param string $var + * @return $this + */ + public function setNextPageToken($var) + { + GPBUtil::checkString($var, True); + $this->next_page_token = $var; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/OutdatedLibrary.php b/WebSecurityScanner/src/V1/OutdatedLibrary.php new file mode 100644 index 000000000000..a72216c0f3d9 --- /dev/null +++ b/WebSecurityScanner/src/V1/OutdatedLibrary.php @@ -0,0 +1,135 @@ +google.cloud.websecurityscanner.v1.OutdatedLibrary + */ +class OutdatedLibrary extends \Google\Protobuf\Internal\Message +{ + /** + * The name of the outdated library. + * + * Generated from protobuf field string library_name = 1; + */ + private $library_name = ''; + /** + * The version number. + * + * Generated from protobuf field string version = 2; + */ + private $version = ''; + /** + * URLs to learn more information about the vulnerabilities in the library. + * + * Generated from protobuf field repeated string learn_more_urls = 3; + */ + private $learn_more_urls; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $library_name + * The name of the outdated library. + * @type string $version + * The version number. + * @type array|\Google\Protobuf\Internal\RepeatedField $learn_more_urls + * URLs to learn more information about the vulnerabilities in the library. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\FindingAddon::initOnce(); + parent::__construct($data); + } + + /** + * The name of the outdated library. + * + * Generated from protobuf field string library_name = 1; + * @return string + */ + public function getLibraryName() + { + return $this->library_name; + } + + /** + * The name of the outdated library. + * + * Generated from protobuf field string library_name = 1; + * @param string $var + * @return $this + */ + public function setLibraryName($var) + { + GPBUtil::checkString($var, True); + $this->library_name = $var; + + return $this; + } + + /** + * The version number. + * + * Generated from protobuf field string version = 2; + * @return string + */ + public function getVersion() + { + return $this->version; + } + + /** + * The version number. + * + * Generated from protobuf field string version = 2; + * @param string $var + * @return $this + */ + public function setVersion($var) + { + GPBUtil::checkString($var, True); + $this->version = $var; + + return $this; + } + + /** + * URLs to learn more information about the vulnerabilities in the library. + * + * Generated from protobuf field repeated string learn_more_urls = 3; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getLearnMoreUrls() + { + return $this->learn_more_urls; + } + + /** + * URLs to learn more information about the vulnerabilities in the library. + * + * Generated from protobuf field repeated string learn_more_urls = 3; + * @param array|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setLearnMoreUrls($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING); + $this->learn_more_urls = $arr; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/ScanConfig.php b/WebSecurityScanner/src/V1/ScanConfig.php new file mode 100644 index 000000000000..fc94ed8b5598 --- /dev/null +++ b/WebSecurityScanner/src/V1/ScanConfig.php @@ -0,0 +1,535 @@ +google.cloud.websecurityscanner.v1.ScanConfig + */ +class ScanConfig extends \Google\Protobuf\Internal\Message +{ + /** + * The resource name of the ScanConfig. The name follows the format of + * 'projects/{projectId}/scanConfigs/{scanConfigId}'. The ScanConfig IDs are + * generated by the system. + * + * Generated from protobuf field string name = 1; + */ + private $name = ''; + /** + * Required. The user provided display name of the ScanConfig. + * + * Generated from protobuf field string display_name = 2; + */ + private $display_name = ''; + /** + * The maximum QPS during scanning. A valid value ranges from 5 to 20 + * inclusively. If the field is unspecified or its value is set 0, server will + * default to 15. Other values outside of [5, 20] range will be rejected with + * INVALID_ARGUMENT error. + * + * Generated from protobuf field int32 max_qps = 3; + */ + private $max_qps = 0; + /** + * Required. The starting URLs from which the scanner finds site pages. + * + * Generated from protobuf field repeated string starting_urls = 4; + */ + private $starting_urls; + /** + * The authentication configuration. If specified, service will use the + * authentication configuration during scanning. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfig.Authentication authentication = 5; + */ + private $authentication = null; + /** + * The user agent used during scanning. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfig.UserAgent user_agent = 6; + */ + private $user_agent = 0; + /** + * The excluded URL patterns as described in + * https://cloud.google.com/security-command-center/docs/how-to-use-web-security-scanner#excluding_urls + * + * Generated from protobuf field repeated string blacklist_patterns = 7; + */ + private $blacklist_patterns; + /** + * The schedule of the ScanConfig. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfig.Schedule schedule = 8; + */ + private $schedule = null; + /** + * Controls export of scan configurations and results to Security + * Command Center. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfig.ExportToSecurityCommandCenter export_to_security_command_center = 10; + */ + private $export_to_security_command_center = 0; + /** + * The risk level selected for the scan + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfig.RiskLevel risk_level = 12; + */ + private $risk_level = 0; + /** + * Whether the scan config is managed by Web Security Scanner, output + * only. + * + * Generated from protobuf field bool managed_scan = 13; + */ + private $managed_scan = false; + /** + * Whether the scan configuration has enabled static IP address scan feature. + * If enabled, the scanner will access applications from static IP addresses. + * + * Generated from protobuf field bool static_ip_scan = 14; + */ + private $static_ip_scan = false; + /** + * Whether to keep scanning even if most requests return HTTP error codes. + * + * Generated from protobuf field bool ignore_http_status_errors = 15; + */ + private $ignore_http_status_errors = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * The resource name of the ScanConfig. The name follows the format of + * 'projects/{projectId}/scanConfigs/{scanConfigId}'. The ScanConfig IDs are + * generated by the system. + * @type string $display_name + * Required. The user provided display name of the ScanConfig. + * @type int $max_qps + * The maximum QPS during scanning. A valid value ranges from 5 to 20 + * inclusively. If the field is unspecified or its value is set 0, server will + * default to 15. Other values outside of [5, 20] range will be rejected with + * INVALID_ARGUMENT error. + * @type array|\Google\Protobuf\Internal\RepeatedField $starting_urls + * Required. The starting URLs from which the scanner finds site pages. + * @type \Google\Cloud\WebSecurityScanner\V1\ScanConfig\Authentication $authentication + * The authentication configuration. If specified, service will use the + * authentication configuration during scanning. + * @type int $user_agent + * The user agent used during scanning. + * @type array|\Google\Protobuf\Internal\RepeatedField $blacklist_patterns + * The excluded URL patterns as described in + * https://cloud.google.com/security-command-center/docs/how-to-use-web-security-scanner#excluding_urls + * @type \Google\Cloud\WebSecurityScanner\V1\ScanConfig\Schedule $schedule + * The schedule of the ScanConfig. + * @type int $export_to_security_command_center + * Controls export of scan configurations and results to Security + * Command Center. + * @type int $risk_level + * The risk level selected for the scan + * @type bool $managed_scan + * Whether the scan config is managed by Web Security Scanner, output + * only. + * @type bool $static_ip_scan + * Whether the scan configuration has enabled static IP address scan feature. + * If enabled, the scanner will access applications from static IP addresses. + * @type bool $ignore_http_status_errors + * Whether to keep scanning even if most requests return HTTP error codes. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\ScanConfig::initOnce(); + parent::__construct($data); + } + + /** + * The resource name of the ScanConfig. The name follows the format of + * 'projects/{projectId}/scanConfigs/{scanConfigId}'. The ScanConfig IDs are + * generated by the system. + * + * Generated from protobuf field string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * The resource name of the ScanConfig. The name follows the format of + * 'projects/{projectId}/scanConfigs/{scanConfigId}'. The ScanConfig IDs are + * generated by the system. + * + * Generated from protobuf field string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * Required. The user provided display name of the ScanConfig. + * + * Generated from protobuf field string display_name = 2; + * @return string + */ + public function getDisplayName() + { + return $this->display_name; + } + + /** + * Required. The user provided display name of the ScanConfig. + * + * Generated from protobuf field string display_name = 2; + * @param string $var + * @return $this + */ + public function setDisplayName($var) + { + GPBUtil::checkString($var, True); + $this->display_name = $var; + + return $this; + } + + /** + * The maximum QPS during scanning. A valid value ranges from 5 to 20 + * inclusively. If the field is unspecified or its value is set 0, server will + * default to 15. Other values outside of [5, 20] range will be rejected with + * INVALID_ARGUMENT error. + * + * Generated from protobuf field int32 max_qps = 3; + * @return int + */ + public function getMaxQps() + { + return $this->max_qps; + } + + /** + * The maximum QPS during scanning. A valid value ranges from 5 to 20 + * inclusively. If the field is unspecified or its value is set 0, server will + * default to 15. Other values outside of [5, 20] range will be rejected with + * INVALID_ARGUMENT error. + * + * Generated from protobuf field int32 max_qps = 3; + * @param int $var + * @return $this + */ + public function setMaxQps($var) + { + GPBUtil::checkInt32($var); + $this->max_qps = $var; + + return $this; + } + + /** + * Required. The starting URLs from which the scanner finds site pages. + * + * Generated from protobuf field repeated string starting_urls = 4; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getStartingUrls() + { + return $this->starting_urls; + } + + /** + * Required. The starting URLs from which the scanner finds site pages. + * + * Generated from protobuf field repeated string starting_urls = 4; + * @param array|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setStartingUrls($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING); + $this->starting_urls = $arr; + + return $this; + } + + /** + * The authentication configuration. If specified, service will use the + * authentication configuration during scanning. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfig.Authentication authentication = 5; + * @return \Google\Cloud\WebSecurityScanner\V1\ScanConfig\Authentication|null + */ + public function getAuthentication() + { + return $this->authentication; + } + + public function hasAuthentication() + { + return isset($this->authentication); + } + + public function clearAuthentication() + { + unset($this->authentication); + } + + /** + * The authentication configuration. If specified, service will use the + * authentication configuration during scanning. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfig.Authentication authentication = 5; + * @param \Google\Cloud\WebSecurityScanner\V1\ScanConfig\Authentication $var + * @return $this + */ + public function setAuthentication($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\WebSecurityScanner\V1\ScanConfig\Authentication::class); + $this->authentication = $var; + + return $this; + } + + /** + * The user agent used during scanning. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfig.UserAgent user_agent = 6; + * @return int + */ + public function getUserAgent() + { + return $this->user_agent; + } + + /** + * The user agent used during scanning. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfig.UserAgent user_agent = 6; + * @param int $var + * @return $this + */ + public function setUserAgent($var) + { + GPBUtil::checkEnum($var, \Google\Cloud\WebSecurityScanner\V1\ScanConfig\UserAgent::class); + $this->user_agent = $var; + + return $this; + } + + /** + * The excluded URL patterns as described in + * https://cloud.google.com/security-command-center/docs/how-to-use-web-security-scanner#excluding_urls + * + * Generated from protobuf field repeated string blacklist_patterns = 7; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getBlacklistPatterns() + { + return $this->blacklist_patterns; + } + + /** + * The excluded URL patterns as described in + * https://cloud.google.com/security-command-center/docs/how-to-use-web-security-scanner#excluding_urls + * + * Generated from protobuf field repeated string blacklist_patterns = 7; + * @param array|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setBlacklistPatterns($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING); + $this->blacklist_patterns = $arr; + + return $this; + } + + /** + * The schedule of the ScanConfig. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfig.Schedule schedule = 8; + * @return \Google\Cloud\WebSecurityScanner\V1\ScanConfig\Schedule|null + */ + public function getSchedule() + { + return $this->schedule; + } + + public function hasSchedule() + { + return isset($this->schedule); + } + + public function clearSchedule() + { + unset($this->schedule); + } + + /** + * The schedule of the ScanConfig. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfig.Schedule schedule = 8; + * @param \Google\Cloud\WebSecurityScanner\V1\ScanConfig\Schedule $var + * @return $this + */ + public function setSchedule($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\WebSecurityScanner\V1\ScanConfig\Schedule::class); + $this->schedule = $var; + + return $this; + } + + /** + * Controls export of scan configurations and results to Security + * Command Center. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfig.ExportToSecurityCommandCenter export_to_security_command_center = 10; + * @return int + */ + public function getExportToSecurityCommandCenter() + { + return $this->export_to_security_command_center; + } + + /** + * Controls export of scan configurations and results to Security + * Command Center. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfig.ExportToSecurityCommandCenter export_to_security_command_center = 10; + * @param int $var + * @return $this + */ + public function setExportToSecurityCommandCenter($var) + { + GPBUtil::checkEnum($var, \Google\Cloud\WebSecurityScanner\V1\ScanConfig\ExportToSecurityCommandCenter::class); + $this->export_to_security_command_center = $var; + + return $this; + } + + /** + * The risk level selected for the scan + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfig.RiskLevel risk_level = 12; + * @return int + */ + public function getRiskLevel() + { + return $this->risk_level; + } + + /** + * The risk level selected for the scan + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfig.RiskLevel risk_level = 12; + * @param int $var + * @return $this + */ + public function setRiskLevel($var) + { + GPBUtil::checkEnum($var, \Google\Cloud\WebSecurityScanner\V1\ScanConfig\RiskLevel::class); + $this->risk_level = $var; + + return $this; + } + + /** + * Whether the scan config is managed by Web Security Scanner, output + * only. + * + * Generated from protobuf field bool managed_scan = 13; + * @return bool + */ + public function getManagedScan() + { + return $this->managed_scan; + } + + /** + * Whether the scan config is managed by Web Security Scanner, output + * only. + * + * Generated from protobuf field bool managed_scan = 13; + * @param bool $var + * @return $this + */ + public function setManagedScan($var) + { + GPBUtil::checkBool($var); + $this->managed_scan = $var; + + return $this; + } + + /** + * Whether the scan configuration has enabled static IP address scan feature. + * If enabled, the scanner will access applications from static IP addresses. + * + * Generated from protobuf field bool static_ip_scan = 14; + * @return bool + */ + public function getStaticIpScan() + { + return $this->static_ip_scan; + } + + /** + * Whether the scan configuration has enabled static IP address scan feature. + * If enabled, the scanner will access applications from static IP addresses. + * + * Generated from protobuf field bool static_ip_scan = 14; + * @param bool $var + * @return $this + */ + public function setStaticIpScan($var) + { + GPBUtil::checkBool($var); + $this->static_ip_scan = $var; + + return $this; + } + + /** + * Whether to keep scanning even if most requests return HTTP error codes. + * + * Generated from protobuf field bool ignore_http_status_errors = 15; + * @return bool + */ + public function getIgnoreHttpStatusErrors() + { + return $this->ignore_http_status_errors; + } + + /** + * Whether to keep scanning even if most requests return HTTP error codes. + * + * Generated from protobuf field bool ignore_http_status_errors = 15; + * @param bool $var + * @return $this + */ + public function setIgnoreHttpStatusErrors($var) + { + GPBUtil::checkBool($var); + $this->ignore_http_status_errors = $var; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/ScanConfig/Authentication.php b/WebSecurityScanner/src/V1/ScanConfig/Authentication.php new file mode 100644 index 000000000000..ffbe744d721b --- /dev/null +++ b/WebSecurityScanner/src/V1/ScanConfig/Authentication.php @@ -0,0 +1,147 @@ +google.cloud.websecurityscanner.v1.ScanConfig.Authentication + */ +class Authentication extends \Google\Protobuf\Internal\Message +{ + protected $authentication; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Google\Cloud\WebSecurityScanner\V1\ScanConfig\Authentication\GoogleAccount $google_account + * Authentication using a Google account. + * @type \Google\Cloud\WebSecurityScanner\V1\ScanConfig\Authentication\CustomAccount $custom_account + * Authentication using a custom account. + * @type \Google\Cloud\WebSecurityScanner\V1\ScanConfig\Authentication\IapCredential $iap_credential + * Authentication using Identity-Aware-Proxy (IAP). + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\ScanConfig::initOnce(); + parent::__construct($data); + } + + /** + * Authentication using a Google account. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfig.Authentication.GoogleAccount google_account = 1 [deprecated = true]; + * @return \Google\Cloud\WebSecurityScanner\V1\ScanConfig\Authentication\GoogleAccount|null + * @deprecated + */ + public function getGoogleAccount() + { + @trigger_error('google_account is deprecated.', E_USER_DEPRECATED); + return $this->readOneof(1); + } + + public function hasGoogleAccount() + { + @trigger_error('google_account is deprecated.', E_USER_DEPRECATED); + return $this->hasOneof(1); + } + + /** + * Authentication using a Google account. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfig.Authentication.GoogleAccount google_account = 1 [deprecated = true]; + * @param \Google\Cloud\WebSecurityScanner\V1\ScanConfig\Authentication\GoogleAccount $var + * @return $this + * @deprecated + */ + public function setGoogleAccount($var) + { + @trigger_error('google_account is deprecated.', E_USER_DEPRECATED); + GPBUtil::checkMessage($var, \Google\Cloud\WebSecurityScanner\V1\ScanConfig\Authentication\GoogleAccount::class); + $this->writeOneof(1, $var); + + return $this; + } + + /** + * Authentication using a custom account. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfig.Authentication.CustomAccount custom_account = 2; + * @return \Google\Cloud\WebSecurityScanner\V1\ScanConfig\Authentication\CustomAccount|null + */ + public function getCustomAccount() + { + return $this->readOneof(2); + } + + public function hasCustomAccount() + { + return $this->hasOneof(2); + } + + /** + * Authentication using a custom account. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfig.Authentication.CustomAccount custom_account = 2; + * @param \Google\Cloud\WebSecurityScanner\V1\ScanConfig\Authentication\CustomAccount $var + * @return $this + */ + public function setCustomAccount($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\WebSecurityScanner\V1\ScanConfig\Authentication\CustomAccount::class); + $this->writeOneof(2, $var); + + return $this; + } + + /** + * Authentication using Identity-Aware-Proxy (IAP). + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfig.Authentication.IapCredential iap_credential = 4; + * @return \Google\Cloud\WebSecurityScanner\V1\ScanConfig\Authentication\IapCredential|null + */ + public function getIapCredential() + { + return $this->readOneof(4); + } + + public function hasIapCredential() + { + return $this->hasOneof(4); + } + + /** + * Authentication using Identity-Aware-Proxy (IAP). + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfig.Authentication.IapCredential iap_credential = 4; + * @param \Google\Cloud\WebSecurityScanner\V1\ScanConfig\Authentication\IapCredential $var + * @return $this + */ + public function setIapCredential($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\WebSecurityScanner\V1\ScanConfig\Authentication\IapCredential::class); + $this->writeOneof(4, $var); + + return $this; + } + + /** + * @return string + */ + public function getAuthentication() + { + return $this->whichOneof("authentication"); + } + +} + + diff --git a/WebSecurityScanner/src/V1/ScanConfig/Authentication/CustomAccount.php b/WebSecurityScanner/src/V1/ScanConfig/Authentication/CustomAccount.php new file mode 100644 index 000000000000..782e701aab4b --- /dev/null +++ b/WebSecurityScanner/src/V1/ScanConfig/Authentication/CustomAccount.php @@ -0,0 +1,140 @@ +google.cloud.websecurityscanner.v1.ScanConfig.Authentication.CustomAccount + */ +class CustomAccount extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The user name of the custom account. + * + * Generated from protobuf field string username = 1; + */ + private $username = ''; + /** + * Required. Input only. The password of the custom account. The credential is stored encrypted + * and not returned in any response nor included in audit logs. + * + * Generated from protobuf field string password = 2; + */ + private $password = ''; + /** + * Required. The login form URL of the website. + * + * Generated from protobuf field string login_url = 3; + */ + private $login_url = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $username + * Required. The user name of the custom account. + * @type string $password + * Required. Input only. The password of the custom account. The credential is stored encrypted + * and not returned in any response nor included in audit logs. + * @type string $login_url + * Required. The login form URL of the website. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\ScanConfig::initOnce(); + parent::__construct($data); + } + + /** + * Required. The user name of the custom account. + * + * Generated from protobuf field string username = 1; + * @return string + */ + public function getUsername() + { + return $this->username; + } + + /** + * Required. The user name of the custom account. + * + * Generated from protobuf field string username = 1; + * @param string $var + * @return $this + */ + public function setUsername($var) + { + GPBUtil::checkString($var, True); + $this->username = $var; + + return $this; + } + + /** + * Required. Input only. The password of the custom account. The credential is stored encrypted + * and not returned in any response nor included in audit logs. + * + * Generated from protobuf field string password = 2; + * @return string + */ + public function getPassword() + { + return $this->password; + } + + /** + * Required. Input only. The password of the custom account. The credential is stored encrypted + * and not returned in any response nor included in audit logs. + * + * Generated from protobuf field string password = 2; + * @param string $var + * @return $this + */ + public function setPassword($var) + { + GPBUtil::checkString($var, True); + $this->password = $var; + + return $this; + } + + /** + * Required. The login form URL of the website. + * + * Generated from protobuf field string login_url = 3; + * @return string + */ + public function getLoginUrl() + { + return $this->login_url; + } + + /** + * Required. The login form URL of the website. + * + * Generated from protobuf field string login_url = 3; + * @param string $var + * @return $this + */ + public function setLoginUrl($var) + { + GPBUtil::checkString($var, True); + $this->login_url = $var; + + return $this; + } + +} + + diff --git a/WebSecurityScanner/src/V1/ScanConfig/Authentication/GoogleAccount.php b/WebSecurityScanner/src/V1/ScanConfig/Authentication/GoogleAccount.php new file mode 100644 index 000000000000..ccd596347fc5 --- /dev/null +++ b/WebSecurityScanner/src/V1/ScanConfig/Authentication/GoogleAccount.php @@ -0,0 +1,107 @@ +google.cloud.websecurityscanner.v1.ScanConfig.Authentication.GoogleAccount + */ +class GoogleAccount extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The user name of the Google account. + * + * Generated from protobuf field string username = 1; + */ + private $username = ''; + /** + * Required. Input only. The password of the Google account. The credential is stored encrypted + * and not returned in any response nor included in audit logs. + * + * Generated from protobuf field string password = 2; + */ + private $password = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $username + * Required. The user name of the Google account. + * @type string $password + * Required. Input only. The password of the Google account. The credential is stored encrypted + * and not returned in any response nor included in audit logs. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\ScanConfig::initOnce(); + parent::__construct($data); + } + + /** + * Required. The user name of the Google account. + * + * Generated from protobuf field string username = 1; + * @return string + */ + public function getUsername() + { + return $this->username; + } + + /** + * Required. The user name of the Google account. + * + * Generated from protobuf field string username = 1; + * @param string $var + * @return $this + */ + public function setUsername($var) + { + GPBUtil::checkString($var, True); + $this->username = $var; + + return $this; + } + + /** + * Required. Input only. The password of the Google account. The credential is stored encrypted + * and not returned in any response nor included in audit logs. + * + * Generated from protobuf field string password = 2; + * @return string + */ + public function getPassword() + { + return $this->password; + } + + /** + * Required. Input only. The password of the Google account. The credential is stored encrypted + * and not returned in any response nor included in audit logs. + * + * Generated from protobuf field string password = 2; + * @param string $var + * @return $this + */ + public function setPassword($var) + { + GPBUtil::checkString($var, True); + $this->password = $var; + + return $this; + } + +} + + diff --git a/WebSecurityScanner/src/V1/ScanConfig/Authentication/IapCredential.php b/WebSecurityScanner/src/V1/ScanConfig/Authentication/IapCredential.php new file mode 100644 index 000000000000..50e44888f681 --- /dev/null +++ b/WebSecurityScanner/src/V1/ScanConfig/Authentication/IapCredential.php @@ -0,0 +1,79 @@ +google.cloud.websecurityscanner.v1.ScanConfig.Authentication.IapCredential + */ +class IapCredential extends \Google\Protobuf\Internal\Message +{ + protected $iap_credentials; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Google\Cloud\WebSecurityScanner\V1\ScanConfig\Authentication\IapCredential\IapTestServiceAccountInfo $iap_test_service_account_info + * Authentication configuration when Web-Security-Scanner service + * account is added in Identity-Aware-Proxy (IAP) access policies. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\ScanConfig::initOnce(); + parent::__construct($data); + } + + /** + * Authentication configuration when Web-Security-Scanner service + * account is added in Identity-Aware-Proxy (IAP) access policies. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfig.Authentication.IapCredential.IapTestServiceAccountInfo iap_test_service_account_info = 1; + * @return \Google\Cloud\WebSecurityScanner\V1\ScanConfig\Authentication\IapCredential\IapTestServiceAccountInfo|null + */ + public function getIapTestServiceAccountInfo() + { + return $this->readOneof(1); + } + + public function hasIapTestServiceAccountInfo() + { + return $this->hasOneof(1); + } + + /** + * Authentication configuration when Web-Security-Scanner service + * account is added in Identity-Aware-Proxy (IAP) access policies. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfig.Authentication.IapCredential.IapTestServiceAccountInfo iap_test_service_account_info = 1; + * @param \Google\Cloud\WebSecurityScanner\V1\ScanConfig\Authentication\IapCredential\IapTestServiceAccountInfo $var + * @return $this + */ + public function setIapTestServiceAccountInfo($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\WebSecurityScanner\V1\ScanConfig\Authentication\IapCredential\IapTestServiceAccountInfo::class); + $this->writeOneof(1, $var); + + return $this; + } + + /** + * @return string + */ + public function getIapCredentials() + { + return $this->whichOneof("iap_credentials"); + } + +} + + diff --git a/WebSecurityScanner/src/V1/ScanConfig/Authentication/IapCredential/IapTestServiceAccountInfo.php b/WebSecurityScanner/src/V1/ScanConfig/Authentication/IapCredential/IapTestServiceAccountInfo.php new file mode 100644 index 000000000000..e163c40d8bed --- /dev/null +++ b/WebSecurityScanner/src/V1/ScanConfig/Authentication/IapCredential/IapTestServiceAccountInfo.php @@ -0,0 +1,73 @@ +google.cloud.websecurityscanner.v1.ScanConfig.Authentication.IapCredential.IapTestServiceAccountInfo + */ +class IapTestServiceAccountInfo extends \Google\Protobuf\Internal\Message +{ + /** + * Required. Describes OAuth2 client id of resources protected by + * Identity-Aware-Proxy (IAP). + * + * Generated from protobuf field string target_audience_client_id = 1 [(.google.api.field_behavior) = REQUIRED]; + */ + private $target_audience_client_id = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $target_audience_client_id + * Required. Describes OAuth2 client id of resources protected by + * Identity-Aware-Proxy (IAP). + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\ScanConfig::initOnce(); + parent::__construct($data); + } + + /** + * Required. Describes OAuth2 client id of resources protected by + * Identity-Aware-Proxy (IAP). + * + * Generated from protobuf field string target_audience_client_id = 1 [(.google.api.field_behavior) = REQUIRED]; + * @return string + */ + public function getTargetAudienceClientId() + { + return $this->target_audience_client_id; + } + + /** + * Required. Describes OAuth2 client id of resources protected by + * Identity-Aware-Proxy (IAP). + * + * Generated from protobuf field string target_audience_client_id = 1 [(.google.api.field_behavior) = REQUIRED]; + * @param string $var + * @return $this + */ + public function setTargetAudienceClientId($var) + { + GPBUtil::checkString($var, True); + $this->target_audience_client_id = $var; + + return $this; + } + +} + + diff --git a/WebSecurityScanner/src/V1/ScanConfig/ExportToSecurityCommandCenter.php b/WebSecurityScanner/src/V1/ScanConfig/ExportToSecurityCommandCenter.php new file mode 100644 index 000000000000..143af05d323c --- /dev/null +++ b/WebSecurityScanner/src/V1/ScanConfig/ExportToSecurityCommandCenter.php @@ -0,0 +1,63 @@ +google.cloud.websecurityscanner.v1.ScanConfig.ExportToSecurityCommandCenter + */ +class ExportToSecurityCommandCenter +{ + /** + * Use default, which is ENABLED. + * + * Generated from protobuf enum EXPORT_TO_SECURITY_COMMAND_CENTER_UNSPECIFIED = 0; + */ + const EXPORT_TO_SECURITY_COMMAND_CENTER_UNSPECIFIED = 0; + /** + * Export results of this scan to Security Command Center. + * + * Generated from protobuf enum ENABLED = 1; + */ + const ENABLED = 1; + /** + * Do not export results of this scan to Security Command Center. + * + * Generated from protobuf enum DISABLED = 2; + */ + const DISABLED = 2; + + private static $valueToName = [ + self::EXPORT_TO_SECURITY_COMMAND_CENTER_UNSPECIFIED => 'EXPORT_TO_SECURITY_COMMAND_CENTER_UNSPECIFIED', + self::ENABLED => 'ENABLED', + self::DISABLED => 'DISABLED', + ]; + + public static function name($value) + { + if (!isset(self::$valueToName[$value])) { + throw new UnexpectedValueException(sprintf( + 'Enum %s has no name defined for value %s', __CLASS__, $value)); + } + return self::$valueToName[$value]; + } + + + public static function value($name) + { + $const = __CLASS__ . '::' . strtoupper($name); + if (!defined($const)) { + throw new UnexpectedValueException(sprintf( + 'Enum %s has no value defined for name %s', __CLASS__, $name)); + } + return constant($const); + } +} + + diff --git a/WebSecurityScanner/src/V1/ScanConfig/RiskLevel.php b/WebSecurityScanner/src/V1/ScanConfig/RiskLevel.php new file mode 100644 index 000000000000..647ec223879e --- /dev/null +++ b/WebSecurityScanner/src/V1/ScanConfig/RiskLevel.php @@ -0,0 +1,64 @@ +google.cloud.websecurityscanner.v1.ScanConfig.RiskLevel + */ +class RiskLevel +{ + /** + * Use default, which is NORMAL. + * + * Generated from protobuf enum RISK_LEVEL_UNSPECIFIED = 0; + */ + const RISK_LEVEL_UNSPECIFIED = 0; + /** + * Normal scanning (Recommended) + * + * Generated from protobuf enum NORMAL = 1; + */ + const NORMAL = 1; + /** + * Lower impact scanning + * + * Generated from protobuf enum LOW = 2; + */ + const LOW = 2; + + private static $valueToName = [ + self::RISK_LEVEL_UNSPECIFIED => 'RISK_LEVEL_UNSPECIFIED', + self::NORMAL => 'NORMAL', + self::LOW => 'LOW', + ]; + + public static function name($value) + { + if (!isset(self::$valueToName[$value])) { + throw new UnexpectedValueException(sprintf( + 'Enum %s has no name defined for value %s', __CLASS__, $value)); + } + return self::$valueToName[$value]; + } + + + public static function value($name) + { + $const = __CLASS__ . '::' . strtoupper($name); + if (!defined($const)) { + throw new UnexpectedValueException(sprintf( + 'Enum %s has no value defined for name %s', __CLASS__, $name)); + } + return constant($const); + } +} + + diff --git a/WebSecurityScanner/src/V1/ScanConfig/Schedule.php b/WebSecurityScanner/src/V1/ScanConfig/Schedule.php new file mode 100644 index 000000000000..c4e9e30154f0 --- /dev/null +++ b/WebSecurityScanner/src/V1/ScanConfig/Schedule.php @@ -0,0 +1,124 @@ +google.cloud.websecurityscanner.v1.ScanConfig.Schedule + */ +class Schedule extends \Google\Protobuf\Internal\Message +{ + /** + * A timestamp indicates when the next run will be scheduled. The value is + * refreshed by the server after each run. If unspecified, it will default + * to current server time, which means the scan will be scheduled to start + * immediately. + * + * Generated from protobuf field .google.protobuf.Timestamp schedule_time = 1; + */ + private $schedule_time = null; + /** + * Required. The duration of time between executions in days. + * + * Generated from protobuf field int32 interval_duration_days = 2; + */ + private $interval_duration_days = 0; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Google\Protobuf\Timestamp $schedule_time + * A timestamp indicates when the next run will be scheduled. The value is + * refreshed by the server after each run. If unspecified, it will default + * to current server time, which means the scan will be scheduled to start + * immediately. + * @type int $interval_duration_days + * Required. The duration of time between executions in days. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\ScanConfig::initOnce(); + parent::__construct($data); + } + + /** + * A timestamp indicates when the next run will be scheduled. The value is + * refreshed by the server after each run. If unspecified, it will default + * to current server time, which means the scan will be scheduled to start + * immediately. + * + * Generated from protobuf field .google.protobuf.Timestamp schedule_time = 1; + * @return \Google\Protobuf\Timestamp|null + */ + public function getScheduleTime() + { + return $this->schedule_time; + } + + public function hasScheduleTime() + { + return isset($this->schedule_time); + } + + public function clearScheduleTime() + { + unset($this->schedule_time); + } + + /** + * A timestamp indicates when the next run will be scheduled. The value is + * refreshed by the server after each run. If unspecified, it will default + * to current server time, which means the scan will be scheduled to start + * immediately. + * + * Generated from protobuf field .google.protobuf.Timestamp schedule_time = 1; + * @param \Google\Protobuf\Timestamp $var + * @return $this + */ + public function setScheduleTime($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Timestamp::class); + $this->schedule_time = $var; + + return $this; + } + + /** + * Required. The duration of time between executions in days. + * + * Generated from protobuf field int32 interval_duration_days = 2; + * @return int + */ + public function getIntervalDurationDays() + { + return $this->interval_duration_days; + } + + /** + * Required. The duration of time between executions in days. + * + * Generated from protobuf field int32 interval_duration_days = 2; + * @param int $var + * @return $this + */ + public function setIntervalDurationDays($var) + { + GPBUtil::checkInt32($var); + $this->interval_duration_days = $var; + + return $this; + } + +} + + diff --git a/WebSecurityScanner/src/V1/ScanConfig/UserAgent.php b/WebSecurityScanner/src/V1/ScanConfig/UserAgent.php new file mode 100644 index 000000000000..ebd1811c79dc --- /dev/null +++ b/WebSecurityScanner/src/V1/ScanConfig/UserAgent.php @@ -0,0 +1,69 @@ +google.cloud.websecurityscanner.v1.ScanConfig.UserAgent + */ +class UserAgent +{ + /** + * The user agent is unknown. Service will default to CHROME_LINUX. + * + * Generated from protobuf enum USER_AGENT_UNSPECIFIED = 0; + */ + const USER_AGENT_UNSPECIFIED = 0; + /** + * Chrome on Linux. This is the service default if unspecified. + * + * Generated from protobuf enum CHROME_LINUX = 1; + */ + const CHROME_LINUX = 1; + /** + * Chrome on Android. + * + * Generated from protobuf enum CHROME_ANDROID = 2; + */ + const CHROME_ANDROID = 2; + /** + * Safari on IPhone. + * + * Generated from protobuf enum SAFARI_IPHONE = 3; + */ + const SAFARI_IPHONE = 3; + + private static $valueToName = [ + self::USER_AGENT_UNSPECIFIED => 'USER_AGENT_UNSPECIFIED', + self::CHROME_LINUX => 'CHROME_LINUX', + self::CHROME_ANDROID => 'CHROME_ANDROID', + self::SAFARI_IPHONE => 'SAFARI_IPHONE', + ]; + + public static function name($value) + { + if (!isset(self::$valueToName[$value])) { + throw new UnexpectedValueException(sprintf( + 'Enum %s has no name defined for value %s', __CLASS__, $value)); + } + return self::$valueToName[$value]; + } + + + public static function value($name) + { + $const = __CLASS__ . '::' . strtoupper($name); + if (!defined($const)) { + throw new UnexpectedValueException(sprintf( + 'Enum %s has no value defined for name %s', __CLASS__, $name)); + } + return constant($const); + } +} + + diff --git a/WebSecurityScanner/src/V1/ScanConfigError.php b/WebSecurityScanner/src/V1/ScanConfigError.php new file mode 100644 index 000000000000..9d0dac61611a --- /dev/null +++ b/WebSecurityScanner/src/V1/ScanConfigError.php @@ -0,0 +1,116 @@ +google.cloud.websecurityscanner.v1.ScanConfigError + */ +class ScanConfigError extends \Google\Protobuf\Internal\Message +{ + /** + * Output only. Indicates the reason code for a configuration failure. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfigError.Code code = 1; + */ + private $code = 0; + /** + * Output only. Indicates the full name of the ScanConfig field that triggers this error, + * for example "scan_config.max_qps". This field is provided for + * troubleshooting purposes only and its actual value can change in the + * future. + * + * Generated from protobuf field string field_name = 2; + */ + private $field_name = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type int $code + * Output only. Indicates the reason code for a configuration failure. + * @type string $field_name + * Output only. Indicates the full name of the ScanConfig field that triggers this error, + * for example "scan_config.max_qps". This field is provided for + * troubleshooting purposes only and its actual value can change in the + * future. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\ScanConfigError::initOnce(); + parent::__construct($data); + } + + /** + * Output only. Indicates the reason code for a configuration failure. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfigError.Code code = 1; + * @return int + */ + public function getCode() + { + return $this->code; + } + + /** + * Output only. Indicates the reason code for a configuration failure. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfigError.Code code = 1; + * @param int $var + * @return $this + */ + public function setCode($var) + { + GPBUtil::checkEnum($var, \Google\Cloud\WebSecurityScanner\V1\ScanConfigError\Code::class); + $this->code = $var; + + return $this; + } + + /** + * Output only. Indicates the full name of the ScanConfig field that triggers this error, + * for example "scan_config.max_qps". This field is provided for + * troubleshooting purposes only and its actual value can change in the + * future. + * + * Generated from protobuf field string field_name = 2; + * @return string + */ + public function getFieldName() + { + return $this->field_name; + } + + /** + * Output only. Indicates the full name of the ScanConfig field that triggers this error, + * for example "scan_config.max_qps". This field is provided for + * troubleshooting purposes only and its actual value can change in the + * future. + * + * Generated from protobuf field string field_name = 2; + * @param string $var + * @return $this + */ + public function setFieldName($var) + { + GPBUtil::checkString($var, True); + $this->field_name = $var; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/ScanConfigError/Code.php b/WebSecurityScanner/src/V1/ScanConfigError/Code.php new file mode 100644 index 000000000000..49b87a6951ab --- /dev/null +++ b/WebSecurityScanner/src/V1/ScanConfigError/Code.php @@ -0,0 +1,353 @@ +google.cloud.websecurityscanner.v1.ScanConfigError.Code + */ +class Code +{ + /** + * There is no error. + * + * Generated from protobuf enum CODE_UNSPECIFIED = 0; + */ + const CODE_UNSPECIFIED = 0; + /** + * There is no error. + * + * Generated from protobuf enum OK = 0; + */ + const OK = 0; + /** + * Indicates an internal server error. + * Please DO NOT USE THIS ERROR CODE unless the root cause is truly unknown. + * + * Generated from protobuf enum INTERNAL_ERROR = 1; + */ + const INTERNAL_ERROR = 1; + /** + * One of the seed URLs is an App Engine URL but we cannot validate the scan + * settings due to an App Engine API backend error. + * + * Generated from protobuf enum APPENGINE_API_BACKEND_ERROR = 2; + */ + const APPENGINE_API_BACKEND_ERROR = 2; + /** + * One of the seed URLs is an App Engine URL but we cannot access the + * App Engine API to validate scan settings. + * + * Generated from protobuf enum APPENGINE_API_NOT_ACCESSIBLE = 3; + */ + const APPENGINE_API_NOT_ACCESSIBLE = 3; + /** + * One of the seed URLs is an App Engine URL but the Default Host of the + * App Engine is not set. + * + * Generated from protobuf enum APPENGINE_DEFAULT_HOST_MISSING = 4; + */ + const APPENGINE_DEFAULT_HOST_MISSING = 4; + /** + * Google corporate accounts can not be used for scanning. + * + * Generated from protobuf enum CANNOT_USE_GOOGLE_COM_ACCOUNT = 6; + */ + const CANNOT_USE_GOOGLE_COM_ACCOUNT = 6; + /** + * The account of the scan creator can not be used for scanning. + * + * Generated from protobuf enum CANNOT_USE_OWNER_ACCOUNT = 7; + */ + const CANNOT_USE_OWNER_ACCOUNT = 7; + /** + * This scan targets Compute Engine, but we cannot validate scan settings + * due to a Compute Engine API backend error. + * + * Generated from protobuf enum COMPUTE_API_BACKEND_ERROR = 8; + */ + const COMPUTE_API_BACKEND_ERROR = 8; + /** + * This scan targets Compute Engine, but we cannot access the Compute Engine + * API to validate the scan settings. + * + * Generated from protobuf enum COMPUTE_API_NOT_ACCESSIBLE = 9; + */ + const COMPUTE_API_NOT_ACCESSIBLE = 9; + /** + * The Custom Login URL does not belong to the current project. + * + * Generated from protobuf enum CUSTOM_LOGIN_URL_DOES_NOT_BELONG_TO_CURRENT_PROJECT = 10; + */ + const CUSTOM_LOGIN_URL_DOES_NOT_BELONG_TO_CURRENT_PROJECT = 10; + /** + * The Custom Login URL is malformed (can not be parsed). + * + * Generated from protobuf enum CUSTOM_LOGIN_URL_MALFORMED = 11; + */ + const CUSTOM_LOGIN_URL_MALFORMED = 11; + /** + * The Custom Login URL is mapped to a non-routable IP address in DNS. + * + * Generated from protobuf enum CUSTOM_LOGIN_URL_MAPPED_TO_NON_ROUTABLE_ADDRESS = 12; + */ + const CUSTOM_LOGIN_URL_MAPPED_TO_NON_ROUTABLE_ADDRESS = 12; + /** + * The Custom Login URL is mapped to an IP address which is not reserved for + * the current project. + * + * Generated from protobuf enum CUSTOM_LOGIN_URL_MAPPED_TO_UNRESERVED_ADDRESS = 13; + */ + const CUSTOM_LOGIN_URL_MAPPED_TO_UNRESERVED_ADDRESS = 13; + /** + * The Custom Login URL has a non-routable IP address. + * + * Generated from protobuf enum CUSTOM_LOGIN_URL_HAS_NON_ROUTABLE_IP_ADDRESS = 14; + */ + const CUSTOM_LOGIN_URL_HAS_NON_ROUTABLE_IP_ADDRESS = 14; + /** + * The Custom Login URL has an IP address which is not reserved for the + * current project. + * + * Generated from protobuf enum CUSTOM_LOGIN_URL_HAS_UNRESERVED_IP_ADDRESS = 15; + */ + const CUSTOM_LOGIN_URL_HAS_UNRESERVED_IP_ADDRESS = 15; + /** + * Another scan with the same name (case-sensitive) already exists. + * + * Generated from protobuf enum DUPLICATE_SCAN_NAME = 16; + */ + const DUPLICATE_SCAN_NAME = 16; + /** + * A field is set to an invalid value. + * + * Generated from protobuf enum INVALID_FIELD_VALUE = 18; + */ + const INVALID_FIELD_VALUE = 18; + /** + * There was an error trying to authenticate to the scan target. + * + * Generated from protobuf enum FAILED_TO_AUTHENTICATE_TO_TARGET = 19; + */ + const FAILED_TO_AUTHENTICATE_TO_TARGET = 19; + /** + * Finding type value is not specified in the list findings request. + * + * Generated from protobuf enum FINDING_TYPE_UNSPECIFIED = 20; + */ + const FINDING_TYPE_UNSPECIFIED = 20; + /** + * Scan targets Compute Engine, yet current project was not whitelisted for + * Google Compute Engine Scanning Alpha access. + * + * Generated from protobuf enum FORBIDDEN_TO_SCAN_COMPUTE = 21; + */ + const FORBIDDEN_TO_SCAN_COMPUTE = 21; + /** + * User tries to update managed scan + * + * Generated from protobuf enum FORBIDDEN_UPDATE_TO_MANAGED_SCAN = 43; + */ + const FORBIDDEN_UPDATE_TO_MANAGED_SCAN = 43; + /** + * The supplied filter is malformed. For example, it can not be parsed, does + * not have a filter type in expression, or the same filter type appears + * more than once. + * + * Generated from protobuf enum MALFORMED_FILTER = 22; + */ + const MALFORMED_FILTER = 22; + /** + * The supplied resource name is malformed (can not be parsed). + * + * Generated from protobuf enum MALFORMED_RESOURCE_NAME = 23; + */ + const MALFORMED_RESOURCE_NAME = 23; + /** + * The current project is not in an active state. + * + * Generated from protobuf enum PROJECT_INACTIVE = 24; + */ + const PROJECT_INACTIVE = 24; + /** + * A required field is not set. + * + * Generated from protobuf enum REQUIRED_FIELD = 25; + */ + const REQUIRED_FIELD = 25; + /** + * Project id, scanconfig id, scanrun id, or finding id are not consistent + * with each other in resource name. + * + * Generated from protobuf enum RESOURCE_NAME_INCONSISTENT = 26; + */ + const RESOURCE_NAME_INCONSISTENT = 26; + /** + * The scan being requested to start is already running. + * + * Generated from protobuf enum SCAN_ALREADY_RUNNING = 27; + */ + const SCAN_ALREADY_RUNNING = 27; + /** + * The scan that was requested to be stopped is not running. + * + * Generated from protobuf enum SCAN_NOT_RUNNING = 28; + */ + const SCAN_NOT_RUNNING = 28; + /** + * One of the seed URLs does not belong to the current project. + * + * Generated from protobuf enum SEED_URL_DOES_NOT_BELONG_TO_CURRENT_PROJECT = 29; + */ + const SEED_URL_DOES_NOT_BELONG_TO_CURRENT_PROJECT = 29; + /** + * One of the seed URLs is malformed (can not be parsed). + * + * Generated from protobuf enum SEED_URL_MALFORMED = 30; + */ + const SEED_URL_MALFORMED = 30; + /** + * One of the seed URLs is mapped to a non-routable IP address in DNS. + * + * Generated from protobuf enum SEED_URL_MAPPED_TO_NON_ROUTABLE_ADDRESS = 31; + */ + const SEED_URL_MAPPED_TO_NON_ROUTABLE_ADDRESS = 31; + /** + * One of the seed URLs is mapped to an IP address which is not reserved + * for the current project. + * + * Generated from protobuf enum SEED_URL_MAPPED_TO_UNRESERVED_ADDRESS = 32; + */ + const SEED_URL_MAPPED_TO_UNRESERVED_ADDRESS = 32; + /** + * One of the seed URLs has on-routable IP address. + * + * Generated from protobuf enum SEED_URL_HAS_NON_ROUTABLE_IP_ADDRESS = 33; + */ + const SEED_URL_HAS_NON_ROUTABLE_IP_ADDRESS = 33; + /** + * One of the seed URLs has an IP address that is not reserved + * for the current project. + * + * Generated from protobuf enum SEED_URL_HAS_UNRESERVED_IP_ADDRESS = 35; + */ + const SEED_URL_HAS_UNRESERVED_IP_ADDRESS = 35; + /** + * The Web Security Scanner service account is not configured under the + * project. + * + * Generated from protobuf enum SERVICE_ACCOUNT_NOT_CONFIGURED = 36; + */ + const SERVICE_ACCOUNT_NOT_CONFIGURED = 36; + /** + * A project has reached the maximum number of scans. + * + * Generated from protobuf enum TOO_MANY_SCANS = 37; + */ + const TOO_MANY_SCANS = 37; + /** + * Resolving the details of the current project fails. + * + * Generated from protobuf enum UNABLE_TO_RESOLVE_PROJECT_INFO = 38; + */ + const UNABLE_TO_RESOLVE_PROJECT_INFO = 38; + /** + * One or more blacklist patterns were in the wrong format. + * + * Generated from protobuf enum UNSUPPORTED_BLACKLIST_PATTERN_FORMAT = 39; + */ + const UNSUPPORTED_BLACKLIST_PATTERN_FORMAT = 39; + /** + * The supplied filter is not supported. + * + * Generated from protobuf enum UNSUPPORTED_FILTER = 40; + */ + const UNSUPPORTED_FILTER = 40; + /** + * The supplied finding type is not supported. For example, we do not + * provide findings of the given finding type. + * + * Generated from protobuf enum UNSUPPORTED_FINDING_TYPE = 41; + */ + const UNSUPPORTED_FINDING_TYPE = 41; + /** + * The URL scheme of one or more of the supplied URLs is not supported. + * + * Generated from protobuf enum UNSUPPORTED_URL_SCHEME = 42; + */ + const UNSUPPORTED_URL_SCHEME = 42; + + private static $valueToName = [ + self::CODE_UNSPECIFIED => 'CODE_UNSPECIFIED', + self::OK => 'OK', + self::INTERNAL_ERROR => 'INTERNAL_ERROR', + self::APPENGINE_API_BACKEND_ERROR => 'APPENGINE_API_BACKEND_ERROR', + self::APPENGINE_API_NOT_ACCESSIBLE => 'APPENGINE_API_NOT_ACCESSIBLE', + self::APPENGINE_DEFAULT_HOST_MISSING => 'APPENGINE_DEFAULT_HOST_MISSING', + self::CANNOT_USE_GOOGLE_COM_ACCOUNT => 'CANNOT_USE_GOOGLE_COM_ACCOUNT', + self::CANNOT_USE_OWNER_ACCOUNT => 'CANNOT_USE_OWNER_ACCOUNT', + self::COMPUTE_API_BACKEND_ERROR => 'COMPUTE_API_BACKEND_ERROR', + self::COMPUTE_API_NOT_ACCESSIBLE => 'COMPUTE_API_NOT_ACCESSIBLE', + self::CUSTOM_LOGIN_URL_DOES_NOT_BELONG_TO_CURRENT_PROJECT => 'CUSTOM_LOGIN_URL_DOES_NOT_BELONG_TO_CURRENT_PROJECT', + self::CUSTOM_LOGIN_URL_MALFORMED => 'CUSTOM_LOGIN_URL_MALFORMED', + self::CUSTOM_LOGIN_URL_MAPPED_TO_NON_ROUTABLE_ADDRESS => 'CUSTOM_LOGIN_URL_MAPPED_TO_NON_ROUTABLE_ADDRESS', + self::CUSTOM_LOGIN_URL_MAPPED_TO_UNRESERVED_ADDRESS => 'CUSTOM_LOGIN_URL_MAPPED_TO_UNRESERVED_ADDRESS', + self::CUSTOM_LOGIN_URL_HAS_NON_ROUTABLE_IP_ADDRESS => 'CUSTOM_LOGIN_URL_HAS_NON_ROUTABLE_IP_ADDRESS', + self::CUSTOM_LOGIN_URL_HAS_UNRESERVED_IP_ADDRESS => 'CUSTOM_LOGIN_URL_HAS_UNRESERVED_IP_ADDRESS', + self::DUPLICATE_SCAN_NAME => 'DUPLICATE_SCAN_NAME', + self::INVALID_FIELD_VALUE => 'INVALID_FIELD_VALUE', + self::FAILED_TO_AUTHENTICATE_TO_TARGET => 'FAILED_TO_AUTHENTICATE_TO_TARGET', + self::FINDING_TYPE_UNSPECIFIED => 'FINDING_TYPE_UNSPECIFIED', + self::FORBIDDEN_TO_SCAN_COMPUTE => 'FORBIDDEN_TO_SCAN_COMPUTE', + self::FORBIDDEN_UPDATE_TO_MANAGED_SCAN => 'FORBIDDEN_UPDATE_TO_MANAGED_SCAN', + self::MALFORMED_FILTER => 'MALFORMED_FILTER', + self::MALFORMED_RESOURCE_NAME => 'MALFORMED_RESOURCE_NAME', + self::PROJECT_INACTIVE => 'PROJECT_INACTIVE', + self::REQUIRED_FIELD => 'REQUIRED_FIELD', + self::RESOURCE_NAME_INCONSISTENT => 'RESOURCE_NAME_INCONSISTENT', + self::SCAN_ALREADY_RUNNING => 'SCAN_ALREADY_RUNNING', + self::SCAN_NOT_RUNNING => 'SCAN_NOT_RUNNING', + self::SEED_URL_DOES_NOT_BELONG_TO_CURRENT_PROJECT => 'SEED_URL_DOES_NOT_BELONG_TO_CURRENT_PROJECT', + self::SEED_URL_MALFORMED => 'SEED_URL_MALFORMED', + self::SEED_URL_MAPPED_TO_NON_ROUTABLE_ADDRESS => 'SEED_URL_MAPPED_TO_NON_ROUTABLE_ADDRESS', + self::SEED_URL_MAPPED_TO_UNRESERVED_ADDRESS => 'SEED_URL_MAPPED_TO_UNRESERVED_ADDRESS', + self::SEED_URL_HAS_NON_ROUTABLE_IP_ADDRESS => 'SEED_URL_HAS_NON_ROUTABLE_IP_ADDRESS', + self::SEED_URL_HAS_UNRESERVED_IP_ADDRESS => 'SEED_URL_HAS_UNRESERVED_IP_ADDRESS', + self::SERVICE_ACCOUNT_NOT_CONFIGURED => 'SERVICE_ACCOUNT_NOT_CONFIGURED', + self::TOO_MANY_SCANS => 'TOO_MANY_SCANS', + self::UNABLE_TO_RESOLVE_PROJECT_INFO => 'UNABLE_TO_RESOLVE_PROJECT_INFO', + self::UNSUPPORTED_BLACKLIST_PATTERN_FORMAT => 'UNSUPPORTED_BLACKLIST_PATTERN_FORMAT', + self::UNSUPPORTED_FILTER => 'UNSUPPORTED_FILTER', + self::UNSUPPORTED_FINDING_TYPE => 'UNSUPPORTED_FINDING_TYPE', + self::UNSUPPORTED_URL_SCHEME => 'UNSUPPORTED_URL_SCHEME', + ]; + + public static function name($value) + { + if (!isset(self::$valueToName[$value])) { + throw new UnexpectedValueException(sprintf( + 'Enum %s has no name defined for value %s', __CLASS__, $value)); + } + return self::$valueToName[$value]; + } + + + public static function value($name) + { + $const = __CLASS__ . '::' . strtoupper($name); + if (!defined($const)) { + throw new UnexpectedValueException(sprintf( + 'Enum %s has no value defined for name %s', __CLASS__, $name)); + } + return constant($const); + } +} + + diff --git a/WebSecurityScanner/src/V1/ScanRun.php b/WebSecurityScanner/src/V1/ScanRun.php new file mode 100644 index 000000000000..82e7a4b4d144 --- /dev/null +++ b/WebSecurityScanner/src/V1/ScanRun.php @@ -0,0 +1,486 @@ +google.cloud.websecurityscanner.v1.ScanRun + */ +class ScanRun extends \Google\Protobuf\Internal\Message +{ + /** + * Output only. The resource name of the ScanRun. The name follows the format of + * 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. + * The ScanRun IDs are generated by the system. + * + * Generated from protobuf field string name = 1; + */ + private $name = ''; + /** + * Output only. The execution state of the ScanRun. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanRun.ExecutionState execution_state = 2; + */ + private $execution_state = 0; + /** + * Output only. The result state of the ScanRun. This field is only available after the + * execution state reaches "FINISHED". + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanRun.ResultState result_state = 3; + */ + private $result_state = 0; + /** + * Output only. The time at which the ScanRun started. + * + * Generated from protobuf field .google.protobuf.Timestamp start_time = 4; + */ + private $start_time = null; + /** + * Output only. The time at which the ScanRun reached termination state - that the ScanRun + * is either finished or stopped by user. + * + * Generated from protobuf field .google.protobuf.Timestamp end_time = 5; + */ + private $end_time = null; + /** + * Output only. The number of URLs crawled during this ScanRun. If the scan is in progress, + * the value represents the number of URLs crawled up to now. + * + * Generated from protobuf field int64 urls_crawled_count = 6; + */ + private $urls_crawled_count = 0; + /** + * Output only. The number of URLs tested during this ScanRun. If the scan is in progress, + * the value represents the number of URLs tested up to now. The number of + * URLs tested is usually larger than the number URLS crawled because + * typically a crawled URL is tested with multiple test payloads. + * + * Generated from protobuf field int64 urls_tested_count = 7; + */ + private $urls_tested_count = 0; + /** + * Output only. Whether the scan run has found any vulnerabilities. + * + * Generated from protobuf field bool has_vulnerabilities = 8; + */ + private $has_vulnerabilities = false; + /** + * Output only. The percentage of total completion ranging from 0 to 100. + * If the scan is in queue, the value is 0. + * If the scan is running, the value ranges from 0 to 100. + * If the scan is finished, the value is 100. + * + * Generated from protobuf field int32 progress_percent = 9; + */ + private $progress_percent = 0; + /** + * Output only. If result_state is an ERROR, this field provides the primary reason for + * scan's termination and more details, if such are available. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanRunErrorTrace error_trace = 10; + */ + private $error_trace = null; + /** + * Output only. A list of warnings, if such are encountered during this scan run. + * + * Generated from protobuf field repeated .google.cloud.websecurityscanner.v1.ScanRunWarningTrace warning_traces = 11; + */ + private $warning_traces; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * Output only. The resource name of the ScanRun. The name follows the format of + * 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. + * The ScanRun IDs are generated by the system. + * @type int $execution_state + * Output only. The execution state of the ScanRun. + * @type int $result_state + * Output only. The result state of the ScanRun. This field is only available after the + * execution state reaches "FINISHED". + * @type \Google\Protobuf\Timestamp $start_time + * Output only. The time at which the ScanRun started. + * @type \Google\Protobuf\Timestamp $end_time + * Output only. The time at which the ScanRun reached termination state - that the ScanRun + * is either finished or stopped by user. + * @type int|string $urls_crawled_count + * Output only. The number of URLs crawled during this ScanRun. If the scan is in progress, + * the value represents the number of URLs crawled up to now. + * @type int|string $urls_tested_count + * Output only. The number of URLs tested during this ScanRun. If the scan is in progress, + * the value represents the number of URLs tested up to now. The number of + * URLs tested is usually larger than the number URLS crawled because + * typically a crawled URL is tested with multiple test payloads. + * @type bool $has_vulnerabilities + * Output only. Whether the scan run has found any vulnerabilities. + * @type int $progress_percent + * Output only. The percentage of total completion ranging from 0 to 100. + * If the scan is in queue, the value is 0. + * If the scan is running, the value ranges from 0 to 100. + * If the scan is finished, the value is 100. + * @type \Google\Cloud\WebSecurityScanner\V1\ScanRunErrorTrace $error_trace + * Output only. If result_state is an ERROR, this field provides the primary reason for + * scan's termination and more details, if such are available. + * @type array<\Google\Cloud\WebSecurityScanner\V1\ScanRunWarningTrace>|\Google\Protobuf\Internal\RepeatedField $warning_traces + * Output only. A list of warnings, if such are encountered during this scan run. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\ScanRun::initOnce(); + parent::__construct($data); + } + + /** + * Output only. The resource name of the ScanRun. The name follows the format of + * 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. + * The ScanRun IDs are generated by the system. + * + * Generated from protobuf field string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Output only. The resource name of the ScanRun. The name follows the format of + * 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. + * The ScanRun IDs are generated by the system. + * + * Generated from protobuf field string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * Output only. The execution state of the ScanRun. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanRun.ExecutionState execution_state = 2; + * @return int + */ + public function getExecutionState() + { + return $this->execution_state; + } + + /** + * Output only. The execution state of the ScanRun. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanRun.ExecutionState execution_state = 2; + * @param int $var + * @return $this + */ + public function setExecutionState($var) + { + GPBUtil::checkEnum($var, \Google\Cloud\WebSecurityScanner\V1\ScanRun\ExecutionState::class); + $this->execution_state = $var; + + return $this; + } + + /** + * Output only. The result state of the ScanRun. This field is only available after the + * execution state reaches "FINISHED". + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanRun.ResultState result_state = 3; + * @return int + */ + public function getResultState() + { + return $this->result_state; + } + + /** + * Output only. The result state of the ScanRun. This field is only available after the + * execution state reaches "FINISHED". + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanRun.ResultState result_state = 3; + * @param int $var + * @return $this + */ + public function setResultState($var) + { + GPBUtil::checkEnum($var, \Google\Cloud\WebSecurityScanner\V1\ScanRun\ResultState::class); + $this->result_state = $var; + + return $this; + } + + /** + * Output only. The time at which the ScanRun started. + * + * Generated from protobuf field .google.protobuf.Timestamp start_time = 4; + * @return \Google\Protobuf\Timestamp|null + */ + public function getStartTime() + { + return $this->start_time; + } + + public function hasStartTime() + { + return isset($this->start_time); + } + + public function clearStartTime() + { + unset($this->start_time); + } + + /** + * Output only. The time at which the ScanRun started. + * + * Generated from protobuf field .google.protobuf.Timestamp start_time = 4; + * @param \Google\Protobuf\Timestamp $var + * @return $this + */ + public function setStartTime($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Timestamp::class); + $this->start_time = $var; + + return $this; + } + + /** + * Output only. The time at which the ScanRun reached termination state - that the ScanRun + * is either finished or stopped by user. + * + * Generated from protobuf field .google.protobuf.Timestamp end_time = 5; + * @return \Google\Protobuf\Timestamp|null + */ + public function getEndTime() + { + return $this->end_time; + } + + public function hasEndTime() + { + return isset($this->end_time); + } + + public function clearEndTime() + { + unset($this->end_time); + } + + /** + * Output only. The time at which the ScanRun reached termination state - that the ScanRun + * is either finished or stopped by user. + * + * Generated from protobuf field .google.protobuf.Timestamp end_time = 5; + * @param \Google\Protobuf\Timestamp $var + * @return $this + */ + public function setEndTime($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Timestamp::class); + $this->end_time = $var; + + return $this; + } + + /** + * Output only. The number of URLs crawled during this ScanRun. If the scan is in progress, + * the value represents the number of URLs crawled up to now. + * + * Generated from protobuf field int64 urls_crawled_count = 6; + * @return int|string + */ + public function getUrlsCrawledCount() + { + return $this->urls_crawled_count; + } + + /** + * Output only. The number of URLs crawled during this ScanRun. If the scan is in progress, + * the value represents the number of URLs crawled up to now. + * + * Generated from protobuf field int64 urls_crawled_count = 6; + * @param int|string $var + * @return $this + */ + public function setUrlsCrawledCount($var) + { + GPBUtil::checkInt64($var); + $this->urls_crawled_count = $var; + + return $this; + } + + /** + * Output only. The number of URLs tested during this ScanRun. If the scan is in progress, + * the value represents the number of URLs tested up to now. The number of + * URLs tested is usually larger than the number URLS crawled because + * typically a crawled URL is tested with multiple test payloads. + * + * Generated from protobuf field int64 urls_tested_count = 7; + * @return int|string + */ + public function getUrlsTestedCount() + { + return $this->urls_tested_count; + } + + /** + * Output only. The number of URLs tested during this ScanRun. If the scan is in progress, + * the value represents the number of URLs tested up to now. The number of + * URLs tested is usually larger than the number URLS crawled because + * typically a crawled URL is tested with multiple test payloads. + * + * Generated from protobuf field int64 urls_tested_count = 7; + * @param int|string $var + * @return $this + */ + public function setUrlsTestedCount($var) + { + GPBUtil::checkInt64($var); + $this->urls_tested_count = $var; + + return $this; + } + + /** + * Output only. Whether the scan run has found any vulnerabilities. + * + * Generated from protobuf field bool has_vulnerabilities = 8; + * @return bool + */ + public function getHasVulnerabilities() + { + return $this->has_vulnerabilities; + } + + /** + * Output only. Whether the scan run has found any vulnerabilities. + * + * Generated from protobuf field bool has_vulnerabilities = 8; + * @param bool $var + * @return $this + */ + public function setHasVulnerabilities($var) + { + GPBUtil::checkBool($var); + $this->has_vulnerabilities = $var; + + return $this; + } + + /** + * Output only. The percentage of total completion ranging from 0 to 100. + * If the scan is in queue, the value is 0. + * If the scan is running, the value ranges from 0 to 100. + * If the scan is finished, the value is 100. + * + * Generated from protobuf field int32 progress_percent = 9; + * @return int + */ + public function getProgressPercent() + { + return $this->progress_percent; + } + + /** + * Output only. The percentage of total completion ranging from 0 to 100. + * If the scan is in queue, the value is 0. + * If the scan is running, the value ranges from 0 to 100. + * If the scan is finished, the value is 100. + * + * Generated from protobuf field int32 progress_percent = 9; + * @param int $var + * @return $this + */ + public function setProgressPercent($var) + { + GPBUtil::checkInt32($var); + $this->progress_percent = $var; + + return $this; + } + + /** + * Output only. If result_state is an ERROR, this field provides the primary reason for + * scan's termination and more details, if such are available. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanRunErrorTrace error_trace = 10; + * @return \Google\Cloud\WebSecurityScanner\V1\ScanRunErrorTrace|null + */ + public function getErrorTrace() + { + return $this->error_trace; + } + + public function hasErrorTrace() + { + return isset($this->error_trace); + } + + public function clearErrorTrace() + { + unset($this->error_trace); + } + + /** + * Output only. If result_state is an ERROR, this field provides the primary reason for + * scan's termination and more details, if such are available. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanRunErrorTrace error_trace = 10; + * @param \Google\Cloud\WebSecurityScanner\V1\ScanRunErrorTrace $var + * @return $this + */ + public function setErrorTrace($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\WebSecurityScanner\V1\ScanRunErrorTrace::class); + $this->error_trace = $var; + + return $this; + } + + /** + * Output only. A list of warnings, if such are encountered during this scan run. + * + * Generated from protobuf field repeated .google.cloud.websecurityscanner.v1.ScanRunWarningTrace warning_traces = 11; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getWarningTraces() + { + return $this->warning_traces; + } + + /** + * Output only. A list of warnings, if such are encountered during this scan run. + * + * Generated from protobuf field repeated .google.cloud.websecurityscanner.v1.ScanRunWarningTrace warning_traces = 11; + * @param array<\Google\Cloud\WebSecurityScanner\V1\ScanRunWarningTrace>|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setWarningTraces($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\WebSecurityScanner\V1\ScanRunWarningTrace::class); + $this->warning_traces = $arr; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/ScanRun/ExecutionState.php b/WebSecurityScanner/src/V1/ScanRun/ExecutionState.php new file mode 100644 index 000000000000..16738c3bc32a --- /dev/null +++ b/WebSecurityScanner/src/V1/ScanRun/ExecutionState.php @@ -0,0 +1,70 @@ +google.cloud.websecurityscanner.v1.ScanRun.ExecutionState + */ +class ExecutionState +{ + /** + * Represents an invalid state caused by internal server error. This value + * should never be returned. + * + * Generated from protobuf enum EXECUTION_STATE_UNSPECIFIED = 0; + */ + const EXECUTION_STATE_UNSPECIFIED = 0; + /** + * The scan is waiting in the queue. + * + * Generated from protobuf enum QUEUED = 1; + */ + const QUEUED = 1; + /** + * The scan is in progress. + * + * Generated from protobuf enum SCANNING = 2; + */ + const SCANNING = 2; + /** + * The scan is either finished or stopped by user. + * + * Generated from protobuf enum FINISHED = 3; + */ + const FINISHED = 3; + + private static $valueToName = [ + self::EXECUTION_STATE_UNSPECIFIED => 'EXECUTION_STATE_UNSPECIFIED', + self::QUEUED => 'QUEUED', + self::SCANNING => 'SCANNING', + self::FINISHED => 'FINISHED', + ]; + + public static function name($value) + { + if (!isset(self::$valueToName[$value])) { + throw new UnexpectedValueException(sprintf( + 'Enum %s has no name defined for value %s', __CLASS__, $value)); + } + return self::$valueToName[$value]; + } + + + public static function value($name) + { + $const = __CLASS__ . '::' . strtoupper($name); + if (!defined($const)) { + throw new UnexpectedValueException(sprintf( + 'Enum %s has no value defined for name %s', __CLASS__, $name)); + } + return constant($const); + } +} + + diff --git a/WebSecurityScanner/src/V1/ScanRun/ResultState.php b/WebSecurityScanner/src/V1/ScanRun/ResultState.php new file mode 100644 index 000000000000..45295c686499 --- /dev/null +++ b/WebSecurityScanner/src/V1/ScanRun/ResultState.php @@ -0,0 +1,70 @@ +google.cloud.websecurityscanner.v1.ScanRun.ResultState + */ +class ResultState +{ + /** + * Default value. This value is returned when the ScanRun is not yet + * finished. + * + * Generated from protobuf enum RESULT_STATE_UNSPECIFIED = 0; + */ + const RESULT_STATE_UNSPECIFIED = 0; + /** + * The scan finished without errors. + * + * Generated from protobuf enum SUCCESS = 1; + */ + const SUCCESS = 1; + /** + * The scan finished with errors. + * + * Generated from protobuf enum ERROR = 2; + */ + const ERROR = 2; + /** + * The scan was terminated by user. + * + * Generated from protobuf enum KILLED = 3; + */ + const KILLED = 3; + + private static $valueToName = [ + self::RESULT_STATE_UNSPECIFIED => 'RESULT_STATE_UNSPECIFIED', + self::SUCCESS => 'SUCCESS', + self::ERROR => 'ERROR', + self::KILLED => 'KILLED', + ]; + + public static function name($value) + { + if (!isset(self::$valueToName[$value])) { + throw new UnexpectedValueException(sprintf( + 'Enum %s has no name defined for value %s', __CLASS__, $value)); + } + return self::$valueToName[$value]; + } + + + public static function value($name) + { + $const = __CLASS__ . '::' . strtoupper($name); + if (!defined($const)) { + throw new UnexpectedValueException(sprintf( + 'Enum %s has no value defined for name %s', __CLASS__, $name)); + } + return constant($const); + } +} + + diff --git a/WebSecurityScanner/src/V1/ScanRunErrorTrace.php b/WebSecurityScanner/src/V1/ScanRunErrorTrace.php new file mode 100644 index 000000000000..5322839fd8a4 --- /dev/null +++ b/WebSecurityScanner/src/V1/ScanRunErrorTrace.php @@ -0,0 +1,162 @@ +google.cloud.websecurityscanner.v1.ScanRunErrorTrace + */ +class ScanRunErrorTrace extends \Google\Protobuf\Internal\Message +{ + /** + * Output only. Indicates the error reason code. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanRunErrorTrace.Code code = 1; + */ + private $code = 0; + /** + * Output only. If the scan encounters SCAN_CONFIG_ISSUE error, this field has the error + * message encountered during scan configuration validation that is performed + * before each scan run. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfigError scan_config_error = 2; + */ + private $scan_config_error = null; + /** + * Output only. If the scan encounters TOO_MANY_HTTP_ERRORS, this field indicates the most + * common HTTP error code, if such is available. For example, if this code is + * 404, the scan has encountered too many NOT_FOUND responses. + * + * Generated from protobuf field int32 most_common_http_error_code = 3; + */ + private $most_common_http_error_code = 0; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type int $code + * Output only. Indicates the error reason code. + * @type \Google\Cloud\WebSecurityScanner\V1\ScanConfigError $scan_config_error + * Output only. If the scan encounters SCAN_CONFIG_ISSUE error, this field has the error + * message encountered during scan configuration validation that is performed + * before each scan run. + * @type int $most_common_http_error_code + * Output only. If the scan encounters TOO_MANY_HTTP_ERRORS, this field indicates the most + * common HTTP error code, if such is available. For example, if this code is + * 404, the scan has encountered too many NOT_FOUND responses. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\ScanRunErrorTrace::initOnce(); + parent::__construct($data); + } + + /** + * Output only. Indicates the error reason code. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanRunErrorTrace.Code code = 1; + * @return int + */ + public function getCode() + { + return $this->code; + } + + /** + * Output only. Indicates the error reason code. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanRunErrorTrace.Code code = 1; + * @param int $var + * @return $this + */ + public function setCode($var) + { + GPBUtil::checkEnum($var, \Google\Cloud\WebSecurityScanner\V1\ScanRunErrorTrace\Code::class); + $this->code = $var; + + return $this; + } + + /** + * Output only. If the scan encounters SCAN_CONFIG_ISSUE error, this field has the error + * message encountered during scan configuration validation that is performed + * before each scan run. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfigError scan_config_error = 2; + * @return \Google\Cloud\WebSecurityScanner\V1\ScanConfigError|null + */ + public function getScanConfigError() + { + return $this->scan_config_error; + } + + public function hasScanConfigError() + { + return isset($this->scan_config_error); + } + + public function clearScanConfigError() + { + unset($this->scan_config_error); + } + + /** + * Output only. If the scan encounters SCAN_CONFIG_ISSUE error, this field has the error + * message encountered during scan configuration validation that is performed + * before each scan run. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfigError scan_config_error = 2; + * @param \Google\Cloud\WebSecurityScanner\V1\ScanConfigError $var + * @return $this + */ + public function setScanConfigError($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\WebSecurityScanner\V1\ScanConfigError::class); + $this->scan_config_error = $var; + + return $this; + } + + /** + * Output only. If the scan encounters TOO_MANY_HTTP_ERRORS, this field indicates the most + * common HTTP error code, if such is available. For example, if this code is + * 404, the scan has encountered too many NOT_FOUND responses. + * + * Generated from protobuf field int32 most_common_http_error_code = 3; + * @return int + */ + public function getMostCommonHttpErrorCode() + { + return $this->most_common_http_error_code; + } + + /** + * Output only. If the scan encounters TOO_MANY_HTTP_ERRORS, this field indicates the most + * common HTTP error code, if such is available. For example, if this code is + * 404, the scan has encountered too many NOT_FOUND responses. + * + * Generated from protobuf field int32 most_common_http_error_code = 3; + * @param int $var + * @return $this + */ + public function setMostCommonHttpErrorCode($var) + { + GPBUtil::checkInt32($var); + $this->most_common_http_error_code = $var; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/ScanRunErrorTrace/Code.php b/WebSecurityScanner/src/V1/ScanRunErrorTrace/Code.php new file mode 100644 index 000000000000..415fe7a300e3 --- /dev/null +++ b/WebSecurityScanner/src/V1/ScanRunErrorTrace/Code.php @@ -0,0 +1,97 @@ +google.cloud.websecurityscanner.v1.ScanRunErrorTrace.Code + */ +class Code +{ + /** + * Default value is never used. + * + * Generated from protobuf enum CODE_UNSPECIFIED = 0; + */ + const CODE_UNSPECIFIED = 0; + /** + * Indicates that the scan run failed due to an internal server error. + * + * Generated from protobuf enum INTERNAL_ERROR = 1; + */ + const INTERNAL_ERROR = 1; + /** + * Indicates a scan configuration error, usually due to outdated ScanConfig + * settings, such as starting_urls or the DNS configuration. + * + * Generated from protobuf enum SCAN_CONFIG_ISSUE = 2; + */ + const SCAN_CONFIG_ISSUE = 2; + /** + * Indicates an authentication error, usually due to outdated ScanConfig + * authentication settings. + * + * Generated from protobuf enum AUTHENTICATION_CONFIG_ISSUE = 3; + */ + const AUTHENTICATION_CONFIG_ISSUE = 3; + /** + * Indicates a scan operation timeout, usually caused by a very large site. + * + * Generated from protobuf enum TIMED_OUT_WHILE_SCANNING = 4; + */ + const TIMED_OUT_WHILE_SCANNING = 4; + /** + * Indicates that a scan encountered excessive redirects, either to + * authentication or some other page outside of the scan scope. + * + * Generated from protobuf enum TOO_MANY_REDIRECTS = 5; + */ + const TOO_MANY_REDIRECTS = 5; + /** + * Indicates that a scan encountered numerous errors from the web site + * pages. When available, most_common_http_error_code field indicates the + * most common HTTP error code encountered during the scan. + * + * Generated from protobuf enum TOO_MANY_HTTP_ERRORS = 6; + */ + const TOO_MANY_HTTP_ERRORS = 6; + + private static $valueToName = [ + self::CODE_UNSPECIFIED => 'CODE_UNSPECIFIED', + self::INTERNAL_ERROR => 'INTERNAL_ERROR', + self::SCAN_CONFIG_ISSUE => 'SCAN_CONFIG_ISSUE', + self::AUTHENTICATION_CONFIG_ISSUE => 'AUTHENTICATION_CONFIG_ISSUE', + self::TIMED_OUT_WHILE_SCANNING => 'TIMED_OUT_WHILE_SCANNING', + self::TOO_MANY_REDIRECTS => 'TOO_MANY_REDIRECTS', + self::TOO_MANY_HTTP_ERRORS => 'TOO_MANY_HTTP_ERRORS', + ]; + + public static function name($value) + { + if (!isset(self::$valueToName[$value])) { + throw new UnexpectedValueException(sprintf( + 'Enum %s has no name defined for value %s', __CLASS__, $value)); + } + return self::$valueToName[$value]; + } + + + public static function value($name) + { + $const = __CLASS__ . '::' . strtoupper($name); + if (!defined($const)) { + throw new UnexpectedValueException(sprintf( + 'Enum %s has no value defined for name %s', __CLASS__, $name)); + } + return constant($const); + } +} + + diff --git a/WebSecurityScanner/src/V1/ScanRunLog.php b/WebSecurityScanner/src/V1/ScanRunLog.php new file mode 100644 index 000000000000..94e68e35319f --- /dev/null +++ b/WebSecurityScanner/src/V1/ScanRunLog.php @@ -0,0 +1,291 @@ +google.cloud.websecurityscanner.v1.ScanRunLog + */ +class ScanRunLog extends \Google\Protobuf\Internal\Message +{ + /** + * Human friendly message about the event. + * + * Generated from protobuf field string summary = 1; + */ + private $summary = ''; + /** + * The resource name of the ScanRun being logged. + * + * Generated from protobuf field string name = 2; + */ + private $name = ''; + /** + * The execution state of the ScanRun. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanRun.ExecutionState execution_state = 3; + */ + private $execution_state = 0; + /** + * The result state of the ScanRun. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanRun.ResultState result_state = 4; + */ + private $result_state = 0; + /** + * Generated from protobuf field int64 urls_crawled_count = 5; + */ + private $urls_crawled_count = 0; + /** + * Generated from protobuf field int64 urls_tested_count = 6; + */ + private $urls_tested_count = 0; + /** + * Generated from protobuf field bool has_findings = 7; + */ + private $has_findings = false; + /** + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanRunErrorTrace error_trace = 8; + */ + private $error_trace = null; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $summary + * Human friendly message about the event. + * @type string $name + * The resource name of the ScanRun being logged. + * @type int $execution_state + * The execution state of the ScanRun. + * @type int $result_state + * The result state of the ScanRun. + * @type int|string $urls_crawled_count + * @type int|string $urls_tested_count + * @type bool $has_findings + * @type \Google\Cloud\WebSecurityScanner\V1\ScanRunErrorTrace $error_trace + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\ScanRunLog::initOnce(); + parent::__construct($data); + } + + /** + * Human friendly message about the event. + * + * Generated from protobuf field string summary = 1; + * @return string + */ + public function getSummary() + { + return $this->summary; + } + + /** + * Human friendly message about the event. + * + * Generated from protobuf field string summary = 1; + * @param string $var + * @return $this + */ + public function setSummary($var) + { + GPBUtil::checkString($var, True); + $this->summary = $var; + + return $this; + } + + /** + * The resource name of the ScanRun being logged. + * + * Generated from protobuf field string name = 2; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * The resource name of the ScanRun being logged. + * + * Generated from protobuf field string name = 2; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * The execution state of the ScanRun. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanRun.ExecutionState execution_state = 3; + * @return int + */ + public function getExecutionState() + { + return $this->execution_state; + } + + /** + * The execution state of the ScanRun. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanRun.ExecutionState execution_state = 3; + * @param int $var + * @return $this + */ + public function setExecutionState($var) + { + GPBUtil::checkEnum($var, \Google\Cloud\WebSecurityScanner\V1\ScanRun\ExecutionState::class); + $this->execution_state = $var; + + return $this; + } + + /** + * The result state of the ScanRun. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanRun.ResultState result_state = 4; + * @return int + */ + public function getResultState() + { + return $this->result_state; + } + + /** + * The result state of the ScanRun. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanRun.ResultState result_state = 4; + * @param int $var + * @return $this + */ + public function setResultState($var) + { + GPBUtil::checkEnum($var, \Google\Cloud\WebSecurityScanner\V1\ScanRun\ResultState::class); + $this->result_state = $var; + + return $this; + } + + /** + * Generated from protobuf field int64 urls_crawled_count = 5; + * @return int|string + */ + public function getUrlsCrawledCount() + { + return $this->urls_crawled_count; + } + + /** + * Generated from protobuf field int64 urls_crawled_count = 5; + * @param int|string $var + * @return $this + */ + public function setUrlsCrawledCount($var) + { + GPBUtil::checkInt64($var); + $this->urls_crawled_count = $var; + + return $this; + } + + /** + * Generated from protobuf field int64 urls_tested_count = 6; + * @return int|string + */ + public function getUrlsTestedCount() + { + return $this->urls_tested_count; + } + + /** + * Generated from protobuf field int64 urls_tested_count = 6; + * @param int|string $var + * @return $this + */ + public function setUrlsTestedCount($var) + { + GPBUtil::checkInt64($var); + $this->urls_tested_count = $var; + + return $this; + } + + /** + * Generated from protobuf field bool has_findings = 7; + * @return bool + */ + public function getHasFindings() + { + return $this->has_findings; + } + + /** + * Generated from protobuf field bool has_findings = 7; + * @param bool $var + * @return $this + */ + public function setHasFindings($var) + { + GPBUtil::checkBool($var); + $this->has_findings = $var; + + return $this; + } + + /** + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanRunErrorTrace error_trace = 8; + * @return \Google\Cloud\WebSecurityScanner\V1\ScanRunErrorTrace|null + */ + public function getErrorTrace() + { + return $this->error_trace; + } + + public function hasErrorTrace() + { + return isset($this->error_trace); + } + + public function clearErrorTrace() + { + unset($this->error_trace); + } + + /** + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanRunErrorTrace error_trace = 8; + * @param \Google\Cloud\WebSecurityScanner\V1\ScanRunErrorTrace $var + * @return $this + */ + public function setErrorTrace($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\WebSecurityScanner\V1\ScanRunErrorTrace::class); + $this->error_trace = $var; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/ScanRunWarningTrace.php b/WebSecurityScanner/src/V1/ScanRunWarningTrace.php new file mode 100644 index 000000000000..f579a33ea8c5 --- /dev/null +++ b/WebSecurityScanner/src/V1/ScanRunWarningTrace.php @@ -0,0 +1,69 @@ +google.cloud.websecurityscanner.v1.ScanRunWarningTrace + */ +class ScanRunWarningTrace extends \Google\Protobuf\Internal\Message +{ + /** + * Output only. Indicates the warning code. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanRunWarningTrace.Code code = 1; + */ + private $code = 0; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type int $code + * Output only. Indicates the warning code. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\ScanRunWarningTrace::initOnce(); + parent::__construct($data); + } + + /** + * Output only. Indicates the warning code. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanRunWarningTrace.Code code = 1; + * @return int + */ + public function getCode() + { + return $this->code; + } + + /** + * Output only. Indicates the warning code. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanRunWarningTrace.Code code = 1; + * @param int $var + * @return $this + */ + public function setCode($var) + { + GPBUtil::checkEnum($var, \Google\Cloud\WebSecurityScanner\V1\ScanRunWarningTrace\Code::class); + $this->code = $var; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/ScanRunWarningTrace/Code.php b/WebSecurityScanner/src/V1/ScanRunWarningTrace/Code.php new file mode 100644 index 000000000000..4e6152280e4c --- /dev/null +++ b/WebSecurityScanner/src/V1/ScanRunWarningTrace/Code.php @@ -0,0 +1,90 @@ +google.cloud.websecurityscanner.v1.ScanRunWarningTrace.Code + */ +class Code +{ + /** + * Default value is never used. + * + * Generated from protobuf enum CODE_UNSPECIFIED = 0; + */ + const CODE_UNSPECIFIED = 0; + /** + * Indicates that a scan discovered an unexpectedly low number of URLs. This + * is sometimes caused by complex navigation features or by using a single + * URL for numerous pages. + * + * Generated from protobuf enum INSUFFICIENT_CRAWL_RESULTS = 1; + */ + const INSUFFICIENT_CRAWL_RESULTS = 1; + /** + * Indicates that a scan discovered too many URLs to test, or excessive + * redundant URLs. + * + * Generated from protobuf enum TOO_MANY_CRAWL_RESULTS = 2; + */ + const TOO_MANY_CRAWL_RESULTS = 2; + /** + * Indicates that too many tests have been generated for the scan. Customer + * should try reducing the number of starting URLs, increasing the QPS rate, + * or narrowing down the scope of the scan using the excluded patterns. + * + * Generated from protobuf enum TOO_MANY_FUZZ_TASKS = 3; + */ + const TOO_MANY_FUZZ_TASKS = 3; + /** + * Indicates that a scan is blocked by IAP. + * + * Generated from protobuf enum BLOCKED_BY_IAP = 4; + */ + const BLOCKED_BY_IAP = 4; + /** + * Indicates that no seeds is found for a scan + * + * Generated from protobuf enum NO_STARTING_URL_FOUND_FOR_MANAGED_SCAN = 5; + */ + const NO_STARTING_URL_FOUND_FOR_MANAGED_SCAN = 5; + + private static $valueToName = [ + self::CODE_UNSPECIFIED => 'CODE_UNSPECIFIED', + self::INSUFFICIENT_CRAWL_RESULTS => 'INSUFFICIENT_CRAWL_RESULTS', + self::TOO_MANY_CRAWL_RESULTS => 'TOO_MANY_CRAWL_RESULTS', + self::TOO_MANY_FUZZ_TASKS => 'TOO_MANY_FUZZ_TASKS', + self::BLOCKED_BY_IAP => 'BLOCKED_BY_IAP', + self::NO_STARTING_URL_FOUND_FOR_MANAGED_SCAN => 'NO_STARTING_URL_FOUND_FOR_MANAGED_SCAN', + ]; + + public static function name($value) + { + if (!isset(self::$valueToName[$value])) { + throw new UnexpectedValueException(sprintf( + 'Enum %s has no name defined for value %s', __CLASS__, $value)); + } + return self::$valueToName[$value]; + } + + + public static function value($name) + { + $const = __CLASS__ . '::' . strtoupper($name); + if (!defined($const)) { + throw new UnexpectedValueException(sprintf( + 'Enum %s has no value defined for name %s', __CLASS__, $name)); + } + return constant($const); + } +} + + diff --git a/WebSecurityScanner/src/V1/StartScanRunRequest.php b/WebSecurityScanner/src/V1/StartScanRunRequest.php new file mode 100644 index 000000000000..83dfb78d7a45 --- /dev/null +++ b/WebSecurityScanner/src/V1/StartScanRunRequest.php @@ -0,0 +1,71 @@ +google.cloud.websecurityscanner.v1.StartScanRunRequest + */ +class StartScanRunRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The resource name of the ScanConfig to be used. The name follows the + * format of 'projects/{projectId}/scanConfigs/{scanConfigId}'. + * + * Generated from protobuf field string name = 1; + */ + private $name = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * Required. The resource name of the ScanConfig to be used. The name follows the + * format of 'projects/{projectId}/scanConfigs/{scanConfigId}'. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\WebSecurityScanner::initOnce(); + parent::__construct($data); + } + + /** + * Required. The resource name of the ScanConfig to be used. The name follows the + * format of 'projects/{projectId}/scanConfigs/{scanConfigId}'. + * + * Generated from protobuf field string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Required. The resource name of the ScanConfig to be used. The name follows the + * format of 'projects/{projectId}/scanConfigs/{scanConfigId}'. + * + * Generated from protobuf field string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/StopScanRunRequest.php b/WebSecurityScanner/src/V1/StopScanRunRequest.php new file mode 100644 index 000000000000..3cd5d0b75916 --- /dev/null +++ b/WebSecurityScanner/src/V1/StopScanRunRequest.php @@ -0,0 +1,75 @@ +google.cloud.websecurityscanner.v1.StopScanRunRequest + */ +class StopScanRunRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The resource name of the ScanRun to be stopped. The name follows the + * format of + * 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. + * + * Generated from protobuf field string name = 1; + */ + private $name = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * Required. The resource name of the ScanRun to be stopped. The name follows the + * format of + * 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\WebSecurityScanner::initOnce(); + parent::__construct($data); + } + + /** + * Required. The resource name of the ScanRun to be stopped. The name follows the + * format of + * 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. + * + * Generated from protobuf field string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Required. The resource name of the ScanRun to be stopped. The name follows the + * format of + * 'projects/{projectId}/scanConfigs/{scanConfigId}/scanRuns/{scanRunId}'. + * + * Generated from protobuf field string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/UpdateScanConfigRequest.php b/WebSecurityScanner/src/V1/UpdateScanConfigRequest.php new file mode 100644 index 000000000000..8a91638cd155 --- /dev/null +++ b/WebSecurityScanner/src/V1/UpdateScanConfigRequest.php @@ -0,0 +1,137 @@ +google.cloud.websecurityscanner.v1.UpdateScanConfigRequest + */ +class UpdateScanConfigRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The ScanConfig to be updated. The name field must be set to identify the + * resource to be updated. The values of fields not covered by the mask + * will be ignored. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfig scan_config = 2; + */ + private $scan_config = null; + /** + * Required. The update mask applies to the resource. For the `FieldMask` definition, + * see + * https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#fieldmask + * + * Generated from protobuf field .google.protobuf.FieldMask update_mask = 3; + */ + private $update_mask = null; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Google\Cloud\WebSecurityScanner\V1\ScanConfig $scan_config + * Required. The ScanConfig to be updated. The name field must be set to identify the + * resource to be updated. The values of fields not covered by the mask + * will be ignored. + * @type \Google\Protobuf\FieldMask $update_mask + * Required. The update mask applies to the resource. For the `FieldMask` definition, + * see + * https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#fieldmask + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\WebSecurityScanner::initOnce(); + parent::__construct($data); + } + + /** + * Required. The ScanConfig to be updated. The name field must be set to identify the + * resource to be updated. The values of fields not covered by the mask + * will be ignored. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfig scan_config = 2; + * @return \Google\Cloud\WebSecurityScanner\V1\ScanConfig|null + */ + public function getScanConfig() + { + return $this->scan_config; + } + + public function hasScanConfig() + { + return isset($this->scan_config); + } + + public function clearScanConfig() + { + unset($this->scan_config); + } + + /** + * Required. The ScanConfig to be updated. The name field must be set to identify the + * resource to be updated. The values of fields not covered by the mask + * will be ignored. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.ScanConfig scan_config = 2; + * @param \Google\Cloud\WebSecurityScanner\V1\ScanConfig $var + * @return $this + */ + public function setScanConfig($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\WebSecurityScanner\V1\ScanConfig::class); + $this->scan_config = $var; + + return $this; + } + + /** + * Required. The update mask applies to the resource. For the `FieldMask` definition, + * see + * https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#fieldmask + * + * Generated from protobuf field .google.protobuf.FieldMask update_mask = 3; + * @return \Google\Protobuf\FieldMask|null + */ + public function getUpdateMask() + { + return $this->update_mask; + } + + public function hasUpdateMask() + { + return isset($this->update_mask); + } + + public function clearUpdateMask() + { + unset($this->update_mask); + } + + /** + * Required. The update mask applies to the resource. For the `FieldMask` definition, + * see + * https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#fieldmask + * + * Generated from protobuf field .google.protobuf.FieldMask update_mask = 3; + * @param \Google\Protobuf\FieldMask $var + * @return $this + */ + public function setUpdateMask($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\FieldMask::class); + $this->update_mask = $var; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/ViolatingResource.php b/WebSecurityScanner/src/V1/ViolatingResource.php new file mode 100644 index 000000000000..d166ae12d0d3 --- /dev/null +++ b/WebSecurityScanner/src/V1/ViolatingResource.php @@ -0,0 +1,102 @@ +google.cloud.websecurityscanner.v1.ViolatingResource + */ +class ViolatingResource extends \Google\Protobuf\Internal\Message +{ + /** + * The MIME type of this resource. + * + * Generated from protobuf field string content_type = 1; + */ + private $content_type = ''; + /** + * URL of this violating resource. + * + * Generated from protobuf field string resource_url = 2; + */ + private $resource_url = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $content_type + * The MIME type of this resource. + * @type string $resource_url + * URL of this violating resource. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\FindingAddon::initOnce(); + parent::__construct($data); + } + + /** + * The MIME type of this resource. + * + * Generated from protobuf field string content_type = 1; + * @return string + */ + public function getContentType() + { + return $this->content_type; + } + + /** + * The MIME type of this resource. + * + * Generated from protobuf field string content_type = 1; + * @param string $var + * @return $this + */ + public function setContentType($var) + { + GPBUtil::checkString($var, True); + $this->content_type = $var; + + return $this; + } + + /** + * URL of this violating resource. + * + * Generated from protobuf field string resource_url = 2; + * @return string + */ + public function getResourceUrl() + { + return $this->resource_url; + } + + /** + * URL of this violating resource. + * + * Generated from protobuf field string resource_url = 2; + * @param string $var + * @return $this + */ + public function setResourceUrl($var) + { + GPBUtil::checkString($var, True); + $this->resource_url = $var; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/VulnerableHeaders.php b/WebSecurityScanner/src/V1/VulnerableHeaders.php new file mode 100644 index 000000000000..2410d3d26d00 --- /dev/null +++ b/WebSecurityScanner/src/V1/VulnerableHeaders.php @@ -0,0 +1,101 @@ +google.cloud.websecurityscanner.v1.VulnerableHeaders + */ +class VulnerableHeaders extends \Google\Protobuf\Internal\Message +{ + /** + * List of vulnerable headers. + * + * Generated from protobuf field repeated .google.cloud.websecurityscanner.v1.VulnerableHeaders.Header headers = 1; + */ + private $headers; + /** + * List of missing headers. + * + * Generated from protobuf field repeated .google.cloud.websecurityscanner.v1.VulnerableHeaders.Header missing_headers = 2; + */ + private $missing_headers; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type array<\Google\Cloud\WebSecurityScanner\V1\VulnerableHeaders\Header>|\Google\Protobuf\Internal\RepeatedField $headers + * List of vulnerable headers. + * @type array<\Google\Cloud\WebSecurityScanner\V1\VulnerableHeaders\Header>|\Google\Protobuf\Internal\RepeatedField $missing_headers + * List of missing headers. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\FindingAddon::initOnce(); + parent::__construct($data); + } + + /** + * List of vulnerable headers. + * + * Generated from protobuf field repeated .google.cloud.websecurityscanner.v1.VulnerableHeaders.Header headers = 1; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getHeaders() + { + return $this->headers; + } + + /** + * List of vulnerable headers. + * + * Generated from protobuf field repeated .google.cloud.websecurityscanner.v1.VulnerableHeaders.Header headers = 1; + * @param array<\Google\Cloud\WebSecurityScanner\V1\VulnerableHeaders\Header>|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setHeaders($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\WebSecurityScanner\V1\VulnerableHeaders\Header::class); + $this->headers = $arr; + + return $this; + } + + /** + * List of missing headers. + * + * Generated from protobuf field repeated .google.cloud.websecurityscanner.v1.VulnerableHeaders.Header missing_headers = 2; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getMissingHeaders() + { + return $this->missing_headers; + } + + /** + * List of missing headers. + * + * Generated from protobuf field repeated .google.cloud.websecurityscanner.v1.VulnerableHeaders.Header missing_headers = 2; + * @param array<\Google\Cloud\WebSecurityScanner\V1\VulnerableHeaders\Header>|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setMissingHeaders($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\WebSecurityScanner\V1\VulnerableHeaders\Header::class); + $this->missing_headers = $arr; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/VulnerableHeaders/Header.php b/WebSecurityScanner/src/V1/VulnerableHeaders/Header.php new file mode 100644 index 000000000000..9ab083d9659d --- /dev/null +++ b/WebSecurityScanner/src/V1/VulnerableHeaders/Header.php @@ -0,0 +1,102 @@ +google.cloud.websecurityscanner.v1.VulnerableHeaders.Header + */ +class Header extends \Google\Protobuf\Internal\Message +{ + /** + * Header name. + * + * Generated from protobuf field string name = 1; + */ + private $name = ''; + /** + * Header value. + * + * Generated from protobuf field string value = 2; + */ + private $value = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * Header name. + * @type string $value + * Header value. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\FindingAddon::initOnce(); + parent::__construct($data); + } + + /** + * Header name. + * + * Generated from protobuf field string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Header name. + * + * Generated from protobuf field string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * Header value. + * + * Generated from protobuf field string value = 2; + * @return string + */ + public function getValue() + { + return $this->value; + } + + /** + * Header value. + * + * Generated from protobuf field string value = 2; + * @param string $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkString($var, True); + $this->value = $var; + + return $this; + } + +} + + diff --git a/WebSecurityScanner/src/V1/VulnerableParameters.php b/WebSecurityScanner/src/V1/VulnerableParameters.php new file mode 100644 index 000000000000..f6f79dc863a7 --- /dev/null +++ b/WebSecurityScanner/src/V1/VulnerableParameters.php @@ -0,0 +1,67 @@ +google.cloud.websecurityscanner.v1.VulnerableParameters + */ +class VulnerableParameters extends \Google\Protobuf\Internal\Message +{ + /** + * The vulnerable parameter names. + * + * Generated from protobuf field repeated string parameter_names = 1; + */ + private $parameter_names; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type array|\Google\Protobuf\Internal\RepeatedField $parameter_names + * The vulnerable parameter names. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\FindingAddon::initOnce(); + parent::__construct($data); + } + + /** + * The vulnerable parameter names. + * + * Generated from protobuf field repeated string parameter_names = 1; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getParameterNames() + { + return $this->parameter_names; + } + + /** + * The vulnerable parameter names. + * + * Generated from protobuf field repeated string parameter_names = 1; + * @param array|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setParameterNames($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING); + $this->parameter_names = $arr; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/WebSecurityScannerGrpcClient.php b/WebSecurityScanner/src/V1/WebSecurityScannerGrpcClient.php new file mode 100644 index 000000000000..932cde91e5cd --- /dev/null +++ b/WebSecurityScanner/src/V1/WebSecurityScannerGrpcClient.php @@ -0,0 +1,233 @@ +_simpleRequest('/google.cloud.websecurityscanner.v1.WebSecurityScanner/CreateScanConfig', + $argument, + ['\Google\Cloud\WebSecurityScanner\V1\ScanConfig', 'decode'], + $metadata, $options); + } + + /** + * Deletes an existing ScanConfig and its child resources. + * @param \Google\Cloud\WebSecurityScanner\V1\DeleteScanConfigRequest $argument input argument + * @param array $metadata metadata + * @param array $options call options + * @return \Grpc\UnaryCall + */ + public function DeleteScanConfig(\Google\Cloud\WebSecurityScanner\V1\DeleteScanConfigRequest $argument, + $metadata = [], $options = []) { + return $this->_simpleRequest('/google.cloud.websecurityscanner.v1.WebSecurityScanner/DeleteScanConfig', + $argument, + ['\Google\Protobuf\GPBEmpty', 'decode'], + $metadata, $options); + } + + /** + * Gets a ScanConfig. + * @param \Google\Cloud\WebSecurityScanner\V1\GetScanConfigRequest $argument input argument + * @param array $metadata metadata + * @param array $options call options + * @return \Grpc\UnaryCall + */ + public function GetScanConfig(\Google\Cloud\WebSecurityScanner\V1\GetScanConfigRequest $argument, + $metadata = [], $options = []) { + return $this->_simpleRequest('/google.cloud.websecurityscanner.v1.WebSecurityScanner/GetScanConfig', + $argument, + ['\Google\Cloud\WebSecurityScanner\V1\ScanConfig', 'decode'], + $metadata, $options); + } + + /** + * Lists ScanConfigs under a given project. + * @param \Google\Cloud\WebSecurityScanner\V1\ListScanConfigsRequest $argument input argument + * @param array $metadata metadata + * @param array $options call options + * @return \Grpc\UnaryCall + */ + public function ListScanConfigs(\Google\Cloud\WebSecurityScanner\V1\ListScanConfigsRequest $argument, + $metadata = [], $options = []) { + return $this->_simpleRequest('/google.cloud.websecurityscanner.v1.WebSecurityScanner/ListScanConfigs', + $argument, + ['\Google\Cloud\WebSecurityScanner\V1\ListScanConfigsResponse', 'decode'], + $metadata, $options); + } + + /** + * Updates a ScanConfig. This method support partial update of a ScanConfig. + * @param \Google\Cloud\WebSecurityScanner\V1\UpdateScanConfigRequest $argument input argument + * @param array $metadata metadata + * @param array $options call options + * @return \Grpc\UnaryCall + */ + public function UpdateScanConfig(\Google\Cloud\WebSecurityScanner\V1\UpdateScanConfigRequest $argument, + $metadata = [], $options = []) { + return $this->_simpleRequest('/google.cloud.websecurityscanner.v1.WebSecurityScanner/UpdateScanConfig', + $argument, + ['\Google\Cloud\WebSecurityScanner\V1\ScanConfig', 'decode'], + $metadata, $options); + } + + /** + * Start a ScanRun according to the given ScanConfig. + * @param \Google\Cloud\WebSecurityScanner\V1\StartScanRunRequest $argument input argument + * @param array $metadata metadata + * @param array $options call options + * @return \Grpc\UnaryCall + */ + public function StartScanRun(\Google\Cloud\WebSecurityScanner\V1\StartScanRunRequest $argument, + $metadata = [], $options = []) { + return $this->_simpleRequest('/google.cloud.websecurityscanner.v1.WebSecurityScanner/StartScanRun', + $argument, + ['\Google\Cloud\WebSecurityScanner\V1\ScanRun', 'decode'], + $metadata, $options); + } + + /** + * Gets a ScanRun. + * @param \Google\Cloud\WebSecurityScanner\V1\GetScanRunRequest $argument input argument + * @param array $metadata metadata + * @param array $options call options + * @return \Grpc\UnaryCall + */ + public function GetScanRun(\Google\Cloud\WebSecurityScanner\V1\GetScanRunRequest $argument, + $metadata = [], $options = []) { + return $this->_simpleRequest('/google.cloud.websecurityscanner.v1.WebSecurityScanner/GetScanRun', + $argument, + ['\Google\Cloud\WebSecurityScanner\V1\ScanRun', 'decode'], + $metadata, $options); + } + + /** + * Lists ScanRuns under a given ScanConfig, in descending order of ScanRun + * stop time. + * @param \Google\Cloud\WebSecurityScanner\V1\ListScanRunsRequest $argument input argument + * @param array $metadata metadata + * @param array $options call options + * @return \Grpc\UnaryCall + */ + public function ListScanRuns(\Google\Cloud\WebSecurityScanner\V1\ListScanRunsRequest $argument, + $metadata = [], $options = []) { + return $this->_simpleRequest('/google.cloud.websecurityscanner.v1.WebSecurityScanner/ListScanRuns', + $argument, + ['\Google\Cloud\WebSecurityScanner\V1\ListScanRunsResponse', 'decode'], + $metadata, $options); + } + + /** + * Stops a ScanRun. The stopped ScanRun is returned. + * @param \Google\Cloud\WebSecurityScanner\V1\StopScanRunRequest $argument input argument + * @param array $metadata metadata + * @param array $options call options + * @return \Grpc\UnaryCall + */ + public function StopScanRun(\Google\Cloud\WebSecurityScanner\V1\StopScanRunRequest $argument, + $metadata = [], $options = []) { + return $this->_simpleRequest('/google.cloud.websecurityscanner.v1.WebSecurityScanner/StopScanRun', + $argument, + ['\Google\Cloud\WebSecurityScanner\V1\ScanRun', 'decode'], + $metadata, $options); + } + + /** + * List CrawledUrls under a given ScanRun. + * @param \Google\Cloud\WebSecurityScanner\V1\ListCrawledUrlsRequest $argument input argument + * @param array $metadata metadata + * @param array $options call options + * @return \Grpc\UnaryCall + */ + public function ListCrawledUrls(\Google\Cloud\WebSecurityScanner\V1\ListCrawledUrlsRequest $argument, + $metadata = [], $options = []) { + return $this->_simpleRequest('/google.cloud.websecurityscanner.v1.WebSecurityScanner/ListCrawledUrls', + $argument, + ['\Google\Cloud\WebSecurityScanner\V1\ListCrawledUrlsResponse', 'decode'], + $metadata, $options); + } + + /** + * Gets a Finding. + * @param \Google\Cloud\WebSecurityScanner\V1\GetFindingRequest $argument input argument + * @param array $metadata metadata + * @param array $options call options + * @return \Grpc\UnaryCall + */ + public function GetFinding(\Google\Cloud\WebSecurityScanner\V1\GetFindingRequest $argument, + $metadata = [], $options = []) { + return $this->_simpleRequest('/google.cloud.websecurityscanner.v1.WebSecurityScanner/GetFinding', + $argument, + ['\Google\Cloud\WebSecurityScanner\V1\Finding', 'decode'], + $metadata, $options); + } + + /** + * List Findings under a given ScanRun. + * @param \Google\Cloud\WebSecurityScanner\V1\ListFindingsRequest $argument input argument + * @param array $metadata metadata + * @param array $options call options + * @return \Grpc\UnaryCall + */ + public function ListFindings(\Google\Cloud\WebSecurityScanner\V1\ListFindingsRequest $argument, + $metadata = [], $options = []) { + return $this->_simpleRequest('/google.cloud.websecurityscanner.v1.WebSecurityScanner/ListFindings', + $argument, + ['\Google\Cloud\WebSecurityScanner\V1\ListFindingsResponse', 'decode'], + $metadata, $options); + } + + /** + * List all FindingTypeStats under a given ScanRun. + * @param \Google\Cloud\WebSecurityScanner\V1\ListFindingTypeStatsRequest $argument input argument + * @param array $metadata metadata + * @param array $options call options + * @return \Grpc\UnaryCall + */ + public function ListFindingTypeStats(\Google\Cloud\WebSecurityScanner\V1\ListFindingTypeStatsRequest $argument, + $metadata = [], $options = []) { + return $this->_simpleRequest('/google.cloud.websecurityscanner.v1.WebSecurityScanner/ListFindingTypeStats', + $argument, + ['\Google\Cloud\WebSecurityScanner\V1\ListFindingTypeStatsResponse', 'decode'], + $metadata, $options); + } + +} diff --git a/WebSecurityScanner/src/V1/Xss.php b/WebSecurityScanner/src/V1/Xss.php new file mode 100644 index 000000000000..dd360613a914 --- /dev/null +++ b/WebSecurityScanner/src/V1/Xss.php @@ -0,0 +1,169 @@ +google.cloud.websecurityscanner.v1.Xss + */ +class Xss extends \Google\Protobuf\Internal\Message +{ + /** + * Stack traces leading to the point where the XSS occurred. + * + * Generated from protobuf field repeated string stack_traces = 1; + */ + private $stack_traces; + /** + * An error message generated by a javascript breakage. + * + * Generated from protobuf field string error_message = 2; + */ + private $error_message = ''; + /** + * The attack vector of the payload triggering this XSS. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.Xss.AttackVector attack_vector = 3; + */ + private $attack_vector = 0; + /** + * The reproduction url for the seeding POST request of a Stored XSS. + * + * Generated from protobuf field string stored_xss_seeding_url = 4; + */ + private $stored_xss_seeding_url = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type array|\Google\Protobuf\Internal\RepeatedField $stack_traces + * Stack traces leading to the point where the XSS occurred. + * @type string $error_message + * An error message generated by a javascript breakage. + * @type int $attack_vector + * The attack vector of the payload triggering this XSS. + * @type string $stored_xss_seeding_url + * The reproduction url for the seeding POST request of a Stored XSS. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\FindingAddon::initOnce(); + parent::__construct($data); + } + + /** + * Stack traces leading to the point where the XSS occurred. + * + * Generated from protobuf field repeated string stack_traces = 1; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getStackTraces() + { + return $this->stack_traces; + } + + /** + * Stack traces leading to the point where the XSS occurred. + * + * Generated from protobuf field repeated string stack_traces = 1; + * @param array|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setStackTraces($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING); + $this->stack_traces = $arr; + + return $this; + } + + /** + * An error message generated by a javascript breakage. + * + * Generated from protobuf field string error_message = 2; + * @return string + */ + public function getErrorMessage() + { + return $this->error_message; + } + + /** + * An error message generated by a javascript breakage. + * + * Generated from protobuf field string error_message = 2; + * @param string $var + * @return $this + */ + public function setErrorMessage($var) + { + GPBUtil::checkString($var, True); + $this->error_message = $var; + + return $this; + } + + /** + * The attack vector of the payload triggering this XSS. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.Xss.AttackVector attack_vector = 3; + * @return int + */ + public function getAttackVector() + { + return $this->attack_vector; + } + + /** + * The attack vector of the payload triggering this XSS. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.Xss.AttackVector attack_vector = 3; + * @param int $var + * @return $this + */ + public function setAttackVector($var) + { + GPBUtil::checkEnum($var, \Google\Cloud\WebSecurityScanner\V1\Xss\AttackVector::class); + $this->attack_vector = $var; + + return $this; + } + + /** + * The reproduction url for the seeding POST request of a Stored XSS. + * + * Generated from protobuf field string stored_xss_seeding_url = 4; + * @return string + */ + public function getStoredXssSeedingUrl() + { + return $this->stored_xss_seeding_url; + } + + /** + * The reproduction url for the seeding POST request of a Stored XSS. + * + * Generated from protobuf field string stored_xss_seeding_url = 4; + * @param string $var + * @return $this + */ + public function setStoredXssSeedingUrl($var) + { + GPBUtil::checkString($var, True); + $this->stored_xss_seeding_url = $var; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/Xss/AttackVector.php b/WebSecurityScanner/src/V1/Xss/AttackVector.php new file mode 100644 index 000000000000..8888e4029e36 --- /dev/null +++ b/WebSecurityScanner/src/V1/Xss/AttackVector.php @@ -0,0 +1,154 @@ +google.cloud.websecurityscanner.v1.Xss.AttackVector + */ +class AttackVector +{ + /** + * Unknown attack vector. + * + * Generated from protobuf enum ATTACK_VECTOR_UNSPECIFIED = 0; + */ + const ATTACK_VECTOR_UNSPECIFIED = 0; + /** + * The attack comes from fuzzing the browser's localStorage. + * + * Generated from protobuf enum LOCAL_STORAGE = 1; + */ + const LOCAL_STORAGE = 1; + /** + * The attack comes from fuzzing the browser's sessionStorage. + * + * Generated from protobuf enum SESSION_STORAGE = 2; + */ + const SESSION_STORAGE = 2; + /** + * The attack comes from fuzzing the window's name property. + * + * Generated from protobuf enum WINDOW_NAME = 3; + */ + const WINDOW_NAME = 3; + /** + * The attack comes from fuzzing the referrer property. + * + * Generated from protobuf enum REFERRER = 4; + */ + const REFERRER = 4; + /** + * The attack comes from fuzzing an input element. + * + * Generated from protobuf enum FORM_INPUT = 5; + */ + const FORM_INPUT = 5; + /** + * The attack comes from fuzzing the browser's cookies. + * + * Generated from protobuf enum COOKIE = 6; + */ + const COOKIE = 6; + /** + * The attack comes from hijacking the post messaging mechanism. + * + * Generated from protobuf enum POST_MESSAGE = 7; + */ + const POST_MESSAGE = 7; + /** + * The attack comes from fuzzing parameters in the url. + * + * Generated from protobuf enum GET_PARAMETERS = 8; + */ + const GET_PARAMETERS = 8; + /** + * The attack comes from fuzzing the fragment in the url. + * + * Generated from protobuf enum URL_FRAGMENT = 9; + */ + const URL_FRAGMENT = 9; + /** + * The attack comes from fuzzing the HTML comments. + * + * Generated from protobuf enum HTML_COMMENT = 10; + */ + const HTML_COMMENT = 10; + /** + * The attack comes from fuzzing the POST parameters. + * + * Generated from protobuf enum POST_PARAMETERS = 11; + */ + const POST_PARAMETERS = 11; + /** + * The attack comes from fuzzing the protocol. + * + * Generated from protobuf enum PROTOCOL = 12; + */ + const PROTOCOL = 12; + /** + * The attack comes from the server side and is stored. + * + * Generated from protobuf enum STORED_XSS = 13; + */ + const STORED_XSS = 13; + /** + * The attack is a Same-Origin Method Execution attack via a GET parameter. + * + * Generated from protobuf enum SAME_ORIGIN = 14; + */ + const SAME_ORIGIN = 14; + /** + * The attack payload is received from a third-party host via a URL that is + * user-controllable + * + * Generated from protobuf enum USER_CONTROLLABLE_URL = 15; + */ + const USER_CONTROLLABLE_URL = 15; + + private static $valueToName = [ + self::ATTACK_VECTOR_UNSPECIFIED => 'ATTACK_VECTOR_UNSPECIFIED', + self::LOCAL_STORAGE => 'LOCAL_STORAGE', + self::SESSION_STORAGE => 'SESSION_STORAGE', + self::WINDOW_NAME => 'WINDOW_NAME', + self::REFERRER => 'REFERRER', + self::FORM_INPUT => 'FORM_INPUT', + self::COOKIE => 'COOKIE', + self::POST_MESSAGE => 'POST_MESSAGE', + self::GET_PARAMETERS => 'GET_PARAMETERS', + self::URL_FRAGMENT => 'URL_FRAGMENT', + self::HTML_COMMENT => 'HTML_COMMENT', + self::POST_PARAMETERS => 'POST_PARAMETERS', + self::PROTOCOL => 'PROTOCOL', + self::STORED_XSS => 'STORED_XSS', + self::SAME_ORIGIN => 'SAME_ORIGIN', + self::USER_CONTROLLABLE_URL => 'USER_CONTROLLABLE_URL', + ]; + + public static function name($value) + { + if (!isset(self::$valueToName[$value])) { + throw new UnexpectedValueException(sprintf( + 'Enum %s has no name defined for value %s', __CLASS__, $value)); + } + return self::$valueToName[$value]; + } + + + public static function value($name) + { + $const = __CLASS__ . '::' . strtoupper($name); + if (!defined($const)) { + throw new UnexpectedValueException(sprintf( + 'Enum %s has no value defined for name %s', __CLASS__, $name)); + } + return constant($const); + } +} + + diff --git a/WebSecurityScanner/src/V1/Xxe.php b/WebSecurityScanner/src/V1/Xxe.php new file mode 100644 index 000000000000..2fb63902fd56 --- /dev/null +++ b/WebSecurityScanner/src/V1/Xxe.php @@ -0,0 +1,105 @@ +google.cloud.websecurityscanner.v1.Xxe + */ +class Xxe extends \Google\Protobuf\Internal\Message +{ + /** + * The XML string that triggered the XXE vulnerability. Non-payload values + * might be redacted. + * + * Generated from protobuf field string payload_value = 1; + */ + private $payload_value = ''; + /** + * Location within the request where the payload was placed. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.Xxe.Location payload_location = 2; + */ + private $payload_location = 0; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $payload_value + * The XML string that triggered the XXE vulnerability. Non-payload values + * might be redacted. + * @type int $payload_location + * Location within the request where the payload was placed. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Websecurityscanner\V1\FindingAddon::initOnce(); + parent::__construct($data); + } + + /** + * The XML string that triggered the XXE vulnerability. Non-payload values + * might be redacted. + * + * Generated from protobuf field string payload_value = 1; + * @return string + */ + public function getPayloadValue() + { + return $this->payload_value; + } + + /** + * The XML string that triggered the XXE vulnerability. Non-payload values + * might be redacted. + * + * Generated from protobuf field string payload_value = 1; + * @param string $var + * @return $this + */ + public function setPayloadValue($var) + { + GPBUtil::checkString($var, True); + $this->payload_value = $var; + + return $this; + } + + /** + * Location within the request where the payload was placed. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.Xxe.Location payload_location = 2; + * @return int + */ + public function getPayloadLocation() + { + return $this->payload_location; + } + + /** + * Location within the request where the payload was placed. + * + * Generated from protobuf field .google.cloud.websecurityscanner.v1.Xxe.Location payload_location = 2; + * @param int $var + * @return $this + */ + public function setPayloadLocation($var) + { + GPBUtil::checkEnum($var, \Google\Cloud\WebSecurityScanner\V1\Xxe\Location::class); + $this->payload_location = $var; + + return $this; + } + +} + diff --git a/WebSecurityScanner/src/V1/Xxe/Location.php b/WebSecurityScanner/src/V1/Xxe/Location.php new file mode 100644 index 000000000000..14f66a9a6112 --- /dev/null +++ b/WebSecurityScanner/src/V1/Xxe/Location.php @@ -0,0 +1,55 @@ +google.cloud.websecurityscanner.v1.Xxe.Location + */ +class Location +{ + /** + * Unknown Location. + * + * Generated from protobuf enum LOCATION_UNSPECIFIED = 0; + */ + const LOCATION_UNSPECIFIED = 0; + /** + * The XML payload replaced the complete request body. + * + * Generated from protobuf enum COMPLETE_REQUEST_BODY = 1; + */ + const COMPLETE_REQUEST_BODY = 1; + + private static $valueToName = [ + self::LOCATION_UNSPECIFIED => 'LOCATION_UNSPECIFIED', + self::COMPLETE_REQUEST_BODY => 'COMPLETE_REQUEST_BODY', + ]; + + public static function name($value) + { + if (!isset(self::$valueToName[$value])) { + throw new UnexpectedValueException(sprintf( + 'Enum %s has no name defined for value %s', __CLASS__, $value)); + } + return self::$valueToName[$value]; + } + + + public static function value($name) + { + $const = __CLASS__ . '::' . strtoupper($name); + if (!defined($const)) { + throw new UnexpectedValueException(sprintf( + 'Enum %s has no value defined for name %s', __CLASS__, $name)); + } + return constant($const); + } +} + + diff --git a/WebSecurityScanner/src/V1/gapic_metadata.json b/WebSecurityScanner/src/V1/gapic_metadata.json new file mode 100644 index 000000000000..d8c19414ac9f --- /dev/null +++ b/WebSecurityScanner/src/V1/gapic_metadata.json @@ -0,0 +1,83 @@ +{ + "schema": "1.0", + "comment": "This file maps proto services\/RPCs to the corresponding library clients\/methods", + "language": "php", + "protoPackage": "google.cloud.websecurityscanner.v1", + "libraryPackage": "Google\\Cloud\\WebSecurityScanner\\V1", + "services": { + "WebSecurityScanner": { + "clients": { + "grpc": { + "libraryClient": "WebSecurityScannerGapicClient", + "rpcs": { + "CreateScanConfig": { + "methods": [ + "createScanConfig" + ] + }, + "DeleteScanConfig": { + "methods": [ + "deleteScanConfig" + ] + }, + "GetFinding": { + "methods": [ + "getFinding" + ] + }, + "GetScanConfig": { + "methods": [ + "getScanConfig" + ] + }, + "GetScanRun": { + "methods": [ + "getScanRun" + ] + }, + "ListCrawledUrls": { + "methods": [ + "listCrawledUrls" + ] + }, + "ListFindingTypeStats": { + "methods": [ + "listFindingTypeStats" + ] + }, + "ListFindings": { + "methods": [ + "listFindings" + ] + }, + "ListScanConfigs": { + "methods": [ + "listScanConfigs" + ] + }, + "ListScanRuns": { + "methods": [ + "listScanRuns" + ] + }, + "StartScanRun": { + "methods": [ + "startScanRun" + ] + }, + "StopScanRun": { + "methods": [ + "stopScanRun" + ] + }, + "UpdateScanConfig": { + "methods": [ + "updateScanConfig" + ] + } + } + } + } + } + } +} \ No newline at end of file diff --git a/WebSecurityScanner/src/V1/resources/web_security_scanner_client_config.json b/WebSecurityScanner/src/V1/resources/web_security_scanner_client_config.json new file mode 100644 index 000000000000..29d08ef04d1c --- /dev/null +++ b/WebSecurityScanner/src/V1/resources/web_security_scanner_client_config.json @@ -0,0 +1,110 @@ +{ + "interfaces": { + "google.cloud.websecurityscanner.v1.WebSecurityScanner": { + "retry_codes": { + "no_retry_codes": [], + "no_retry_1_codes": [], + "retry_policy_1_codes": [ + "DEADLINE_EXCEEDED", + "UNAVAILABLE" + ] + }, + "retry_params": { + "no_retry_params": { + "initial_retry_delay_millis": 0, + "retry_delay_multiplier": 0.0, + "max_retry_delay_millis": 0, + "initial_rpc_timeout_millis": 0, + "rpc_timeout_multiplier": 1.0, + "max_rpc_timeout_millis": 0, + "total_timeout_millis": 0 + }, + "no_retry_1_params": { + "initial_retry_delay_millis": 0, + "retry_delay_multiplier": 0.0, + "max_retry_delay_millis": 0, + "initial_rpc_timeout_millis": 600000, + "rpc_timeout_multiplier": 1.0, + "max_rpc_timeout_millis": 600000, + "total_timeout_millis": 600000 + }, + "retry_policy_1_params": { + "initial_retry_delay_millis": 100, + "retry_delay_multiplier": 1.3, + "max_retry_delay_millis": 60000, + "initial_rpc_timeout_millis": 600000, + "rpc_timeout_multiplier": 1.0, + "max_rpc_timeout_millis": 600000, + "total_timeout_millis": 600000 + } + }, + "methods": { + "CreateScanConfig": { + "timeout_millis": 600000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + }, + "DeleteScanConfig": { + "timeout_millis": 600000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "GetFinding": { + "timeout_millis": 600000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "GetScanConfig": { + "timeout_millis": 600000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "GetScanRun": { + "timeout_millis": 600000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "ListCrawledUrls": { + "timeout_millis": 600000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "ListFindingTypeStats": { + "timeout_millis": 600000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "ListFindings": { + "timeout_millis": 600000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "ListScanConfigs": { + "timeout_millis": 600000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "ListScanRuns": { + "timeout_millis": 600000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "StartScanRun": { + "timeout_millis": 600000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + }, + "StopScanRun": { + "timeout_millis": 600000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + }, + "UpdateScanConfig": { + "timeout_millis": 600000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + } + } + } + } +} diff --git a/WebSecurityScanner/src/V1/resources/web_security_scanner_descriptor_config.php b/WebSecurityScanner/src/V1/resources/web_security_scanner_descriptor_config.php new file mode 100644 index 000000000000..d64b2e48f719 --- /dev/null +++ b/WebSecurityScanner/src/V1/resources/web_security_scanner_descriptor_config.php @@ -0,0 +1,197 @@ + [ + 'google.cloud.websecurityscanner.v1.WebSecurityScanner' => [ + 'CreateScanConfig' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\WebSecurityScanner\V1\ScanConfig', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'DeleteScanConfig' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetFinding' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\WebSecurityScanner\V1\Finding', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetScanConfig' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\WebSecurityScanner\V1\ScanConfig', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetScanRun' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\WebSecurityScanner\V1\ScanRun', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'ListCrawledUrls' => [ + 'pageStreaming' => [ + 'requestPageTokenGetMethod' => 'getPageToken', + 'requestPageTokenSetMethod' => 'setPageToken', + 'requestPageSizeGetMethod' => 'getPageSize', + 'requestPageSizeSetMethod' => 'setPageSize', + 'responsePageTokenGetMethod' => 'getNextPageToken', + 'resourcesGetMethod' => 'getCrawledUrls', + ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\WebSecurityScanner\V1\ListCrawledUrlsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'ListFindingTypeStats' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\WebSecurityScanner\V1\ListFindingTypeStatsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'ListFindings' => [ + 'pageStreaming' => [ + 'requestPageTokenGetMethod' => 'getPageToken', + 'requestPageTokenSetMethod' => 'setPageToken', + 'requestPageSizeGetMethod' => 'getPageSize', + 'requestPageSizeSetMethod' => 'setPageSize', + 'responsePageTokenGetMethod' => 'getNextPageToken', + 'resourcesGetMethod' => 'getFindings', + ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\WebSecurityScanner\V1\ListFindingsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'ListScanConfigs' => [ + 'pageStreaming' => [ + 'requestPageTokenGetMethod' => 'getPageToken', + 'requestPageTokenSetMethod' => 'setPageToken', + 'requestPageSizeGetMethod' => 'getPageSize', + 'requestPageSizeSetMethod' => 'setPageSize', + 'responsePageTokenGetMethod' => 'getNextPageToken', + 'resourcesGetMethod' => 'getScanConfigs', + ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\WebSecurityScanner\V1\ListScanConfigsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'ListScanRuns' => [ + 'pageStreaming' => [ + 'requestPageTokenGetMethod' => 'getPageToken', + 'requestPageTokenSetMethod' => 'setPageToken', + 'requestPageSizeGetMethod' => 'getPageSize', + 'requestPageSizeSetMethod' => 'setPageSize', + 'responsePageTokenGetMethod' => 'getNextPageToken', + 'resourcesGetMethod' => 'getScanRuns', + ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\WebSecurityScanner\V1\ListScanRunsResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], + 'StartScanRun' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\WebSecurityScanner\V1\ScanRun', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'StopScanRun' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\WebSecurityScanner\V1\ScanRun', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'UpdateScanConfig' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\WebSecurityScanner\V1\ScanConfig', + 'headerParams' => [ + [ + 'keyName' => 'scan_config.name', + 'fieldAccessors' => [ + 'getScanConfig', + 'getName', + ], + ], + ], + ], + ], + ], +]; diff --git a/WebSecurityScanner/src/V1/resources/web_security_scanner_rest_client_config.php b/WebSecurityScanner/src/V1/resources/web_security_scanner_rest_client_config.php new file mode 100644 index 000000000000..c38e23bc436f --- /dev/null +++ b/WebSecurityScanner/src/V1/resources/web_security_scanner_rest_client_config.php @@ -0,0 +1,157 @@ + [ + 'google.cloud.websecurityscanner.v1.WebSecurityScanner' => [ + 'CreateScanConfig' => [ + 'method' => 'post', + 'uriTemplate' => '/v1/{parent=projects/*}/scanConfigs', + 'body' => 'scan_config', + 'placeholders' => [ + 'parent' => [ + 'getters' => [ + 'getParent', + ], + ], + ], + ], + 'DeleteScanConfig' => [ + 'method' => 'delete', + 'uriTemplate' => '/v1/{name=projects/*/scanConfigs/*}', + 'placeholders' => [ + 'name' => [ + 'getters' => [ + 'getName', + ], + ], + ], + ], + 'GetFinding' => [ + 'method' => 'get', + 'uriTemplate' => '/v1/{name=projects/*/scanConfigs/*/scanRuns/*/findings/*}', + 'placeholders' => [ + 'name' => [ + 'getters' => [ + 'getName', + ], + ], + ], + ], + 'GetScanConfig' => [ + 'method' => 'get', + 'uriTemplate' => '/v1/{name=projects/*/scanConfigs/*}', + 'placeholders' => [ + 'name' => [ + 'getters' => [ + 'getName', + ], + ], + ], + ], + 'GetScanRun' => [ + 'method' => 'get', + 'uriTemplate' => '/v1/{name=projects/*/scanConfigs/*/scanRuns/*}', + 'placeholders' => [ + 'name' => [ + 'getters' => [ + 'getName', + ], + ], + ], + ], + 'ListCrawledUrls' => [ + 'method' => 'get', + 'uriTemplate' => '/v1/{parent=projects/*/scanConfigs/*/scanRuns/*}/crawledUrls', + 'placeholders' => [ + 'parent' => [ + 'getters' => [ + 'getParent', + ], + ], + ], + ], + 'ListFindingTypeStats' => [ + 'method' => 'get', + 'uriTemplate' => '/v1/{parent=projects/*/scanConfigs/*/scanRuns/*}/findingTypeStats', + 'placeholders' => [ + 'parent' => [ + 'getters' => [ + 'getParent', + ], + ], + ], + ], + 'ListFindings' => [ + 'method' => 'get', + 'uriTemplate' => '/v1/{parent=projects/*/scanConfigs/*/scanRuns/*}/findings', + 'placeholders' => [ + 'parent' => [ + 'getters' => [ + 'getParent', + ], + ], + ], + ], + 'ListScanConfigs' => [ + 'method' => 'get', + 'uriTemplate' => '/v1/{parent=projects/*}/scanConfigs', + 'placeholders' => [ + 'parent' => [ + 'getters' => [ + 'getParent', + ], + ], + ], + ], + 'ListScanRuns' => [ + 'method' => 'get', + 'uriTemplate' => '/v1/{parent=projects/*/scanConfigs/*}/scanRuns', + 'placeholders' => [ + 'parent' => [ + 'getters' => [ + 'getParent', + ], + ], + ], + ], + 'StartScanRun' => [ + 'method' => 'post', + 'uriTemplate' => '/v1/{name=projects/*/scanConfigs/*}:start', + 'body' => '*', + 'placeholders' => [ + 'name' => [ + 'getters' => [ + 'getName', + ], + ], + ], + ], + 'StopScanRun' => [ + 'method' => 'post', + 'uriTemplate' => '/v1/{name=projects/*/scanConfigs/*/scanRuns/*}:stop', + 'body' => '*', + 'placeholders' => [ + 'name' => [ + 'getters' => [ + 'getName', + ], + ], + ], + ], + 'UpdateScanConfig' => [ + 'method' => 'patch', + 'uriTemplate' => '/v1/{scan_config.name=projects/*/scanConfigs/*}', + 'body' => 'scan_config', + 'placeholders' => [ + 'scan_config.name' => [ + 'getters' => [ + 'getScanConfig', + 'getName', + ], + ], + ], + ], + ], + ], + 'numericEnums' => true, +]; diff --git a/WebSecurityScanner/tests/Unit/V1/Client/WebSecurityScannerClientTest.php b/WebSecurityScanner/tests/Unit/V1/Client/WebSecurityScannerClientTest.php new file mode 100644 index 000000000000..c9d375b48fdc --- /dev/null +++ b/WebSecurityScanner/tests/Unit/V1/Client/WebSecurityScannerClientTest.php @@ -0,0 +1,944 @@ +getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + } + + /** @return WebSecurityScannerClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new WebSecurityScannerClient($options); + } + + /** @test */ + public function createScanConfigTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $maxQps = 844445913; + $managedScan = false; + $staticIpScan = true; + $ignoreHttpStatusErrors = true; + $expectedResponse = new ScanConfig(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setMaxQps($maxQps); + $expectedResponse->setManagedScan($managedScan); + $expectedResponse->setStaticIpScan($staticIpScan); + $expectedResponse->setIgnoreHttpStatusErrors($ignoreHttpStatusErrors); + $transport->addResponse($expectedResponse); + $request = new CreateScanConfigRequest(); + $response = $gapicClient->createScanConfig($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.websecurityscanner.v1.WebSecurityScanner/CreateScanConfig', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createScanConfigExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new CreateScanConfigRequest(); + try { + $gapicClient->createScanConfig($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteScanConfigTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + $request = new DeleteScanConfigRequest(); + $gapicClient->deleteScanConfig($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.websecurityscanner.v1.WebSecurityScanner/DeleteScanConfig', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteScanConfigExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new DeleteScanConfigRequest(); + try { + $gapicClient->deleteScanConfig($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getFindingTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $findingType = 'findingType274496048'; + $httpMethod = 'httpMethod820747384'; + $fuzzedUrl = 'fuzzedUrl-2120677666'; + $body = 'body3029410'; + $description = 'description-1724546052'; + $reproductionUrl = 'reproductionUrl-244934180'; + $frameUrl = 'frameUrl545464221'; + $finalUrl = 'finalUrl355601190'; + $trackingId = 'trackingId1878901667'; + $expectedResponse = new Finding(); + $expectedResponse->setName($name2); + $expectedResponse->setFindingType($findingType); + $expectedResponse->setHttpMethod($httpMethod); + $expectedResponse->setFuzzedUrl($fuzzedUrl); + $expectedResponse->setBody($body); + $expectedResponse->setDescription($description); + $expectedResponse->setReproductionUrl($reproductionUrl); + $expectedResponse->setFrameUrl($frameUrl); + $expectedResponse->setFinalUrl($finalUrl); + $expectedResponse->setTrackingId($trackingId); + $transport->addResponse($expectedResponse); + $request = new GetFindingRequest(); + $response = $gapicClient->getFinding($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.websecurityscanner.v1.WebSecurityScanner/GetFinding', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getFindingExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new GetFindingRequest(); + try { + $gapicClient->getFinding($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getScanConfigTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $displayName = 'displayName1615086568'; + $maxQps = 844445913; + $managedScan = false; + $staticIpScan = true; + $ignoreHttpStatusErrors = true; + $expectedResponse = new ScanConfig(); + $expectedResponse->setName($name2); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setMaxQps($maxQps); + $expectedResponse->setManagedScan($managedScan); + $expectedResponse->setStaticIpScan($staticIpScan); + $expectedResponse->setIgnoreHttpStatusErrors($ignoreHttpStatusErrors); + $transport->addResponse($expectedResponse); + $request = new GetScanConfigRequest(); + $response = $gapicClient->getScanConfig($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.websecurityscanner.v1.WebSecurityScanner/GetScanConfig', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getScanConfigExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new GetScanConfigRequest(); + try { + $gapicClient->getScanConfig($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getScanRunTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $urlsCrawledCount = 1749797253; + $urlsTestedCount = 1498664068; + $hasVulnerabilities = false; + $progressPercent = 2137894861; + $expectedResponse = new ScanRun(); + $expectedResponse->setName($name2); + $expectedResponse->setUrlsCrawledCount($urlsCrawledCount); + $expectedResponse->setUrlsTestedCount($urlsTestedCount); + $expectedResponse->setHasVulnerabilities($hasVulnerabilities); + $expectedResponse->setProgressPercent($progressPercent); + $transport->addResponse($expectedResponse); + $request = new GetScanRunRequest(); + $response = $gapicClient->getScanRun($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.websecurityscanner.v1.WebSecurityScanner/GetScanRun', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getScanRunExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new GetScanRunRequest(); + try { + $gapicClient->getScanRun($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listCrawledUrlsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $crawledUrlsElement = new CrawledUrl(); + $crawledUrls = [ + $crawledUrlsElement, + ]; + $expectedResponse = new ListCrawledUrlsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setCrawledUrls($crawledUrls); + $transport->addResponse($expectedResponse); + $request = new ListCrawledUrlsRequest(); + $response = $gapicClient->listCrawledUrls($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getCrawledUrls()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.websecurityscanner.v1.WebSecurityScanner/ListCrawledUrls', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listCrawledUrlsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new ListCrawledUrlsRequest(); + try { + $gapicClient->listCrawledUrls($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listFindingTypeStatsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new ListFindingTypeStatsResponse(); + $transport->addResponse($expectedResponse); + $request = new ListFindingTypeStatsRequest(); + $response = $gapicClient->listFindingTypeStats($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.websecurityscanner.v1.WebSecurityScanner/ListFindingTypeStats', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listFindingTypeStatsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new ListFindingTypeStatsRequest(); + try { + $gapicClient->listFindingTypeStats($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listFindingsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $findingsElement = new Finding(); + $findings = [ + $findingsElement, + ]; + $expectedResponse = new ListFindingsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setFindings($findings); + $transport->addResponse($expectedResponse); + $request = new ListFindingsRequest(); + $response = $gapicClient->listFindings($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getFindings()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.websecurityscanner.v1.WebSecurityScanner/ListFindings', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listFindingsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new ListFindingsRequest(); + try { + $gapicClient->listFindings($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listScanConfigsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $scanConfigsElement = new ScanConfig(); + $scanConfigs = [ + $scanConfigsElement, + ]; + $expectedResponse = new ListScanConfigsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setScanConfigs($scanConfigs); + $transport->addResponse($expectedResponse); + $request = new ListScanConfigsRequest(); + $response = $gapicClient->listScanConfigs($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getScanConfigs()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.websecurityscanner.v1.WebSecurityScanner/ListScanConfigs', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listScanConfigsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new ListScanConfigsRequest(); + try { + $gapicClient->listScanConfigs($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listScanRunsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $scanRunsElement = new ScanRun(); + $scanRuns = [ + $scanRunsElement, + ]; + $expectedResponse = new ListScanRunsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setScanRuns($scanRuns); + $transport->addResponse($expectedResponse); + $request = new ListScanRunsRequest(); + $response = $gapicClient->listScanRuns($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getScanRuns()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.websecurityscanner.v1.WebSecurityScanner/ListScanRuns', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listScanRunsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new ListScanRunsRequest(); + try { + $gapicClient->listScanRuns($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function startScanRunTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $urlsCrawledCount = 1749797253; + $urlsTestedCount = 1498664068; + $hasVulnerabilities = false; + $progressPercent = 2137894861; + $expectedResponse = new ScanRun(); + $expectedResponse->setName($name2); + $expectedResponse->setUrlsCrawledCount($urlsCrawledCount); + $expectedResponse->setUrlsTestedCount($urlsTestedCount); + $expectedResponse->setHasVulnerabilities($hasVulnerabilities); + $expectedResponse->setProgressPercent($progressPercent); + $transport->addResponse($expectedResponse); + $request = new StartScanRunRequest(); + $response = $gapicClient->startScanRun($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.websecurityscanner.v1.WebSecurityScanner/StartScanRun', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function startScanRunExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new StartScanRunRequest(); + try { + $gapicClient->startScanRun($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function stopScanRunTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $urlsCrawledCount = 1749797253; + $urlsTestedCount = 1498664068; + $hasVulnerabilities = false; + $progressPercent = 2137894861; + $expectedResponse = new ScanRun(); + $expectedResponse->setName($name2); + $expectedResponse->setUrlsCrawledCount($urlsCrawledCount); + $expectedResponse->setUrlsTestedCount($urlsTestedCount); + $expectedResponse->setHasVulnerabilities($hasVulnerabilities); + $expectedResponse->setProgressPercent($progressPercent); + $transport->addResponse($expectedResponse); + $request = new StopScanRunRequest(); + $response = $gapicClient->stopScanRun($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.websecurityscanner.v1.WebSecurityScanner/StopScanRun', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function stopScanRunExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new StopScanRunRequest(); + try { + $gapicClient->stopScanRun($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateScanConfigTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $maxQps = 844445913; + $managedScan = false; + $staticIpScan = true; + $ignoreHttpStatusErrors = true; + $expectedResponse = new ScanConfig(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setMaxQps($maxQps); + $expectedResponse->setManagedScan($managedScan); + $expectedResponse->setStaticIpScan($staticIpScan); + $expectedResponse->setIgnoreHttpStatusErrors($ignoreHttpStatusErrors); + $transport->addResponse($expectedResponse); + $request = new UpdateScanConfigRequest(); + $response = $gapicClient->updateScanConfig($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.websecurityscanner.v1.WebSecurityScanner/UpdateScanConfig', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateScanConfigExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + $request = new UpdateScanConfigRequest(); + try { + $gapicClient->updateScanConfig($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createScanConfigAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $displayName = 'displayName1615086568'; + $maxQps = 844445913; + $managedScan = false; + $staticIpScan = true; + $ignoreHttpStatusErrors = true; + $expectedResponse = new ScanConfig(); + $expectedResponse->setName($name); + $expectedResponse->setDisplayName($displayName); + $expectedResponse->setMaxQps($maxQps); + $expectedResponse->setManagedScan($managedScan); + $expectedResponse->setStaticIpScan($staticIpScan); + $expectedResponse->setIgnoreHttpStatusErrors($ignoreHttpStatusErrors); + $transport->addResponse($expectedResponse); + $request = new CreateScanConfigRequest(); + $response = $gapicClient->createScanConfigAsync($request)->wait(); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.websecurityscanner.v1.WebSecurityScanner/CreateScanConfig', $actualFuncCall); + $this->assertTrue($transport->isExhausted()); + } +}