Search in sources :

Example 1 with Source

use of com.google.api.services.source.Source in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudRepositoryService method list.

@NotNull
public ListReposResponse list(CredentialedUser user, String cloudProject) throws CloudRepositoryServiceException {
    try {
        Credential credential = user.getCredential();
        HttpRequestInitializer initializer = httpRequest -> {
            HttpHeaders headers = new HttpHeaders();
            httpRequest.setConnectTimeout(LIST_TIMEOUT_MS);
            httpRequest.setReadTimeout(LIST_TIMEOUT_MS);
            httpRequest.setHeaders(headers);
            credential.initialize(httpRequest);
        };
        HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
        String userAgent = ServiceManager.getService(PluginInfoService.class).getUserAgent();
        Source source = new Source.Builder(httpTransport, JacksonFactory.getDefaultInstance(), initializer).setRootUrl(CLOUD_SOURCE_API_ROOT_URL).setServicePath("").setApplicationName(userAgent).build();
        return new CustomUrlSourceRequest(source, cloudProject).execute();
    } catch (IOException | GeneralSecurityException ex) {
        throw new CloudRepositoryServiceException();
    }
}
Also used : HttpHeaders(com.google.api.client.http.HttpHeaders) ListReposResponse(com.google.api.services.source.model.ListReposResponse) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory) HttpTransport(com.google.api.client.http.HttpTransport) GoogleNetHttpTransport(com.google.api.client.googleapis.javanet.GoogleNetHttpTransport) IOException(java.io.IOException) CompletableFuture(java.util.concurrent.CompletableFuture) Preconditions(com.google.api.client.util.Preconditions) Source(com.google.api.services.source.Source) ServiceManager(com.intellij.openapi.components.ServiceManager) GeneralSecurityException(java.security.GeneralSecurityException) HttpRequestInitializer(com.google.api.client.http.HttpRequestInitializer) CredentialedUser(com.google.cloud.tools.intellij.login.CredentialedUser) PluginInfoService(com.google.cloud.tools.intellij.service.PluginInfoService) Key(com.google.api.client.util.Key) Credential(com.google.api.client.auth.oauth2.Credential) SourceRequest(com.google.api.services.source.SourceRequest) NotNull(org.jetbrains.annotations.NotNull) HttpHeaders(com.google.api.client.http.HttpHeaders) Credential(com.google.api.client.auth.oauth2.Credential) GeneralSecurityException(java.security.GeneralSecurityException) PluginInfoService(com.google.cloud.tools.intellij.service.PluginInfoService) IOException(java.io.IOException) Source(com.google.api.services.source.Source) HttpTransport(com.google.api.client.http.HttpTransport) GoogleNetHttpTransport(com.google.api.client.googleapis.javanet.GoogleNetHttpTransport) HttpRequestInitializer(com.google.api.client.http.HttpRequestInitializer) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Credential (com.google.api.client.auth.oauth2.Credential)1 GoogleNetHttpTransport (com.google.api.client.googleapis.javanet.GoogleNetHttpTransport)1 HttpHeaders (com.google.api.client.http.HttpHeaders)1 HttpRequestInitializer (com.google.api.client.http.HttpRequestInitializer)1 HttpTransport (com.google.api.client.http.HttpTransport)1 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)1 Key (com.google.api.client.util.Key)1 Preconditions (com.google.api.client.util.Preconditions)1 Source (com.google.api.services.source.Source)1 SourceRequest (com.google.api.services.source.SourceRequest)1 ListReposResponse (com.google.api.services.source.model.ListReposResponse)1 CredentialedUser (com.google.cloud.tools.intellij.login.CredentialedUser)1 PluginInfoService (com.google.cloud.tools.intellij.service.PluginInfoService)1 ServiceManager (com.intellij.openapi.components.ServiceManager)1 IOException (java.io.IOException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 NotNull (org.jetbrains.annotations.NotNull)1