Refine search
this.monitor = monitor; this.storage = StorageOptions.newBuilder() .setProjectId(projectId) .setCredentials(googleCredentials) .build() .getService();
@Test public void testInvalidTransport() { thrown.expect(IllegalArgumentException.class); StorageOptions.newBuilder().setTransportOptions(EasyMock.createMock(TransportOptions.class)); } }
@Test public void testRuntimeException() { BlobId blob = BlobId.of(BUCKET_NAME1, BLOB_NAME1); String exceptionMessage = "Artificial runtime exception"; EasyMock.expect(storageRpcMock.get(blob.toPb(), EMPTY_RPC_OPTIONS)) .andThrow(new RuntimeException(exceptionMessage)); EasyMock.replay(storageRpcMock); storage = options .toBuilder() .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) .build() .getService(); thrown.expect(StorageException.class); thrown.expectMessage(exceptionMessage); storage.get(blob); } }
throws StorageHelperException { try { HttpTransportOptions transportOptions = StorageOptions.getDefaultHttpTransportOptions(); transportOptions = transportOptions.toBuilder().setConnectTimeout(60000).setReadTimeout(60000).build(); StorageOptions storageOptions = StorageOptions.newBuilder() .setCredentials(GoogleCredentials.fromStream(keyStream)) .setProjectId(projectId) .setRetrySettings(retrySettings()) .setTransportOptions(transportOptions) .build(); return new RemoteStorageHelper(storageOptions); } catch (IOException ex) {
@Override protected Serializable[] serializableObjects() { StorageOptions options = StorageOptions.newBuilder() .setProjectId("p1") .setCredentials(NoCredentials.getInstance()) .build(); StorageOptions otherOptions = options.toBuilder().setProjectId("p2").build(); return new Serializable[] { ACL_DOMAIN,
ServiceAccountCredentials credentials = new ServiceAccountCredentials(null, ACCOUNT, privateKey, null, null); storage = options.toBuilder().setCredentials(credentials).build().getService(); URL url = storage.signUrl(BLOB_INFO1, 14, TimeUnit.DAYS); String stringUrl = url.toString();
/** Returns a default {@code StorageOptions} instance. */ public static StorageOptions getDefaultInstance() { return newBuilder().build(); }
/** * Creates a {@code RemoteStorageHelper} object using default project id and authentication * credentials. */ public static RemoteStorageHelper create() throws StorageHelperException { HttpTransportOptions transportOptions = StorageOptions.getDefaultHttpTransportOptions(); transportOptions = transportOptions.toBuilder().setConnectTimeout(60000).setReadTimeout(60000).build(); StorageOptions storageOptions = StorageOptions.newBuilder() .setRetrySettings(retrySettings()) .setTransportOptions(transportOptions) .build(); return new RemoteStorageHelper(storageOptions); }
return; StorageOptions.Builder optionsBuilder = StorageOptions.newBuilder(); StorageAction action; String actionName; if (args.length >= 2 && !ACTIONS.containsKey(args[0])) { actionName = args[1]; optionsBuilder.setProjectId(args[0]); action = ACTIONS.get(args[1]); args = Arrays.copyOfRange(args, 2, args.length); return; Storage storage = optionsBuilder.build().getService(); Object arg; try {
ServiceAccountCredentials credentials = new ServiceAccountCredentials(null, ACCOUNT, privateKey, null, null); storage = options.toBuilder().setCredentials(credentials).build().getService(); URL url = storage.signUrl(
/** * Lists the project's buckets. Pass "null" to use the default project. * * <p>Example of listing buckets, specifying the page size and a name prefix. * * <pre>{@code * String prefix = "bucket_"; * Page<Bucket> buckets = CloudStorageFileSystem.listBuckets("my-project", BucketListOption.prefix(prefix)); * Iterator<Bucket> bucketIterator = buckets.iterateAll(); * while (bucketIterator.hasNext()) { * Bucket bucket = bucketIterator.next(); * // do something with the bucket * } * }</pre> * * @throws StorageException upon failure */ public static Page<Bucket> listBuckets( @Nullable String project, Storage.BucketListOption... options) { CloudStorageFileSystemProvider provider = new CloudStorageFileSystemProvider( null, StorageOptions.newBuilder().setProjectId(project).build()); return provider.listBuckets(options); }
throws StorageHelperException { try { HttpTransportOptions transportOptions = StorageOptions.getDefaultHttpTransportOptions(); transportOptions = transportOptions.toBuilder().setConnectTimeout(60000).setReadTimeout(60000).build(); StorageOptions storageOptions = StorageOptions.newBuilder() .setCredentials(GoogleCredentials.fromStream(keyStream)) .setProjectId(projectId) .setRetrySettings(retrySettings()) .setTransportOptions(transportOptions) .build(); return new RemoteStorageHelper(storageOptions); } catch (IOException ex) {
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; }
ServiceAccountCredentials credentials = new ServiceAccountCredentials(null, ACCOUNT, privateKey, null, null); storage = options.toBuilder().setCredentials(credentials).build().getService(); URL url = storage.signUrl(BlobInfo.newBuilder(BUCKET_NAME1, blobName).build(), 14, TimeUnit.DAYS);
@Before public void setUp() { rpcFactoryMock = createMock(StorageRpcFactory.class); storageRpcMock = createMock(StorageRpc.class); expect(rpcFactoryMock.create(anyObject(StorageOptions.class))).andReturn(storageRpcMock); replay(rpcFactoryMock); options = StorageOptions.newBuilder() .setProjectId("projectid") .setServiceRpcFactory(rpcFactoryMock) .build(); }
/** * Creates a {@code RemoteStorageHelper} object using default project id and authentication * credentials. */ public static RemoteStorageHelper create() throws StorageHelperException { HttpTransportOptions transportOptions = StorageOptions.getDefaultHttpTransportOptions(); transportOptions = transportOptions.toBuilder().setConnectTimeout(60000).setReadTimeout(60000).build(); StorageOptions storageOptions = StorageOptions.newBuilder() .setRetrySettings(retrySettings()) .setTransportOptions(transportOptions) .build(); return new RemoteStorageHelper(storageOptions); }
@Before public void setUp() { rpcFactoryMock = createMock(StorageRpcFactory.class); storageRpcMock = createMock(StorageRpc.class); expect(rpcFactoryMock.create(anyObject(StorageOptions.class))).andReturn(storageRpcMock); replay(rpcFactoryMock); options = StorageOptions.newBuilder() .setProjectId("projectid") .setServiceRpcFactory(rpcFactoryMock) .setRetrySettings(ServiceOptions.getNoRetrySettings()) .build(); result = new Blob(options.getService(), new BlobInfo.BuilderImpl(RESULT_INFO)); }
ServiceAccountCredentials credentials = new ServiceAccountCredentials(null, ACCOUNT, privateKey, null, null); storage = options.toBuilder().setCredentials(credentials).build().getService();
/** Returns a unauthenticated {@code StorageOptions} instance. */ public static StorageOptions getUnauthenticatedInstance() { return newBuilder().setCredentials(NoCredentials.getInstance()).build(); }
@Test(timeout = 5000) public void testWriteChannelWithConnectionPool() throws IOException { TransportOptions transportOptions = HttpTransportOptions.newBuilder() .setHttpTransportFactory(new CustomHttpTransportFactory()) .build(); Storage storageWithPool = StorageOptions.newBuilder().setTransportOptions(transportOptions).build().getService(); String blobName = "test-custom-pool-management"; BlobInfo blob = BlobInfo.newBuilder(BUCKET, blobName).build(); byte[] stringBytes; try (WriteChannel writer = storageWithPool.writer(blob)) { stringBytes = BLOB_STRING_CONTENT.getBytes(UTF_8); writer.write(ByteBuffer.wrap(BLOB_BYTE_CONTENT)); writer.write(ByteBuffer.wrap(stringBytes)); } try (WriteChannel writer = storageWithPool.writer(blob)) { stringBytes = BLOB_STRING_CONTENT.getBytes(UTF_8); writer.write(ByteBuffer.wrap(BLOB_BYTE_CONTENT)); writer.write(ByteBuffer.wrap(stringBytes)); } }