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\GetIamPolicyRequest;
21use Google\Service\CloudResourceManager\ListProjectsResponse;
22use Google\Service\CloudResourceManager\MoveProjectRequest;
23use Google\Service\CloudResourceManager\Operation;
24use Google\Service\CloudResourceManager\Policy;
25use Google\Service\CloudResourceManager\Project;
26use Google\Service\CloudResourceManager\SearchProjectsResponse;
27use Google\Service\CloudResourceManager\SetIamPolicyRequest;
28use Google\Service\CloudResourceManager\TestIamPermissionsRequest;
29use Google\Service\CloudResourceManager\TestIamPermissionsResponse;
30use Google\Service\CloudResourceManager\UndeleteProjectRequest;
31
32/**
33 * The "projects" collection of methods.
34 * Typical usage is:
35 *  <code>
36 *   $cloudresourcemanagerService = new Google\Service\CloudResourceManager(...);
37 *   $projects = $cloudresourcemanagerService->projects;
38 *  </code>
39 */
40class Projects extends \Google\Service\Resource
41{
42  /**
43   * Request that a new project be created. The result is an `Operation` which can
44   * be used to track the creation process. This process usually takes a few
45   * seconds, but can sometimes take much longer. The tracking `Operation` is
46   * automatically deleted after a few hours, so there is no need to call
47   * `DeleteOperation`. (projects.create)
48   *
49   * @param Project $postBody
50   * @param array $optParams Optional parameters.
51   * @return Operation
52   */
53  public function create(Project $postBody, $optParams = [])
54  {
55    $params = ['postBody' => $postBody];
56    $params = array_merge($params, $optParams);
57    return $this->call('create', [$params], Operation::class);
58  }
59  /**
60   * Marks the project identified by the specified `name` (for example,
61   * `projects/415104041262`) for deletion. This method will only affect the
62   * project if it has a lifecycle state of ACTIVE. This method changes the
63   * Project's lifecycle state from ACTIVE to DELETE_REQUESTED. The deletion
64   * starts at an unspecified time, at which point the Project is no longer
65   * accessible. Until the deletion completes, you can check the lifecycle state
66   * checked by retrieving the project with GetProject, and the project remains
67   * visible to ListProjects. However, you cannot update the project. After the
68   * deletion completes, the project is not retrievable by the GetProject,
69   * ListProjects, and SearchProjects methods. This method behaves idempotently,
70   * such that deleting a `DELETE_REQUESTED` project will not cause an error, but
71   * also won't do anything. The caller must have
72   * `resourcemanager.projects.delete` permissions for this project.
73   * (projects.delete)
74   *
75   * @param string $name Required. The name of the Project (for example,
76   * `projects/415104041262`).
77   * @param array $optParams Optional parameters.
78   * @return Operation
79   */
80  public function delete($name, $optParams = [])
81  {
82    $params = ['name' => $name];
83    $params = array_merge($params, $optParams);
84    return $this->call('delete', [$params], Operation::class);
85  }
86  /**
87   * Retrieves the project identified by the specified `name` (for example,
88   * `projects/415104041262`). The caller must have `resourcemanager.projects.get`
89   * permission for this project. (projects.get)
90   *
91   * @param string $name Required. The name of the project (for example,
92   * `projects/415104041262`).
93   * @param array $optParams Optional parameters.
94   * @return Project
95   */
96  public function get($name, $optParams = [])
97  {
98    $params = ['name' => $name];
99    $params = array_merge($params, $optParams);
100    return $this->call('get', [$params], Project::class);
101  }
102  /**
103   * Returns the IAM access control policy for the specified project, in the
104   * format `projects/{ProjectIdOrNumber}` e.g. projects/123. Permission is denied
105   * if the policy or the resource do not exist. (projects.getIamPolicy)
106   *
107   * @param string $resource REQUIRED: The resource for which the policy is being
108   * requested. See the operation documentation for the appropriate value for this
109   * field.
110   * @param GetIamPolicyRequest $postBody
111   * @param array $optParams Optional parameters.
112   * @return Policy
113   */
114  public function getIamPolicy($resource, GetIamPolicyRequest $postBody, $optParams = [])
115  {
116    $params = ['resource' => $resource, 'postBody' => $postBody];
117    $params = array_merge($params, $optParams);
118    return $this->call('getIamPolicy', [$params], Policy::class);
119  }
120  /**
121   * Lists projects that are direct children of the specified folder or
122   * organization resource. `list()` provides a strongly consistent view of the
123   * projects underneath the specified parent resource. `list()` returns projects
124   * sorted based upon the (ascending) lexical ordering of their `display_name`.
125   * The caller must have `resourcemanager.projects.list` permission on the
126   * identified parent. (projects.listProjects)
127   *
128   * @param array $optParams Optional parameters.
129   *
130   * @opt_param int pageSize Optional. The maximum number of projects to return in
131   * the response. The server can return fewer projects than requested. If
132   * unspecified, server picks an appropriate default.
133   * @opt_param string pageToken Optional. A pagination token returned from a
134   * previous call to ListProjects that indicates from where listing should
135   * continue.
136   * @opt_param string parent Required. The name of the parent resource to list
137   * projects under. For example, setting this field to 'folders/1234' would list
138   * all projects directly under that folder.
139   * @opt_param bool showDeleted Optional. Indicate that projects in the
140   * `DELETE_REQUESTED` state should also be returned. Normally only `ACTIVE`
141   * projects are returned.
142   * @return ListProjectsResponse
143   */
144  public function listProjects($optParams = [])
145  {
146    $params = [];
147    $params = array_merge($params, $optParams);
148    return $this->call('list', [$params], ListProjectsResponse::class);
149  }
150  /**
151   * Move a project to another place in your resource hierarchy, under a new
152   * resource parent. Returns an operation which can be used to track the process
153   * of the project move workflow. Upon success, the `Operation.response` field
154   * will be populated with the moved project. The caller must have
155   * `resourcemanager.projects.move` permission on the project, on the project's
156   * current and proposed new parent. If project has no current parent, or it
157   * currently does not have an associated organization resource, you will also
158   * need the `resourcemanager.projects.setIamPolicy` permission in the project.
159   * (projects.move)
160   *
161   * @param string $name Required. The name of the project to move.
162   * @param MoveProjectRequest $postBody
163   * @param array $optParams Optional parameters.
164   * @return Operation
165   */
166  public function move($name, MoveProjectRequest $postBody, $optParams = [])
167  {
168    $params = ['name' => $name, 'postBody' => $postBody];
169    $params = array_merge($params, $optParams);
170    return $this->call('move', [$params], Operation::class);
171  }
172  /**
173   * Updates the `display_name` and labels of the project identified by the
174   * specified `name` (for example, `projects/415104041262`). Deleting all labels
175   * requires an update mask for labels field. The caller must have
176   * `resourcemanager.projects.update` permission for this project.
177   * (projects.patch)
178   *
179   * @param string $name Output only. The unique resource name of the project. It
180   * is an int64 generated number prefixed by "projects/". Example:
181   * `projects/415104041262`
182   * @param Project $postBody
183   * @param array $optParams Optional parameters.
184   *
185   * @opt_param string updateMask Optional. An update mask to selectively update
186   * fields.
187   * @return Operation
188   */
189  public function patch($name, Project $postBody, $optParams = [])
190  {
191    $params = ['name' => $name, 'postBody' => $postBody];
192    $params = array_merge($params, $optParams);
193    return $this->call('patch', [$params], Operation::class);
194  }
195  /**
196   * Search for projects that the caller has both `resourcemanager.projects.get`
197   * permission on, and also satisfy the specified query. This method returns
198   * projects in an unspecified order. This method is eventually consistent with
199   * project mutations; this means that a newly created project may not appear in
200   * the results or recent updates to an existing project may not be reflected in
201   * the results. To retrieve the latest state of a project, use the GetProject
202   * method. (projects.search)
203   *
204   * @param array $optParams Optional parameters.
205   *
206   * @opt_param int pageSize Optional. The maximum number of projects to return in
207   * the response. The server can return fewer projects than requested. If
208   * unspecified, server picks an appropriate default.
209   * @opt_param string pageToken Optional. A pagination token returned from a
210   * previous call to ListProjects that indicates from where listing should
211   * continue.
212   * @opt_param string query Optional. A query string for searching for projects
213   * that the caller has `resourcemanager.projects.get` permission to. If multiple
214   * fields are included in the query, then it will return results that match any
215   * of the fields. Some eligible fields are: ``` | Field | Description |
216   * |-------------------------|----------------------------------------------| |
217   * displayName, name | Filters by displayName. | | parent | Project's parent
218   * (for example: folders/123, organizations). Prefer parent field over
219   * parent.type and parent.id.| | parent.type | Parent's type: `folder` or
220   * `organization`. | | parent.id | Parent's id number (for example: 123) | | id,
221   * projectId | Filters by projectId. | | state, lifecycleState | Filters by
222   * state. | | labels | Filters by label name or value. | | labels.\ (where *key*
223   * is the name of a label) | Filters by label name.| ``` Search expressions are
224   * case insensitive. Some examples queries: ``` | Query | Description |
225   * |------------------|-----------------------------------------------------| |
226   * name:how* | The project's name starts with "how". | | name:Howl | The
227   * project's name is `Howl` or `howl`. | | name:HOWL | Equivalent to above. | |
228   * NAME:howl | Equivalent to above. | | labels.color:* | The project has the
229   * label `color`. | | labels.color:red | The project's label `color` has the
230   * value `red`. | | labels.color:red labels.size:big | The project's label
231   * `color` has the value `red` and its label `size` has the value `big`.| ``` If
232   * no query is specified, the call will return projects for which the user has
233   * the `resourcemanager.projects.get` permission.
234   * @return SearchProjectsResponse
235   */
236  public function search($optParams = [])
237  {
238    $params = [];
239    $params = array_merge($params, $optParams);
240    return $this->call('search', [$params], SearchProjectsResponse::class);
241  }
242  /**
243   * Sets the IAM access control policy for the specified project, in the format
244   * `projects/{ProjectIdOrNumber}` e.g. projects/123. CAUTION: This method will
245   * replace the existing policy, and cannot be used to append additional IAM
246   * settings. Note: Removing service accounts from policies or changing their
247   * roles can render services completely inoperable. It is important to
248   * understand how the service account is being used before removing or updating
249   * its roles. The following constraints apply when using `setIamPolicy()`: +
250   * Project does not support `allUsers` and `allAuthenticatedUsers` as `members`
251   * in a `Binding` of a `Policy`. + The owner role can be granted to a `user`,
252   * `serviceAccount`, or a group that is part of an organization. For example,
253   * group@myownpersonaldomain.com could be added as an owner to a project in the
254   * myownpersonaldomain.com organization, but not the examplepetstore.com
255   * organization. + Service accounts can be made owners of a project directly
256   * without any restrictions. However, to be added as an owner, a user must be
257   * invited using the Cloud Platform console and must accept the invitation. + A
258   * user cannot be granted the owner role using `setIamPolicy()`. The user must
259   * be granted the owner role using the Cloud Platform Console and must
260   * explicitly accept the invitation. + Invitations to grant the owner role
261   * cannot be sent using `setIamPolicy()`; they must be sent only using the Cloud
262   * Platform Console. + If the project is not part of an organization, there must
263   * be at least one owner who has accepted the Terms of Service (ToS) agreement
264   * in the policy. Calling `setIamPolicy()` to remove the last ToS-accepted owner
265   * from the policy will fail. This restriction also applies to legacy projects
266   * that no longer have owners who have accepted the ToS. Edits to IAM policies
267   * will be rejected until the lack of a ToS-accepting owner is rectified. If the
268   * project is part of an organization, you can remove all owners, potentially
269   * making the organization inaccessible. + Calling this method requires enabling
270   * the App Engine Admin API. (projects.setIamPolicy)
271   *
272   * @param string $resource REQUIRED: The resource for which the policy is being
273   * specified. See the operation documentation for the appropriate value for this
274   * field.
275   * @param SetIamPolicyRequest $postBody
276   * @param array $optParams Optional parameters.
277   * @return Policy
278   */
279  public function setIamPolicy($resource, SetIamPolicyRequest $postBody, $optParams = [])
280  {
281    $params = ['resource' => $resource, 'postBody' => $postBody];
282    $params = array_merge($params, $optParams);
283    return $this->call('setIamPolicy', [$params], Policy::class);
284  }
285  /**
286   * Returns permissions that a caller has on the specified project, in the format
287   * `projects/{ProjectIdOrNumber}` e.g. projects/123..
288   * (projects.testIamPermissions)
289   *
290   * @param string $resource REQUIRED: The resource for which the policy detail is
291   * being requested. See the operation documentation for the appropriate value
292   * for this field.
293   * @param TestIamPermissionsRequest $postBody
294   * @param array $optParams Optional parameters.
295   * @return TestIamPermissionsResponse
296   */
297  public function testIamPermissions($resource, TestIamPermissionsRequest $postBody, $optParams = [])
298  {
299    $params = ['resource' => $resource, 'postBody' => $postBody];
300    $params = array_merge($params, $optParams);
301    return $this->call('testIamPermissions', [$params], TestIamPermissionsResponse::class);
302  }
303  /**
304   * Restores the project identified by the specified `name` (for example,
305   * `projects/415104041262`). You can only use this method for a project that has
306   * a lifecycle state of DELETE_REQUESTED. After deletion starts, the project
307   * cannot be restored. The caller must have `resourcemanager.projects.undelete`
308   * permission for this project. (projects.undelete)
309   *
310   * @param string $name Required. The name of the project (for example,
311   * `projects/415104041262`). Required.
312   * @param UndeleteProjectRequest $postBody
313   * @param array $optParams Optional parameters.
314   * @return Operation
315   */
316  public function undelete($name, UndeleteProjectRequest $postBody, $optParams = [])
317  {
318    $params = ['name' => $name, 'postBody' => $postBody];
319    $params = array_merge($params, $optParams);
320    return $this->call('undelete', [$params], Operation::class);
321  }
322}
323
324// Adding a class alias for backwards compatibility with the previous class name.
325class_alias(Projects::class, 'Google_Service_CloudResourceManager_Resource_Projects');
326