@Inject GoogleAppSecretDecrypter( HttpTransport transport, JsonFactory jsonFactory, @ProjectId String projectId) throws GoogleCredentialException { GoogleCredential credential; try { credential = GoogleCredential.getApplicationDefault(transport, jsonFactory); } catch (IOException e) { throw new GoogleCredentialException( "Problem obtaining credentials via GoogleCredential.getApplicationDefault()"); } if (credential.createScopedRequired()) { credential = credential.createScoped(CloudKMSScopes.all()); } this.cloudKMS = new CloudKMS.Builder(transport, jsonFactory, credential) .setApplicationName("GoogleAppSecretDecrypter") .build(); this.secretsCryptoKey = String.format(SECRETS_CRYPTO_KEY_FMT_STRING, projectId); }
Credential credential = GoogleCredential.getApplicationDefault(); if (serviceAccountEmail != null && privateKeyFile != null) { credential = DatastoreHelper.getServiceAccountCredential(
@Provides @LazySingleton public GoogleStorage getGoogleStorage(final GoogleAccountConfig config) throws IOException, GeneralSecurityException { LOG.info("Building Cloud Storage Client..."); HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); GoogleCredential credential = GoogleCredential.getApplicationDefault(httpTransport, jsonFactory); if (credential.createScopedRequired()) { credential = credential.createScoped(StorageScopes.all()); } Storage storage = new Storage.Builder(httpTransport, jsonFactory, credential).setApplicationName(APPLICATION_NAME).build(); return new GoogleStorage(storage); } }
protected GoogleCredential getCredential(HttpTransport httpTransport, JsonFactory jsonFactory, Collection<String> scopes) throws IOException { log.debug("Loading credentials for project {} using application default credentials, with scopes {}.", project, scopes); // No JSON key was specified in matching config on key server, so use application default credentials. return GoogleCredential.getApplicationDefault().createScoped(scopes); }
/** * Create a Storage Transfer client using application default credentials and other default * settings. * * @return a Storage Transfer client * @throws IOException * there was an error obtaining application default credentials */ public static Storagetransfer createStorageTransferClient() throws IOException { HttpTransport httpTransport = Utils.getDefaultTransport(); JsonFactory jsonFactory = Utils.getDefaultJsonFactory(); GoogleCredential credential = GoogleCredential.getApplicationDefault(httpTransport, jsonFactory); return createStorageTransferClient(httpTransport, jsonFactory, credential); }
GoogleCredential credential = GoogleCredential.getApplicationDefault(); if (credential.createScopedRequired()) { List<String> scopes = new ArrayList<>();
/** * Fetches the listing of the given bucket. * * @param bucketName the name of the bucket to list. * * @return the raw XML containing the listing of the bucket. * @throws IOException if there's an error communicating with Cloud Storage. * @throws GeneralSecurityException for errors creating https connection. */ public static String listBucket(final String bucketName) throws IOException, GeneralSecurityException { //[START snippet] // Build an account credential. GoogleCredential credential = GoogleCredential.getApplicationDefault() .createScoped(Collections.singleton(STORAGE_SCOPE)); // Set up and execute a Google Cloud Storage request. String uri = "https://storage.googleapis.com/" + URLEncoder.encode(bucketName, "UTF-8"); HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); HttpRequestFactory requestFactory = httpTransport.createRequestFactory( credential); GenericUrl url = new GenericUrl(uri); HttpRequest request = requestFactory.buildGetRequest(url); HttpResponse response = request.execute(); String content = response.parseAsString(); //[END snippet] return content; }
/** * Connects to the Vision API using Application Default Credentials. */ public static Vision getVisionService() throws IOException, GeneralSecurityException { GoogleCredential credential = GoogleCredential.getApplicationDefault().createScoped(VisionScopes.all()); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); return new Vision.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, credential) .setApplicationName(APPLICATION_NAME) .build(); }
/** * Connects to the Vision API using Application Default Credentials. */ public static Vision getVisionService() throws IOException, GeneralSecurityException { GoogleCredential credential = GoogleCredential.getApplicationDefault().createScoped(VisionScopes.all()); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); return new Vision.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, credential) .setApplicationName(APPLICATION_NAME) .build(); }
/** * Connects to the Vision API using Application Default Credentials. */ public static Vision getVisionService() throws IOException, GeneralSecurityException { GoogleCredential credential = GoogleCredential.getApplicationDefault().createScoped(VisionScopes.all()); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); return new Vision.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, credential) .setApplicationName(APPLICATION_NAME) .build(); } // [END vision_face_detection_tutorial_client]
/** * Connects to the Vision API using Application Default Credentials. */ public static Vision getVisionService() throws IOException, GeneralSecurityException { GoogleCredential credential = GoogleCredential.getApplicationDefault().createScoped(VisionScopes.all()); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); return new Vision.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, credential) .setApplicationName(APPLICATION_NAME) .build(); }
System.out.println(content.getLength()); GoogleCredential credential = GoogleCredential.getApplicationDefault(); HttpRequestFactory requestFactory = httpTransport.createRequestFactory(credential); HttpRequest request = requestFactory.buildRequest(method.getHttpMethod(), url, content);
private static Storage buildService() throws IOException, GeneralSecurityException { HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport(); JsonFactory jsonFactory = new JacksonFactory(); GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory); // Depending on the environment that provides the default credentials (for // example: Compute Engine, App Engine), the credentials may require us to // specify the scopes we need explicitly. Check for this case, and inject // the Cloud Storage scope if required. if (credential.createScopedRequired()) { Collection<String> scopes = StorageScopes.all(); credential = credential.createScoped(scopes); } return new Storage.Builder(transport, jsonFactory, credential) .setApplicationName("GCS Samples") .build(); } }
GoogleCredential credential = GoogleCredential.getApplicationDefault(); credential = credential.createScoped(Arrays.asList("https://www.googleapis.com/auth/bigquery"));
GoogleCredential credential = GoogleCredential.getApplicationDefault(); credential = credential.createScoped(Arrays.asList("https://www.googleapis.com/auth/bigquery"));
@Override public GoogleCredential getCredential() { try { return GoogleCredential.getApplicationDefault(); } catch (IOException e) { throw new RuntimeException("Failed to load application default GoogleCredential", e); } } }
public static GoogleIdTokenAuth ofDefaultCredential() { try { return of(Optional.of(GoogleCredential.getApplicationDefault())); } catch (IOException e) { return of(Optional.empty()); } }
private GoogleCredential getGoogleCredential(GcpIamProperties gcp) throws IOException { GcpCredentials credentialProperties = gcp.getCredentials(); if (credentialProperties.getLocation() != null) { return GoogleCredential.fromStream(credentialProperties.getLocation() .getInputStream()); } if (StringUtils.hasText(credentialProperties.getEncodedKey())) { return GoogleCredential.fromStream(new ByteArrayInputStream(Base64 .getDecoder().decode(credentialProperties.getEncodedKey()))); } return GoogleCredential.getApplicationDefault(); }
private GoogleCredential getGoogleCredential(GcpIamProperties gcp) throws IOException { GcpCredentials credentialProperties = gcp.getCredentials(); if (credentialProperties.getLocation() != null) { return GoogleCredential.fromStream(credentialProperties.getLocation() .getInputStream()); } if (StringUtils.hasText(credentialProperties.getEncodedKey())) { return GoogleCredential.fromStream(new ByteArrayInputStream(Base64 .getDecoder().decode(credentialProperties.getEncodedKey()))); } return GoogleCredential.getApplicationDefault(); }
/** * Creates a Cloud Pub/Sub client. */ public Pubsub createPubsubClient() throws IOException, GeneralSecurityException { HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport(); GoogleCredential credential = GoogleCredential.getApplicationDefault(); HttpRequestInitializer initializer = new RetryHttpInitializerWrapper(credential); return new Pubsub.Builder(transport, JSON_FACTORY, initializer).build(); }