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\CloudResourceManager\Resource;
19
20use Google\Service\CloudResourceManager\Folder;
21use Google\Service\CloudResourceManager\GetIamPolicyRequest;
22use Google\Service\CloudResourceManager\ListFoldersResponse;
23use Google\Service\CloudResourceManager\MoveFolderRequest;
24use Google\Service\CloudResourceManager\Operation;
25use Google\Service\CloudResourceManager\Policy;
26use Google\Service\CloudResourceManager\SearchFoldersResponse;
27use Google\Service\CloudResourceManager\SetIamPolicyRequest;
28use Google\Service\CloudResourceManager\TestIamPermissionsRequest;
29use Google\Service\CloudResourceManager\TestIamPermissionsResponse;
30use Google\Service\CloudResourceManager\UndeleteFolderRequest;
31
32/**
33 * The "folders" collection of methods.
34 * Typical usage is:
35 *  <code>
36 *   $cloudresourcemanagerService = new Google\Service\CloudResourceManager(...);
37 *   $folders = $cloudresourcemanagerService->folders;
38 *  </code>
39 */
40class Folders extends \Google\Service\Resource
41{
42  /**
43   * Creates a folder in the resource hierarchy. Returns an `Operation` which can
44   * be used to track the progress of the folder creation workflow. Upon success,
45   * the `Operation.response` field will be populated with the created Folder. In
46   * order to succeed, the addition of this new folder must not violate the folder
47   * naming, height, or fanout constraints. + The folder's `display_name` must be
48   * distinct from all other folders that share its parent. + The addition of the
49   * folder must not cause the active folder hierarchy to exceed a height of 10.
50   * Note, the full active + deleted folder hierarchy is allowed to reach a height
51   * of 20; this provides additional headroom when moving folders that contain
52   * deleted folders. + The addition of the folder must not cause the total number
53   * of folders under its parent to exceed 300. If the operation fails due to a
54   * folder constraint violation, some errors may be returned by the
55   * `CreateFolder` request, with status code `FAILED_PRECONDITION` and an error
56   * description. Other folder constraint violations will be communicated in the
57   * `Operation`, with the specific `PreconditionFailure` returned in the details
58   * list in the `Operation.error` field. The caller must have
59   * `resourcemanager.folders.create` permission on the identified parent.
60   * (folders.create)
61   *
62   * @param Folder $postBody
63   * @param array $optParams Optional parameters.
64   * @return Operation
65   */
66  public function create(Folder $postBody, $optParams = [])
67  {
68    $params = ['postBody' => $postBody];
69    $params = array_merge($params, $optParams);
70    return $this->call('create', [$params], Operation::class);
71  }
72  /**
73   * Requests deletion of a folder. The folder is moved into the DELETE_REQUESTED
74   * state immediately, and is deleted approximately 30 days later. This method
75   * may only be called on an empty folder, where a folder is empty if it doesn't
76   * contain any folders or projects in the ACTIVE state. If called on a folder in
77   * DELETE_REQUESTED state the operation will result in a no-op success. The
78   * caller must have `resourcemanager.folders.delete` permission on the
79   * identified folder. (folders.delete)
80   *
81   * @param string $name Required. The resource name of the folder to be deleted.
82   * Must be of the form `folders/{folder_id}`.
83   * @param array $optParams Optional parameters.
84   * @return Operation
85   */
86  public function delete($name, $optParams = [])
87  {
88    $params = ['name' => $name];
89    $params = array_merge($params, $optParams);
90    return $this->call('delete', [$params], Operation::class);
91  }
92  /**
93   * Retrieves a folder identified by the supplied resource name. Valid folder
94   * resource names have the format `folders/{folder_id}` (for example,
95   * `folders/1234`). The caller must have `resourcemanager.folders.get`
96   * permission on the identified folder. (folders.get)
97   *
98   * @param string $name Required. The resource name of the folder to retrieve.
99   * Must be of the form `folders/{folder_id}`.
100   * @param array $optParams Optional parameters.
101   * @return Folder
102   */
103  public function get($name, $optParams = [])
104  {
105    $params = ['name' => $name];
106    $params = array_merge($params, $optParams);
107    return $this->call('get', [$params], Folder::class);
108  }
109  /**
110   * Gets the access control policy for a folder. The returned policy may be empty
111   * if no such policy or resource exists. The `resource` field should be the
112   * folder's resource name, for example: "folders/1234". The caller must have
113   * `resourcemanager.folders.getIamPolicy` permission on the identified folder.
114   * (folders.getIamPolicy)
115   *
116   * @param string $resource REQUIRED: The resource for which the policy is being
117   * requested. See the operation documentation for the appropriate value for this
118   * field.
119   * @param GetIamPolicyRequest $postBody
120   * @param array $optParams Optional parameters.
121   * @return Policy
122   */
123  public function getIamPolicy($resource, GetIamPolicyRequest $postBody, $optParams = [])
124  {
125    $params = ['resource' => $resource, 'postBody' => $postBody];
126    $params = array_merge($params, $optParams);
127    return $this->call('getIamPolicy', [$params], Policy::class);
128  }
129  /**
130   * Lists the folders that are direct descendants of supplied parent resource.
131   * `list()` provides a strongly consistent view of the folders underneath the
132   * specified parent resource. `list()` returns folders sorted based upon the
133   * (ascending) lexical ordering of their display_name. The caller must have
134   * `resourcemanager.folders.list` permission on the identified parent.
135   * (folders.listFolders)
136   *
137   * @param array $optParams Optional parameters.
138   *
139   * @opt_param int pageSize Optional. The maximum number of folders to return in
140   * the response. The server can return fewer folders than requested. If
141   * unspecified, server picks an appropriate default.
142   * @opt_param string pageToken Optional. A pagination token returned from a
143   * previous call to `ListFolders` that indicates where this listing should
144   * continue from.
145   * @opt_param string parent Required. The resource name of the organization or
146   * folder whose folders are being listed. Must be of the form
147   * `folders/{folder_id}` or `organizations/{org_id}`. Access to this method is
148   * controlled by checking the `resourcemanager.folders.list` permission on the
149   * `parent`.
150   * @opt_param bool showDeleted Optional. Controls whether folders in the
151   * DELETE_REQUESTED state should be returned. Defaults to false.
152   * @return ListFoldersResponse
153   */
154  public function listFolders($optParams = [])
155  {
156    $params = [];
157    $params = array_merge($params, $optParams);
158    return $this->call('list', [$params], ListFoldersResponse::class);
159  }
160  /**
161   * Moves a folder under a new resource parent. Returns an `Operation` which can
162   * be used to track the progress of the folder move workflow. Upon success, the
163   * `Operation.response` field will be populated with the moved folder. Upon
164   * failure, a `FolderOperationError` categorizing the failure cause will be
165   * returned - if the failure occurs synchronously then the
166   * `FolderOperationError` will be returned in the `Status.details` field. If it
167   * occurs asynchronously, then the FolderOperation will be returned in the
168   * `Operation.error` field. In addition, the `Operation.metadata` field will be
169   * populated with a `FolderOperation` message as an aid to stateless clients.
170   * Folder moves will be rejected if they violate either the naming, height, or
171   * fanout constraints described in the CreateFolder documentation. The caller
172   * must have `resourcemanager.folders.move` permission on the folder's current
173   * and proposed new parent. (folders.move)
174   *
175   * @param string $name Required. The resource name of the Folder to move. Must
176   * be of the form folders/{folder_id}
177   * @param MoveFolderRequest $postBody
178   * @param array $optParams Optional parameters.
179   * @return Operation
180   */
181  public function move($name, MoveFolderRequest $postBody, $optParams = [])
182  {
183    $params = ['name' => $name, 'postBody' => $postBody];
184    $params = array_merge($params, $optParams);
185    return $this->call('move', [$params], Operation::class);
186  }
187  /**
188   * Updates a folder, changing its `display_name`. Changes to the folder
189   * `display_name` will be rejected if they violate either the `display_name`
190   * formatting rules or the naming constraints described in the CreateFolder
191   * documentation. The folder's `display_name` must start and end with a letter
192   * or digit, may contain letters, digits, spaces, hyphens and underscores and
193   * can be between 3 and 30 characters. This is captured by the regular
194   * expression: `\p{L}\p{N}{1,28}[\p{L}\p{N}]`. The caller must have
195   * `resourcemanager.folders.update` permission on the identified folder. If the
196   * update fails due to the unique name constraint then a `PreconditionFailure`
197   * explaining this violation will be returned in the Status.details field.
198   * (folders.patch)
199   *
200   * @param string $name Output only. The resource name of the folder. Its format
201   * is `folders/{folder_id}`, for example: "folders/1234".
202   * @param Folder $postBody
203   * @param array $optParams Optional parameters.
204   *
205   * @opt_param string updateMask Required. Fields to be updated. Only the
206   * `display_name` can be updated.
207   * @return Operation
208   */
209  public function patch($name, Folder $postBody, $optParams = [])
210  {
211    $params = ['name' => $name, 'postBody' => $postBody];
212    $params = array_merge($params, $optParams);
213    return $this->call('patch', [$params], Operation::class);
214  }
215  /**
216   * Search for folders that match specific filter criteria. `search()` provides
217   * an eventually consistent view of the folders a user has access to which meet
218   * the specified filter criteria. This will only return folders on which the
219   * caller has the permission `resourcemanager.folders.get`. (folders.search)
220   *
221   * @param array $optParams Optional parameters.
222   *
223   * @opt_param int pageSize Optional. The maximum number of folders to return in
224   * the response. The server can return fewer folders than requested. If
225   * unspecified, server picks an appropriate default.
226   * @opt_param string pageToken Optional. A pagination token returned from a
227   * previous call to `SearchFolders` that indicates from where search should
228   * continue.
229   * @opt_param string query Optional. Search criteria used to select the folders
230   * to return. If no search criteria is specified then all accessible folders
231   * will be returned. Query expressions can be used to restrict results based
232   * upon displayName, state and parent, where the operators `=` (`:`) `NOT`,
233   * `AND` and `OR` can be used along with the suffix wildcard symbol `*`. The
234   * `displayName` field in a query expression should use escaped quotes for
235   * values that include whitespace to prevent unexpected behavior. ``` | Field |
236   * Description |
237   * |-------------------------|----------------------------------------| |
238   * displayName | Filters by displayName. | | parent | Filters by parent (for
239   * example: folders/123). | | state, lifecycleState | Filters by state. | ```
240   * Some example queries are: * Query `displayName=Test*` returns Folder
241   * resources whose display name starts with "Test". * Query `state=ACTIVE`
242   * returns Folder resources with `state` set to `ACTIVE`. * Query
243   * `parent=folders/123` returns Folder resources that have `folders/123` as a
244   * parent resource. * Query `parent=folders/123 AND state=ACTIVE` returns active
245   * Folder resources that have `folders/123` as a parent resource. * Query
246   * `displayName=\\"Test String\\"` returns Folder resources with display names
247   * that include both "Test" and "String".
248   * @return SearchFoldersResponse
249   */
250  public function search($optParams = [])
251  {
252    $params = [];
253    $params = array_merge($params, $optParams);
254    return $this->call('search', [$params], SearchFoldersResponse::class);
255  }
256  /**
257   * Sets the access control policy on a folder, replacing any existing policy.
258   * The `resource` field should be the folder's resource name, for example:
259   * "folders/1234". The caller must have `resourcemanager.folders.setIamPolicy`
260   * permission on the identified folder. (folders.setIamPolicy)
261   *
262   * @param string $resource REQUIRED: The resource for which the policy is being
263   * specified. See the operation documentation for the appropriate value for this
264   * field.
265   * @param SetIamPolicyRequest $postBody
266   * @param array $optParams Optional parameters.
267   * @return Policy
268   */
269  public function setIamPolicy($resource, SetIamPolicyRequest $postBody, $optParams = [])
270  {
271    $params = ['resource' => $resource, 'postBody' => $postBody];
272    $params = array_merge($params, $optParams);
273    return $this->call('setIamPolicy', [$params], Policy::class);
274  }
275  /**
276   * Returns permissions that a caller has on the specified folder. The `resource`
277   * field should be the folder's resource name, for example: "folders/1234".
278   * There are no permissions required for making this API call.
279   * (folders.testIamPermissions)
280   *
281   * @param string $resource REQUIRED: The resource for which the policy detail is
282   * being requested. See the operation documentation for the appropriate value
283   * for this field.
284   * @param TestIamPermissionsRequest $postBody
285   * @param array $optParams Optional parameters.
286   * @return TestIamPermissionsResponse
287   */
288  public function testIamPermissions($resource, TestIamPermissionsRequest $postBody, $optParams = [])
289  {
290    $params = ['resource' => $resource, 'postBody' => $postBody];
291    $params = array_merge($params, $optParams);
292    return $this->call('testIamPermissions', [$params], TestIamPermissionsResponse::class);
293  }
294  /**
295   * Cancels the deletion request for a folder. This method may be called on a
296   * folder in any state. If the folder is in the ACTIVE state the result will be
297   * a no-op success. In order to succeed, the folder's parent must be in the
298   * ACTIVE state. In addition, reintroducing the folder into the tree must not
299   * violate folder naming, height, and fanout constraints described in the
300   * CreateFolder documentation. The caller must have
301   * `resourcemanager.folders.undelete` permission on the identified folder.
302   * (folders.undelete)
303   *
304   * @param string $name Required. The resource name of the folder to undelete.
305   * Must be of the form `folders/{folder_id}`.
306   * @param UndeleteFolderRequest $postBody
307   * @param array $optParams Optional parameters.
308   * @return Operation
309   */
310  public function undelete($name, UndeleteFolderRequest $postBody, $optParams = [])
311  {
312    $params = ['name' => $name, 'postBody' => $postBody];
313    $params = array_merge($params, $optParams);
314    return $this->call('undelete', [$params], Operation::class);
315  }
316}
317
318// Adding a class alias for backwards compatibility with the previous class name.
319class_alias(Folders::class, 'Google_Service_CloudResourceManager_Resource_Folders');
320