Search in sources :

Example 91 with HttpTransport

use of com.google.api.client.http.HttpTransport in project hub-alert by blackducksoftware.

the class AzureBoardsProperties method hasOAuthCredentials.

public boolean hasOAuthCredentials(ProxyInfo proxy) {
    HttpTransport httpTransport = createHttpTransport(proxy);
    try {
        AuthorizationCodeFlow oAuthFlow = createOAuthFlow(httpTransport);
        Optional<Credential> oAuthCredential = getExistingOAuthCredential(oAuthFlow);
        return oAuthCredential.isPresent();
    } catch (IOException e) {
        return false;
    }
}
Also used : HttpTransport(com.google.api.client.http.HttpTransport) ApacheHttpTransport(com.google.api.client.http.apache.v2.ApacheHttpTransport) Credential(com.google.api.client.auth.oauth2.Credential) StoredCredential(com.google.api.client.auth.oauth2.StoredCredential) IOException(java.io.IOException) AuthorizationCodeFlow(com.google.api.client.auth.oauth2.AuthorizationCodeFlow) AzureAuthorizationCodeFlow(com.synopsys.integration.azure.boards.common.oauth.AzureAuthorizationCodeFlow)

Example 92 with HttpTransport

use of com.google.api.client.http.HttpTransport in project hub-alert by blackducksoftware.

the class AzureBoardsProperties method createAzureHttpRequestCreator.

public AzureHttpRequestCreator createAzureHttpRequestCreator(ProxyInfo proxyInfo, Gson gson) throws AlertException {
    HttpTransport httpTransport = createHttpTransport(proxyInfo);
    try {
        AuthorizationCodeFlow oAuthFlow = createOAuthFlow(httpTransport);
        Credential oAuthCredential = getExistingOAuthCredential(oAuthFlow).orElseThrow(() -> new AlertException(String.format("No existing Azure OAuth credential associated with '%s'", oauthUserId)));
        return AzureHttpRequestCreatorFactory.withCredential(httpTransport, oAuthCredential, gson);
    } catch (IOException e) {
        throw new AlertException("Cannot read OAuth credentials", e);
    }
}
Also used : HttpTransport(com.google.api.client.http.HttpTransport) ApacheHttpTransport(com.google.api.client.http.apache.v2.ApacheHttpTransport) Credential(com.google.api.client.auth.oauth2.Credential) StoredCredential(com.google.api.client.auth.oauth2.StoredCredential) IOException(java.io.IOException) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) AuthorizationCodeFlow(com.google.api.client.auth.oauth2.AuthorizationCodeFlow) AzureAuthorizationCodeFlow(com.synopsys.integration.azure.boards.common.oauth.AzureAuthorizationCodeFlow)

Example 93 with HttpTransport

use of com.google.api.client.http.HttpTransport in project hub-alert by blackducksoftware.

the class AzureBoardsProperties method createAzureHttpService.

public AzureHttpService createAzureHttpService(ProxyInfo proxy, Gson gson, String authorizationCode) throws AlertException {
    HttpTransport httpTransport = createHttpTransport(proxy);
    try {
        AuthorizationCodeFlow oAuthFlow = createOAuthFlow(httpTransport);
        Credential oAuthCredential = requestTokens(oAuthFlow, authorizationCode).orElseThrow(() -> new AlertException(String.format("Cannot request Azure OAuth credential associated with '%s'", oauthUserId)));
        AzureHttpRequestCreator httpRequestCreator = AzureHttpRequestCreatorFactory.withCredential(httpTransport, oAuthCredential, gson);
        return new AzureHttpService(gson, httpRequestCreator);
    } catch (IOException e) {
        throw new AlertException("Cannot request OAuth credentials", e);
    }
}
Also used : HttpTransport(com.google.api.client.http.HttpTransport) ApacheHttpTransport(com.google.api.client.http.apache.v2.ApacheHttpTransport) Credential(com.google.api.client.auth.oauth2.Credential) StoredCredential(com.google.api.client.auth.oauth2.StoredCredential) AzureHttpRequestCreator(com.synopsys.integration.azure.boards.common.http.AzureHttpRequestCreator) IOException(java.io.IOException) AzureHttpService(com.synopsys.integration.azure.boards.common.http.AzureHttpService) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) AuthorizationCodeFlow(com.google.api.client.auth.oauth2.AuthorizationCodeFlow) AzureAuthorizationCodeFlow(com.synopsys.integration.azure.boards.common.oauth.AzureAuthorizationCodeFlow)

Example 94 with HttpTransport

use of com.google.api.client.http.HttpTransport in project cloudbreak by hortonworks.

the class GcpDeleteVpcTest method deleteNetwork.

@AfterSuite
@Parameters("vpcName")
public void deleteNetwork(@Optional("it-vpc") String vpcName) throws Exception {
    springTestContextPrepareTestInstance();
    String serviceAccountPrivateKey = ResourceUtil.readBase64EncodedContentFromResource(applicationContext, defaultP12File);
    HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
    PrivateKey privateKey = SecurityUtils.loadPrivateKeyFromKeyStore(SecurityUtils.getPkcs12KeyStore(), new ByteArrayInputStream(Base64.decodeBase64(serviceAccountPrivateKey)), "notasecret", "privatekey", "notasecret");
    JacksonFactory jsonFactory = JacksonFactory.getDefaultInstance();
    GoogleCredential googleCredential = new GoogleCredential.Builder().setTransport(httpTransport).setJsonFactory(jsonFactory).setServiceAccountId(defaultServiceAccountId).setServiceAccountScopes(Collections.singletonList(ComputeScopes.COMPUTE)).setServiceAccountPrivateKey(privateKey).build();
    Compute compute = new Builder(httpTransport, jsonFactory, null).setApplicationName(defaultName).setHttpRequestInitializer(googleCredential).build();
    Delete delete = compute.networks().delete(defaultProjectId, vpcName);
    Operation operation = delete.execute();
    if (operation.getHttpErrorStatusCode() != null) {
        throw new IllegalStateException("gcp operation failed: " + operation.getHttpErrorMessage());
    }
}
Also used : Delete(com.google.api.services.compute.Compute.Networks.Delete) HttpTransport(com.google.api.client.http.HttpTransport) GoogleNetHttpTransport(com.google.api.client.googleapis.javanet.GoogleNetHttpTransport) PrivateKey(java.security.PrivateKey) ByteArrayInputStream(java.io.ByteArrayInputStream) Builder(com.google.api.services.compute.Compute.Builder) Compute(com.google.api.services.compute.Compute) GoogleCredential(com.google.api.client.googleapis.auth.oauth2.GoogleCredential) Operation(com.google.api.services.compute.model.Operation) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory) Parameters(org.testng.annotations.Parameters) AfterSuite(org.testng.annotations.AfterSuite)

Example 95 with HttpTransport

use of com.google.api.client.http.HttpTransport in project pinpoint by naver.

the class HttpRequestIT method execute.

@Test
public void execute() throws Exception {
    HttpTransport NET_HTTP_TRANSPORT = new NetHttpTransport();
    HttpRequestFactory requestFactory = NET_HTTP_TRANSPORT.createRequestFactory(new HttpRequestInitializer() {

        @Override
        public void initialize(HttpRequest request) {
        }
    });
    GenericUrl url = new GenericUrl(webServer.getCallHttpUrl());
    HttpRequest request = null;
    HttpResponse response = null;
    try {
        request = requestFactory.buildGetRequest(url);
        response = request.execute();
    } catch (IOException ignored) {
    } finally {
        close(response);
    }
    Method executeMethod = HttpRequest.class.getDeclaredMethod("execute");
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
    verifier.verifyTrace(Expectations.event("GOOGLE_HTTP_CLIENT_INTERNAL", executeMethod));
}
Also used : HttpRequest(com.google.api.client.http.HttpRequest) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) HttpTransport(com.google.api.client.http.HttpTransport) HttpRequestFactory(com.google.api.client.http.HttpRequestFactory) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) HttpResponse(com.google.api.client.http.HttpResponse) GenericUrl(com.google.api.client.http.GenericUrl) IOException(java.io.IOException) Method(java.lang.reflect.Method) HttpRequestInitializer(com.google.api.client.http.HttpRequestInitializer) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) Test(org.junit.Test)

Aggregations

HttpTransport (com.google.api.client.http.HttpTransport)106 MockHttpTransport (com.google.api.client.testing.http.MockHttpTransport)40 JsonFactory (com.google.api.client.json.JsonFactory)35 HttpRequest (com.google.api.client.http.HttpRequest)29 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)28 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)28 GoogleCredential (com.google.api.client.googleapis.auth.oauth2.GoogleCredential)27 IOException (java.io.IOException)24 GoogleNetHttpTransport (com.google.api.client.googleapis.javanet.GoogleNetHttpTransport)21 HttpResponse (com.google.api.client.http.HttpResponse)21 GenericUrl (com.google.api.client.http.GenericUrl)15 MockLowLevelHttpRequest (com.google.api.client.testing.http.MockLowLevelHttpRequest)12 MockLowLevelHttpResponse (com.google.api.client.testing.http.MockLowLevelHttpResponse)11 Credential (com.google.api.client.auth.oauth2.Credential)10 HttpRequestFactory (com.google.api.client.http.HttpRequestFactory)10 Storage (com.google.api.services.storage.Storage)9 HttpRequestInitializer (com.google.api.client.http.HttpRequestInitializer)8 Test (org.junit.Test)8 Monitor (org.datatransferproject.api.launcher.Monitor)7 ErrorTransport (com.google.api.client.googleapis.json.GoogleJsonErrorTest.ErrorTransport)6