You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here is a code snippet showing a simple usage example. Note that you must supply Google SDK credentials forthis service, not other forms of authentication listedin the [Authentication section](#authentication).
<!-- TODO(ajaykannan): once the API becomes usable, make an example application
24
38
Example Application
@@ -27,27 +41,145 @@ Example Application
27
41
Authentication
28
42
--------------
29
43
30
-
See the [Authentication](https://github.com/GoogleCloudPlatform/gcloud-java#authentication) section in the base directory's README.
44
+
Unlike other `gcloud-java` service libraries, `gcloud-java-resourcemanager` only accepts Google Cloud SDK credentials at this time. If you are having trouble authenticating, it may be that you have other types of credentials that override your Google Cloud SDK credentials. See more about Google Cloud SDK credentials and credential precedence in the global README's [Authentication section](https://github.com/GoogleCloudPlatform/gcloud-java#authentication).
31
45
32
46
About Google Cloud Resource Manager
33
47
-----------------------------------
34
48
35
-
Google [Cloud Resource Manager][cloud-resourcemanager] provides a programmatic way to manage your Google Cloud Platform projects. Google Cloud Resource Manager is currently in beta and may occasionally make backwards incompatible changes.
49
+
Google [Cloud Resource Manager][cloud-resourcemanager] provides a programmatic way to manage your Google Cloud Platform projects. With this API, you can do the following:
50
+
51
+
* Get a list of all projects associated with an account.
52
+
* Create new projects.
53
+
* Update existing projects.
54
+
* Delete projects.
55
+
* Undelete projects that you don't want to delete.
56
+
57
+
Google Cloud Resource Manager is currently in beta and may occasionally make backwards incompatible changes.
36
58
37
59
Be sure to activate the Google Cloud Resource Manager API on the Developer's Console to use Resource Manager from your project.
38
60
39
61
See the ``gcloud-java`` API [Resource Manager documentation][resourcemanager-api] to learn how to interact
40
62
with the Cloud Resource Manager using this client Library.
41
63
42
-
<!-- TODO(ajaykannan): add code snippet -->
64
+
Getting Started
65
+
---------------
66
+
#### Prerequisites
67
+
You will need to set up the local development environment by [installing the Google Cloud SDK](https://cloud.google.com/sdk/) and running the following command in command line: `gcloud auth login`.
68
+
69
+
> Note: You don't need a project ID to use this service. If you have a project ID set in the Google Cloud SDK, you can unset it by typing `gcloud config unset project` in command line.
70
+
71
+
#### Installation and setup
72
+
You'll need to obtain the `gcloud-java-resourcemanager` library. See the [Quickstart](#quickstart) section to add `gcloud-java-resourcemanager` as a dependency in your code.
73
+
74
+
#### Creating an authorized service object
75
+
To make authenticated requests to Google Cloud Resource Manager, you must create a service object with Google Cloud SDK credentials. You can then make API calls by calling methods on the Resource Manager service object. The simplest way to authenticate is to use [Application Default Credentials](https://developers.google.com/identity/protocols/application-default-credentials). These credentials are automatically inferred from your environment, so you only need the following code to create your service object:
All you need to create a project is a globally unique project ID. You can also optionally attach a non-unique name and labels to your project. Read more about naming guidelines for project IDs, names, and labels [here](https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects). To create a project, add the following import at the top of your file:
Note that the return value from `create` is a `ProjectInfo` that includes additional read-only information, like creation time, project number, and lifecycle state. Read more about these fields on the [Projects page](https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects).
99
+
100
+
#### Getting a specific project
101
+
You can load a project if you know it's project ID and have read permissions to the project. For example, to get the project we just created we can do the following:
Note that the values of the project you pass in to `replace` overwrite the server's values for non-read-only fields, namely `projectName` and `labels`. For example, if you create a project with `projectName` "some-project-name" and subsequently call replace using a `ProjectInfo` object that didn't set the `projectName`, then the server will unset the project's name. The server ignores any attempted changes to the read-only fields `projectNumber`, `lifecycleState`, and `createTime`. The `projectId` cannot change.
118
+
119
+
#### Listing all projects
120
+
Suppose that we want a list of all projects for which we have read permissions. Add the following import:
121
+
122
+
```java
123
+
importjava.util.Iterator;
124
+
```
125
+
126
+
Then add the following code to print a list of projects you can view:
Here we put together all the code shown above into one program. This program assumes that you are running from your own desktop and used the Google Cloud SDK to authenticate yourself.
0 commit comments