@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); } }
private synchronized Storage getService() throws IOException, GeneralSecurityException { logger.trace("Getting Google Cloud Storage service"); // leave this here for tests because they do things like manipulate properties dynamically to test invalid values this.bucketName = properties.getProperty( "usergrid.binary.bucketname" ); if (instance == null) { // Google provides different authentication types which are different based on if the application is // running within GCE(Google Compute Engine) or GAE (Google App Engine). If Usergrid is running in // GCE or GAE, the SDK will automatically authenticate and get access to // cloud storage. Else, the full path to a credential file should be provided in the following environment variable // // GOOGLE_APPLICATION_CREDENTIALS // // The SDK will attempt to load the credential file for a service account. See the following // for more info: https://developers.google.com/identity/protocols/application-default-credentials#howtheywork GoogleCredentials credentials = GoogleCredentials.getApplicationDefault().createScoped(StorageScopes.all()); final TransportOptions transportOptions = HttpTransportOptions.newBuilder() .setConnectTimeout(30000) // in milliseconds .setReadTimeout(30000) // in milliseconds .build(); instance = StorageOptions.newBuilder() .setCredentials(credentials) .setTransportOptions(transportOptions) .build() .getService(); } return instance; }
public Storage getStorage() throws IOException { JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); HttpTransport httpTransport = buildHttpTransport(); GoogleCredential credential = getCredential(httpTransport, jsonFactory, StorageScopes.all()); HttpRequestInitializer reqInit = setHttpTimeout(credential); String applicationName = "Spinnaker/" + applicationVersion; return new Storage.Builder(httpTransport, jsonFactory, credential) .setApplicationName(applicationName) .setHttpRequestInitializer(reqInit) .build(); }
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(); } }
private static GoogleCredential loadStorageCredential(HttpTransport transport, JsonFactory factory, String jsonPath) throws IOException { GoogleCredential credential; if (!jsonPath.isEmpty()) { FileInputStream stream = new FileInputStream(jsonPath); credential = GoogleCredential.fromStream(stream, transport, factory); log.info("Loaded storage credentials from " + jsonPath); } else { log.info("Using storage default application credentials."); credential = GoogleCredential.getApplicationDefault(); } if (credential.createScopedRequired()) { credential = credential.createScoped(StorageScopes.all()); } return credential; } }
private static GoogleCredential loadStorageCredential(HttpTransport transport, JsonFactory factory, String jsonPath) throws IOException { GoogleCredential credential; if (!jsonPath.isEmpty()) { FileInputStream stream = new FileInputStream(jsonPath); credential = GoogleCredential.fromStream(stream, transport, factory); log.info("Loaded storage credentials from " + jsonPath); } else { log.info("Using storage default application credentials."); credential = GoogleCredential.getApplicationDefault(); } if (credential.createScopedRequired()) { credential = credential.createScoped(StorageScopes.all()); } return credential; } }
public Storage getStorage() throws IOException { JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); HttpTransport httpTransport = buildHttpTransport(); GoogleCredential credential = getCredential(httpTransport, jsonFactory, StorageScopes.all()); HttpRequestInitializer reqInit = setHttpTimeout(credential); String applicationName = "Spinnaker/" + applicationVersion; return new Storage.Builder(httpTransport, jsonFactory, credential) .setApplicationName(applicationName) .setHttpRequestInitializer(reqInit) .build(); }