1<?php 2/* 3 * Copyright 2014 Google Inc. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 6 * use this file except in compliance with the License. You may obtain a copy of 7 * the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 * License for the specific language governing permissions and limitations under 15 * the License. 16 */ 17 18namespace Google\Service\CloudFunctions\Resource; 19 20use Google\Service\CloudFunctions\CallFunctionRequest; 21use Google\Service\CloudFunctions\CallFunctionResponse; 22use Google\Service\CloudFunctions\CloudFunction; 23use Google\Service\CloudFunctions\GenerateDownloadUrlRequest; 24use Google\Service\CloudFunctions\GenerateDownloadUrlResponse; 25use Google\Service\CloudFunctions\GenerateUploadUrlRequest; 26use Google\Service\CloudFunctions\GenerateUploadUrlResponse; 27use Google\Service\CloudFunctions\ListFunctionsResponse; 28use Google\Service\CloudFunctions\Operation; 29use Google\Service\CloudFunctions\Policy; 30use Google\Service\CloudFunctions\SetIamPolicyRequest; 31use Google\Service\CloudFunctions\TestIamPermissionsRequest; 32use Google\Service\CloudFunctions\TestIamPermissionsResponse; 33 34/** 35 * The "functions" collection of methods. 36 * Typical usage is: 37 * <code> 38 * $cloudfunctionsService = new Google\Service\CloudFunctions(...); 39 * $functions = $cloudfunctionsService->functions; 40 * </code> 41 */ 42class ProjectsLocationsFunctions extends \Google\Service\Resource 43{ 44 /** 45 * Synchronously invokes a deployed Cloud Function. To be used for testing 46 * purposes as very limited traffic is allowed. For more information on the 47 * actual limits, refer to [Rate 48 * Limits](https://cloud.google.com/functions/quotas#rate_limits). 49 * (functions.callProjectsLocationsFunctions) 50 * 51 * @param string $name Required. The name of the function to be called. 52 * @param CallFunctionRequest $postBody 53 * @param array $optParams Optional parameters. 54 * @return CallFunctionResponse 55 */ 56 public function callProjectsLocationsFunctions($name, CallFunctionRequest $postBody, $optParams = []) 57 { 58 $params = ['name' => $name, 'postBody' => $postBody]; 59 $params = array_merge($params, $optParams); 60 return $this->call('call', [$params], CallFunctionResponse::class); 61 } 62 /** 63 * Creates a new function. If a function with the given name already exists in 64 * the specified project, the long running operation will return 65 * `ALREADY_EXISTS` error. (functions.create) 66 * 67 * @param string $location Required. The project and location in which the 68 * function should be created, specified in the format `projects/locations` 69 * @param CloudFunction $postBody 70 * @param array $optParams Optional parameters. 71 * @return Operation 72 */ 73 public function create($location, CloudFunction $postBody, $optParams = []) 74 { 75 $params = ['location' => $location, 'postBody' => $postBody]; 76 $params = array_merge($params, $optParams); 77 return $this->call('create', [$params], Operation::class); 78 } 79 /** 80 * Deletes a function with the given name from the specified project. If the 81 * given function is used by some trigger, the trigger will be updated to remove 82 * this function. (functions.delete) 83 * 84 * @param string $name Required. The name of the function which should be 85 * deleted. 86 * @param array $optParams Optional parameters. 87 * @return Operation 88 */ 89 public function delete($name, $optParams = []) 90 { 91 $params = ['name' => $name]; 92 $params = array_merge($params, $optParams); 93 return $this->call('delete', [$params], Operation::class); 94 } 95 /** 96 * Returns a signed URL for downloading deployed function source code. The URL 97 * is only valid for a limited period and should be used within minutes after 98 * generation. For more information about the signed URL usage see: 99 * https://cloud.google.com/storage/docs/access-control/signed-urls 100 * (functions.generateDownloadUrl) 101 * 102 * @param string $name The name of function for which source code Google Cloud 103 * Storage signed URL should be generated. 104 * @param GenerateDownloadUrlRequest $postBody 105 * @param array $optParams Optional parameters. 106 * @return GenerateDownloadUrlResponse 107 */ 108 public function generateDownloadUrl($name, GenerateDownloadUrlRequest $postBody, $optParams = []) 109 { 110 $params = ['name' => $name, 'postBody' => $postBody]; 111 $params = array_merge($params, $optParams); 112 return $this->call('generateDownloadUrl', [$params], GenerateDownloadUrlResponse::class); 113 } 114 /** 115 * Returns a signed URL for uploading a function source code. For more 116 * information about the signed URL usage see: 117 * https://cloud.google.com/storage/docs/access-control/signed-urls. Once the 118 * function source code upload is complete, the used signed URL should be 119 * provided in CreateFunction or UpdateFunction request as a reference to the 120 * function source code. When uploading source code to the generated signed URL, 121 * please follow these restrictions: * Source file type should be a zip file. * 122 * Source file size should not exceed 100MB limit. * No credentials should be 123 * attached - the signed URLs provide access to the target bucket using internal 124 * service identity; if credentials were attached, the identity from the 125 * credentials would be used, but that identity does not have permissions to 126 * upload files to the URL. When making a HTTP PUT request, these two headers 127 * need to be specified: * `content-type: application/zip` * `x-goog-content- 128 * length-range: 0,104857600` And this header SHOULD NOT be specified: * 129 * `Authorization: Bearer YOUR_TOKEN` (functions.generateUploadUrl) 130 * 131 * @param string $parent The project and location in which the Google Cloud 132 * Storage signed URL should be generated, specified in the format 133 * `projects/locations`. 134 * @param GenerateUploadUrlRequest $postBody 135 * @param array $optParams Optional parameters. 136 * @return GenerateUploadUrlResponse 137 */ 138 public function generateUploadUrl($parent, GenerateUploadUrlRequest $postBody, $optParams = []) 139 { 140 $params = ['parent' => $parent, 'postBody' => $postBody]; 141 $params = array_merge($params, $optParams); 142 return $this->call('generateUploadUrl', [$params], GenerateUploadUrlResponse::class); 143 } 144 /** 145 * Returns a function with the given name from the requested project. 146 * (functions.get) 147 * 148 * @param string $name Required. The name of the function which details should 149 * be obtained. 150 * @param array $optParams Optional parameters. 151 * @return CloudFunction 152 */ 153 public function get($name, $optParams = []) 154 { 155 $params = ['name' => $name]; 156 $params = array_merge($params, $optParams); 157 return $this->call('get', [$params], CloudFunction::class); 158 } 159 /** 160 * Gets the IAM access control policy for a function. Returns an empty policy if 161 * the function exists and does not have a policy set. (functions.getIamPolicy) 162 * 163 * @param string $resource REQUIRED: The resource for which the policy is being 164 * requested. See the operation documentation for the appropriate value for this 165 * field. 166 * @param array $optParams Optional parameters. 167 * 168 * @opt_param int options.requestedPolicyVersion Optional. The maximum policy 169 * version that will be used to format the policy. Valid values are 0, 1, and 3. 170 * Requests specifying an invalid value will be rejected. Requests for policies 171 * with any conditional role bindings must specify version 3. Policies with no 172 * conditional role bindings may specify any valid value or leave the field 173 * unset. The policy in the response might use the policy version that you 174 * specified, or it might use a lower policy version. For example, if you 175 * specify version 3, but the policy has no conditional role bindings, the 176 * response uses version 1. To learn which resources support conditions in their 177 * IAM policies, see the [IAM 178 * documentation](https://cloud.google.com/iam/help/conditions/resource- 179 * policies). 180 * @return Policy 181 */ 182 public function getIamPolicy($resource, $optParams = []) 183 { 184 $params = ['resource' => $resource]; 185 $params = array_merge($params, $optParams); 186 return $this->call('getIamPolicy', [$params], Policy::class); 187 } 188 /** 189 * Returns a list of functions that belong to the requested project. 190 * (functions.listProjectsLocationsFunctions) 191 * 192 * @param string $parent The project and location from which the function should 193 * be listed, specified in the format `projects/locations` If you want to list 194 * functions in all locations, use "-" in place of a location. When listing 195 * functions in all locations, if one or more location(s) are unreachable, the 196 * response will contain functions from all reachable locations along with the 197 * names of any unreachable locations. 198 * @param array $optParams Optional parameters. 199 * 200 * @opt_param int pageSize Maximum number of functions to return per call. 201 * @opt_param string pageToken The value returned by the last 202 * `ListFunctionsResponse`; indicates that this is a continuation of a prior 203 * `ListFunctions` call, and that the system should return the next page of 204 * data. 205 * @return ListFunctionsResponse 206 */ 207 public function listProjectsLocationsFunctions($parent, $optParams = []) 208 { 209 $params = ['parent' => $parent]; 210 $params = array_merge($params, $optParams); 211 return $this->call('list', [$params], ListFunctionsResponse::class); 212 } 213 /** 214 * Updates existing function. (functions.patch) 215 * 216 * @param string $name A user-defined name of the function. Function names must 217 * be unique globally and match pattern `projects/locations/functions` 218 * @param CloudFunction $postBody 219 * @param array $optParams Optional parameters. 220 * 221 * @opt_param string updateMask Required. The list of fields in `CloudFunction` 222 * that have to be updated. 223 * @return Operation 224 */ 225 public function patch($name, CloudFunction $postBody, $optParams = []) 226 { 227 $params = ['name' => $name, 'postBody' => $postBody]; 228 $params = array_merge($params, $optParams); 229 return $this->call('patch', [$params], Operation::class); 230 } 231 /** 232 * Sets the IAM access control policy on the specified function. Replaces any 233 * existing policy. (functions.setIamPolicy) 234 * 235 * @param string $resource REQUIRED: The resource for which the policy is being 236 * specified. See the operation documentation for the appropriate value for this 237 * field. 238 * @param SetIamPolicyRequest $postBody 239 * @param array $optParams Optional parameters. 240 * @return Policy 241 */ 242 public function setIamPolicy($resource, SetIamPolicyRequest $postBody, $optParams = []) 243 { 244 $params = ['resource' => $resource, 'postBody' => $postBody]; 245 $params = array_merge($params, $optParams); 246 return $this->call('setIamPolicy', [$params], Policy::class); 247 } 248 /** 249 * Tests the specified permissions against the IAM access control policy for a 250 * function. If the function does not exist, this will return an empty set of 251 * permissions, not a NOT_FOUND error. (functions.testIamPermissions) 252 * 253 * @param string $resource REQUIRED: The resource for which the policy detail is 254 * being requested. See the operation documentation for the appropriate value 255 * for this field. 256 * @param TestIamPermissionsRequest $postBody 257 * @param array $optParams Optional parameters. 258 * @return TestIamPermissionsResponse 259 */ 260 public function testIamPermissions($resource, TestIamPermissionsRequest $postBody, $optParams = []) 261 { 262 $params = ['resource' => $resource, 'postBody' => $postBody]; 263 $params = array_merge($params, $optParams); 264 return $this->call('testIamPermissions', [$params], TestIamPermissionsResponse::class); 265 } 266} 267 268// Adding a class alias for backwards compatibility with the previous class name. 269class_alias(ProjectsLocationsFunctions::class, 'Google_Service_CloudFunctions_Resource_ProjectsLocationsFunctions'); 270