Search in sources :

Example 1 with Project

use of com.google.cloud.resourcemanager.Project in project google-cloud-java by GoogleCloudPlatform.

the class GetOrCreateProject method main.

public static void main(String... args) {
    // Create Resource Manager service object.
    // By default, credentials are inferred from the runtime environment.
    ResourceManager resourceManager = ResourceManagerOptions.getDefaultInstance().getService();
    // Change to a unique project ID.
    String projectId = "my-globally-unique-project-id";
    // Get a project from the server.
    Project project = resourceManager.get(projectId);
    if (project == null) {
        // Create a project.
        project = resourceManager.create(ProjectInfo.newBuilder(projectId).build());
    }
    System.out.println("Got project " + project.getProjectId() + " from the server.");
}
Also used : Project(com.google.cloud.resourcemanager.Project) ResourceManager(com.google.cloud.resourcemanager.ResourceManager)

Example 2 with Project

use of com.google.cloud.resourcemanager.Project in project google-cloud-java by GoogleCloudPlatform.

the class ModifyPolicy method main.

public static void main(String... args) {
    // Create Resource Manager service object
    // By default, credentials are inferred from the runtime environment.
    ResourceManager resourceManager = ResourceManagerOptions.getDefaultInstance().getService();
    // Get a project from the server
    // Use an existing project's ID
    String projectId = "some-project-id";
    Project project = resourceManager.get(projectId);
    // Get the project's policy
    Policy policy = project.getPolicy();
    // Add a viewer
    Policy.Builder modifiedPolicy = policy.toBuilder();
    Identity newViewer = Identity.user("<insert user's email address here>");
    modifiedPolicy.addIdentity(Role.viewer(), newViewer);
    // Write policy
    Policy updatedPolicy = project.replacePolicy(modifiedPolicy.build());
    // Print policy
    System.out.printf("Updated policy for %s: %n%s%n", projectId, updatedPolicy);
}
Also used : Policy(com.google.cloud.Policy) Project(com.google.cloud.resourcemanager.Project) ResourceManager(com.google.cloud.resourcemanager.ResourceManager) Identity(com.google.cloud.Identity)

Example 3 with Project

use of com.google.cloud.resourcemanager.Project in project google-cloud-java by GoogleCloudPlatform.

the class UpdateAndListProjects method main.

public static void main(String... args) {
    // Create Resource Manager service object
    // By default, credentials are inferred from the runtime environment.
    ResourceManager resourceManager = ResourceManagerOptions.getDefaultInstance().getService();
    // Get a project from the server
    // Use an existing project's ID
    Project project = resourceManager.get("some-project-id");
    // Update a project
    if (project != null) {
        Project newProject = project.toBuilder().addLabel("launch-status", "in-development").build().replace();
        System.out.println("Updated the labels of project " + newProject.getProjectId() + " to be " + newProject.getLabels());
    }
    // List all the projects you have permission to view.
    System.out.println("Projects I can view:");
    for (Project currentProject : resourceManager.list().iterateAll()) {
        System.out.println(currentProject.getProjectId());
    }
}
Also used : Project(com.google.cloud.resourcemanager.Project) ResourceManager(com.google.cloud.resourcemanager.ResourceManager)

Aggregations

Project (com.google.cloud.resourcemanager.Project)3 ResourceManager (com.google.cloud.resourcemanager.ResourceManager)3 Identity (com.google.cloud.Identity)1 Policy (com.google.cloud.Policy)1