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).
This method will block a short amount of time until the server thread has been terminated.
101
+
102
+
#### On a remote machine
103
+
104
+
You can test against a remote Resource Manager emulator as well. To do this, set the host to the hostname of the remote machine, like the example below.
Copy file name to clipboardExpand all lines: gcloud-java-resourcemanager/README.md
+138-5Lines changed: 138 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,27 +27,153 @@ Example Application
27
27
Authentication
28
28
--------------
29
29
30
-
See the [Authentication](https://github.com/GoogleCloudPlatform/gcloud-java#authentication) section in the base directory's README.
30
+
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
31
32
32
About Google Cloud Resource Manager
33
33
-----------------------------------
34
34
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.
35
+
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:
36
+
37
+
* Get a list of all projects associated with an account.
38
+
* Create new projects.
39
+
* Update existing projects.
40
+
* Delete projects.
41
+
* Undelete, or recover, projects that you don't want to delete.
42
+
43
+
Google Cloud Resource Manager is currently in beta and may occasionally make backwards incompatible changes.
36
44
37
45
Be sure to activate the Google Cloud Resource Manager API on the Developer's Console to use Resource Manager from your project.
38
46
39
47
See the ``gcloud-java`` API [Resource Manager documentation][resourcemanager-api] to learn how to interact
40
48
with the Cloud Resource Manager using this client Library.
41
49
42
-
<!-- TODO(ajaykannan): add code snippet -->
50
+
Getting Started
51
+
---------------
52
+
#### Prerequisites
53
+
You will also need to set up the local development environment by [installing the Google Cloud SDK](https://cloud.google.com/sdk/) and running the following commands in command line: `gcloud auth login`.
54
+
55
+
> 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.
56
+
57
+
#### Installation and setup
58
+
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.
59
+
60
+
#### Creating an authorized service object
61
+
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 imports 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).
85
+
86
+
#### Getting a specific project
87
+
You can load a project if you know it's project ID and have read permissions to the project. For example, say we wanted 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.
110
+
111
+
#### Listing all projects
112
+
Suppose that we want list of all projects for which we have read permissions. Add the following import:
113
+
114
+
```java
115
+
importjava.util.Iterator;
116
+
```
117
+
118
+
Then add the following code to print a list of projects you can view:
0 commit comments