com.google.gcloud.resourcemanager.spi.DefaultResourceManagerRpc Maven / Gradle / Ivy
package com.google.gcloud.resourcemanager.spi;
import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.gcloud.resourcemanager.spi.ResourceManagerRpc.Option.FIELDS;
import static com.google.gcloud.resourcemanager.spi.ResourceManagerRpc.Option.FILTER;
import static com.google.gcloud.resourcemanager.spi.ResourceManagerRpc.Option.PAGE_SIZE;
import static com.google.gcloud.resourcemanager.spi.ResourceManagerRpc.Option.PAGE_TOKEN;
import static java.net.HttpURLConnection.HTTP_FORBIDDEN;
import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.jackson.JacksonFactory;
import com.google.api.services.cloudresourcemanager.Cloudresourcemanager;
import com.google.api.services.cloudresourcemanager.model.GetIamPolicyRequest;
import com.google.api.services.cloudresourcemanager.model.ListProjectsResponse;
import com.google.api.services.cloudresourcemanager.model.Policy;
import com.google.api.services.cloudresourcemanager.model.Project;
import com.google.api.services.cloudresourcemanager.model.SetIamPolicyRequest;
import com.google.api.services.cloudresourcemanager.model.TestIamPermissionsRequest;
import com.google.api.services.cloudresourcemanager.model.TestIamPermissionsResponse;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.gcloud.resourcemanager.ResourceManagerException;
import com.google.gcloud.resourcemanager.ResourceManagerOptions;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class DefaultResourceManagerRpc implements ResourceManagerRpc {
private final Cloudresourcemanager resourceManager;
public DefaultResourceManagerRpc(ResourceManagerOptions options) {
HttpTransport transport = options.httpTransportFactory().create();
HttpRequestInitializer initializer = options.httpRequestInitializer();
resourceManager =
new Cloudresourcemanager.Builder(transport, new JacksonFactory(), initializer)
.setRootUrl(options.host())
.setApplicationName(options.applicationName())
.build();
}
private static ResourceManagerException translate(IOException exception) {
return new ResourceManagerException(exception);
}
@Override
public Project create(Project project) {
try {
return resourceManager.projects().create(project).execute();
} catch (IOException ex) {
throw translate(ex);
}
}
@Override
public void delete(String projectId) {
try {
resourceManager.projects().delete(projectId).execute();
} catch (IOException ex) {
throw translate(ex);
}
}
@Override
public Project get(String projectId, Map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy