SampleSettings settings = SampleSettings.load(jsonFactory); Credential credential = CredentialsProvider.authorize(httpTransport, jsonFactory); Storage storage = new Storage.Builder(httpTransport, jsonFactory, credential) .setApplicationName(APPLICATION_NAME).build();
options .as(GCSOptions.class)) .build() .objects(); final SamReader reader = BAMIO.openBAM(storage, bamFilePath, ValidationStringency.SILENT, true,
options .as(GCSOptions.class)) .build() .objects(); final SamReader reader = BAMIO.openBAM(storage, bamFilePath, ValidationStringency.SILENT, true,
options .as(GCSOptions.class)) .build() .objects();
options .as(GCSOptions.class)) .build() .objects();
pipelineOptions .as(GCSOptions.class)) .build() .objects(); LOG.info("Cleaning up output file " + destPath + " and " + destIdxPath);
pipelineOptions .as(GCSOptions.class)) .build() .objects(); LOG.info("Cleaning up output file " + destPath + " and " + destIdxPath);
new Storage.Builder( transport, Transport.getJsonFactory(), new RetryHttpRequestInitializer( fakeClockAndSleeper, fakeClockAndSleeper, Collections.emptyList(), null)) .build();
readBAMSTransform.setAuth(auth); final Storage.Objects storage = Transport .newStorageClient(pipelineOptions.as(GCSOptions.class)).build().objects(); final List<BAMShard> shardsList = Sharder.shardBAMFile(storage, BAMFile, contigs, shardingPolicy);
readBAMSTransform.setAuth(auth); final Storage.Objects storage = Transport .newStorageClient(pipelineOptions.as(GCSOptions.class)).build().objects(); final List<BAMShard> shardsList = Sharder.shardBAMFile(storage, BAMFile, contigs, shardingPolicy);
executor, new Storage.Builder(transport, jsonFactory, credential) .setApplicationName("Cloud Pub/Sub Loadtest Framework") .build(), new Compute.Builder(transport, jsonFactory, credential) .setApplicationName("Cloud Pub/Sub Loadtest Framework")
this.gcs = new Storage.Builder( httpTransport, JSON_FACTORY, httpRequestInitializer) .setApplicationName(options.getAppName()) .build();
private static Storage getStorage() throws Exception { if (storage == null) { HttpTransport httpTransport = new NetHttpTransport(); JsonFactory jsonFactory = new JacksonFactory(); List<String> scopes = new ArrayList<String>(); scopes.add(StorageScopes.DEVSTORAGE_FULL_CONTROL); Credential credential = new GoogleCredential.Builder() .setTransport(httpTransport) .setJsonFactory(jsonFactory) .setServiceAccountId( getProperties().getProperty(ACCOUNT_ID_PROPERTY)) .setServiceAccountPrivateKeyFromP12File( new File(getProperties().getProperty( PRIVATE_KEY_PATH_PROPERTY))) .setServiceAccountScopes(scopes).build(); storage = new Storage.Builder(httpTransport, jsonFactory, credential).setApplicationName( getProperties().getProperty(APPLICATION_NAME_PROPERTY)) .build(); } return storage; } }
@Before public void setUp() { MockitoAnnotations.initMocks(this); HttpTransport lowLevelTransport = new HttpTransport() { @Override protected LowLevelHttpRequest buildRequest(String method, String url) throws IOException { return mockLowLevelRequest; } }; // Retry initializer will pass through to credential, since we can have // only a single HttpRequestInitializer, and we use multiple Credential // types in the SDK, not all of which allow for retry configuration. RetryHttpRequestInitializer initializer = new RetryHttpRequestInitializer( new MockNanoClock(), millis -> {}, Arrays.asList(418 /* I'm a teapot */), mockHttpResponseInterceptor); storage = new Storage.Builder(lowLevelTransport, jsonFactory, initializer) .setApplicationName("test") .build(); }
public Image getProfileImage(@Named("id") long id, @Named("imageName")String imageName){ try{ ProfileRecord pr = get(id); HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); GoogleCredential credential = GoogleCredential.getApplicationDefault(); Storage.Builder storageBuilder = new Storage.Builder(httpTransport,new JacksonFactory(),credential); Storage storage = storageBuilder.build(); Storage.Objects.Get getObject = storage.objects().get("mybucket", imageName); ByteArrayOutputStream out = new ByteArrayOutputStream(); // If you're not in AppEngine, download the whole thing in one request, if possible. getObject.getMediaHttpDownloader().setDirectDownloadEnabled(false); getObject.executeMediaAndDownloadTo(out); byte[] oldImageData = out.toByteArray(); out.close(); return ImagesServiceFactory.makeImage(oldImageData); }catch(Exception e){ logger.info("Error getting image named "+imageName); } return null; }
/** Returns a Cloud Storage client builder using the specified {@link GcsOptions}. */ public static Storage.Builder newStorageClient(GcsOptions options) { String servicePath = options.getGcsEndpoint(); Storage.Builder storageBuilder = new Storage.Builder( getTransport(), getJsonFactory(), chainHttpRequestInitializer( options.getGcpCredential(), // Do not log the code 404. Code up the stack will deal with 404's if needed, and // logging it by default clutters the output during file staging. new RetryHttpRequestInitializer( ImmutableList.of(404), new UploadIdResponseInterceptor()))) .setApplicationName(options.getAppName()) .setGoogleClientRequestInitializer(options.getGoogleApiTrace()); if (servicePath != null) { ApiComponents components = apiComponentsFromUrl(servicePath); storageBuilder.setRootUrl(components.rootUrl); storageBuilder.setServicePath(components.servicePath); storageBuilder.setBatchPath(Paths.get("batch/", components.servicePath).toString()); } return storageBuilder; }
@Test public void testMatchingAgainstRequestType() throws Exception { GcsOptions options = PipelineOptionsFactory.as(GcsOptions.class); options.setGcpCredential(new TestCredential()); options.setGoogleApiTrace( new GoogleApiTracer() .addTraceFor( Transport.newStorageClient(options) .build() .objects() .get("aProjectId", "aObjectId"), "TraceDestination")); Storage.Objects.Get getRequest = Transport.newStorageClient(options).build().objects().get("testBucketId", "testObjectId"); assertEquals("TraceDestination", getRequest.get("$trace")); Storage.Objects.List listRequest = Transport.newStorageClient(options).build().objects().list("testProjectId"); assertNull(listRequest.get("$trace")); }
private Storage createGoogleStorage(boolean useApplicationDefaultCreds) { JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); String applicationName = "Spinnaker/Halyard"; HttpRequestInitializer requestInitializer; try { GoogleCredential credential = useApplicationDefaultCreds ? GoogleCredential.getApplicationDefault() : new GoogleCredential(); if (credential.createScopedRequired()) { credential = credential.createScoped(Collections.singleton(StorageScopes.DEVSTORAGE_FULL_CONTROL)); } requestInitializer = GoogleCredentials.setHttpTimeout(credential); log.info("Loaded application default credential for reading BOMs & profiles."); } catch (Exception e) { requestInitializer = GoogleCredentials.retryRequestInitializer(); log.debug("No application default credential could be loaded for reading BOMs & profiles. Continuing unauthenticated: {}", e.getMessage()); } return new Storage.Builder(GoogleCredentials.buildHttpTransport(), jsonFactory, requestInitializer) .setApplicationName(applicationName) .build(); }
public GcsArtifactCredentials(String applicationName, GcsArtifactAccount account) throws IOException, GeneralSecurityException { HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport(); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); String credentialsPath = account.getJsonPath(); GoogleCredential credential; if (!StringUtils.isEmpty(credentialsPath)) { FileInputStream stream = new FileInputStream(credentialsPath); credential = GoogleCredential.fromStream(stream, transport, jsonFactory) .createScoped(Collections.singleton(StorageScopes.DEVSTORAGE_READ_ONLY)); log.info("Loaded credentials from {}", credentialsPath); } else { log.info("artifacts.gcs.enabled without artifacts.gcs.[].jsonPath. Using default application credentials."); credential = GoogleCredential.getApplicationDefault(); } name = account.getName(); storage = new Storage.Builder(transport, jsonFactory, credential) .setApplicationName(applicationName) .build(); }
@Test public void testMatchingAgainstClient() throws Exception { GcsOptions options = PipelineOptionsFactory.as(GcsOptions.class); options.setGcpCredential(new TestCredential()); options.setGoogleApiTrace( new GoogleApiTracer() .addTraceFor(Transport.newStorageClient(options).build(), "TraceDestination")); Storage.Objects.Get getRequest = Transport.newStorageClient(options).build().objects().get("testBucketId", "testObjectId"); assertEquals("TraceDestination", getRequest.get("$trace")); Delete deleteRequest = GcpOptions.GcpTempLocationFactory.newCloudResourceManagerClient( options.as(CloudResourceManagerOptions.class)) .build() .projects() .delete("testProjectId"); assertNull(deleteRequest.get("$trace")); }