private Storage constructGcsStorageHandle() { if (this.gcsStorageHandle != null) { return this.gcsStorageHandle; } try { constructGcsCredential(); } catch (Exception e) { throw new IllegalStateException("Exception during GCS authorization", e); } this.gcsStorageHandle = new Storage.Builder(this.httpTransport, JSON_FACTORY, this.credential) .setApplicationName(APPLICATION_NAME) .build(); return this.gcsStorageHandle; }
@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); } }
storage = new Storage.Builder(httpTransport, JacksonFactory.getDefaultInstance(), cred) .setApplicationName(projectName).build();
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(); }
public static Storage.Objects createStorageClient(GCSOptions gcsOptions, OfflineAuth auth) { final Storage.Builder storageBuilder = new Storage.Builder( gcsOptions.getTransport(), gcsOptions.getJsonFactory(), null); return gcsOptions.getGenomicsFactory() .fromOfflineAuth(storageBuilder, auth) .build() .objects(); }
private Storage createClient() throws IOException, GeneralSecurityException { GoogleCredential credential = GoogleCredential.fromStream( new ByteArrayInputStream(settings.serviceAccount.getBytes(StandardCharsets.UTF_8))) .createScoped(Collections.singleton(StorageScopes.CLOUD_PLATFORM)); NetHttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance(); return new Storage.Builder( httpTransport, JSON_FACTORY, null).setApplicationName(APPLICATION_NAME) .setHttpRequestInitializer(credential).build(); } }
private Storage buildCredentials(GoogleSecureStorageProperties properties) { HttpTransport transport = new NetHttpTransport(); JsonFactory jsonFactory = new JacksonFactory(); GoogleCredential credential; try { credential = loadStorageCredential(transport, jsonFactory, properties.getJsonPath()); } catch (IOException e) { throw new RuntimeException("Unable to load KMS credentials: " + e.getMessage(), e); } return new Storage.Builder(transport, jsonFactory, credential) .setApplicationName("halyard") .build(); }
public static Storage.Objects createStorageClient(GCSOptions gcsOptions, OfflineAuth auth) { final Storage.Builder storageBuilder = new Storage.Builder( gcsOptions.getTransport(), gcsOptions.getJsonFactory(), null); return gcsOptions.getGenomicsFactory() .fromOfflineAuth(storageBuilder, auth) .build() .objects(); }
public DefaultStorageRpc(StorageOptions options) { HttpTransport transport = options.httpTransportFactory().create(); HttpRequestInitializer initializer = options.httpRequestInitializer(); this.options = options; storage = new Storage.Builder(transport, new JacksonFactory(), initializer) .setRootUrl(options.host()) .setApplicationName(options.applicationName()) .build(); }
@Override protected Storage client(GoogleCredential credential, HttpTransport transport, JsonFactory jsonFactory) { if (credential.createScopedRequired()) { credential = credential.createScoped(BigqueryScopes.all()); } return new Storage.Builder(transport, jsonFactory, credential) .setApplicationName("Digdag") .build(); }
SampleSettings settings = SampleSettings.load(jsonFactory); Credential credential = CredentialsProvider.authorize(httpTransport, jsonFactory); Storage storage = new Storage.Builder(httpTransport, jsonFactory, credential) .setApplicationName(APPLICATION_NAME).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(); } }
public static void main(String[] args) throws Exception { HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); Credential credential = CredentialsProvider.authorize(httpTransport, jsonFactory); Storage storage = new Storage.Builder(httpTransport, jsonFactory, credential) .setApplicationName("Google-ObjectsDownloadExample/1.0").build(); ByteArrayOutputStream out = new ByteArrayOutputStream(); downloadToOutputStream(storage, BUCKET_NAME, OBJECT_NAME, out); System.out.println("Downloaded " + out.toByteArray().length + " bytes"); } }
public static void main(String[] args) throws Exception { HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); Credential credential = CredentialsProvider.authorize(httpTransport, jsonFactory); Storage storage = new Storage.Builder(httpTransport, jsonFactory, credential) .setApplicationName("Google-BucketsInsertExample/1.0").build(); createInProject(storage, PROJECT_NAME, new Bucket().setName(BUCKET_NAME) .setLocation(BUCKET_LOCATION)); }
public static void main(String[] args) throws Exception { HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); Credential credential = CredentialsProvider.authorize(httpTransport, jsonFactory); Storage storage = new Storage.Builder(httpTransport, jsonFactory, credential) .setApplicationName("Google-ObjectsListExample/1.0").build(); for (StorageObject object : list(storage, BUCKET_NAME)) { System.out.println(object.getName() + " (size: " + object.getSize() + ")"); } } }
public static void main(String[] args) throws Exception { HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); Credential credential = CredentialsProvider.authorize(httpTransport, jsonFactory); Storage storage = new Storage.Builder(httpTransport, jsonFactory, credential) .setApplicationName("Google-BucketsGetExample/1.0").build(); get(storage, BUCKET_NAME); }
public static void main(String[] args) throws Exception { HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); Credential credential = CredentialsProvider.authorize(httpTransport, jsonFactory); Storage storage = new Storage.Builder(httpTransport, jsonFactory, credential) .setApplicationName("Google-ObjectsGetMetadataExample/1.0").build(); StorageObject object = get(storage, BUCKET_NAME, OBJECT_NAME); System.out.println(object.getName() + " (size: " + object.getSize() + ")"); }
public static void main(String[] args) throws Exception { HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); Credential credential = CredentialsProvider.authorize(httpTransport, jsonFactory); Storage storage = new Storage.Builder(httpTransport, jsonFactory, credential) .setApplicationName("Google-ObjectsUploadExample/1.0").build(); StorageObject object = uploadSimple(storage, BUCKET_NAME, OBJECT_NAME, new File(FILE_NAME)); System.out.println(object.getName() + " (size: " + object.getSize() + ")"); }
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(); }
public HttpStorageRpc(StorageOptions options) { HttpTransportOptions transportOptions = (HttpTransportOptions) options.getTransportOptions(); HttpTransport transport = transportOptions.getHttpTransportFactory().create(); HttpRequestInitializer initializer = transportOptions.getHttpRequestInitializer(options); this.options = options; // Open Census initialization censusHttpModule = new CensusHttpModule(tracer, true); initializer = censusHttpModule.getHttpRequestInitializer(initializer); batchRequestInitializer = censusHttpModule.getHttpRequestInitializer(null); HttpStorageRpcSpans.registerAllSpanNamesForCollection(); storage = new Storage.Builder(transport, new JacksonFactory(), initializer) .setRootUrl(options.getHost()) .setApplicationName(options.getApplicationName()) .build(); }