sharanya17410 commented on a change in pull request #6:
URL: https://github.com/apache/airavata-mft/pull/6#discussion_r413269205



##########
File path: 
transport/gcp-transport/src/main/java/org/apache/airavata/mft/transport/gcp/GCSSender.java
##########
@@ -0,0 +1,86 @@
+package org.apache.airavata.mft.transport.gcp;
+
+import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
+import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
+import com.google.api.client.http.HttpTransport;
+import com.google.api.client.http.InputStreamContent;
+import com.google.api.client.json.JsonFactory;
+import com.google.api.client.json.jackson2.JacksonFactory;
+import com.google.api.services.storage.Storage;
+import com.google.api.services.storage.Storage.Objects.Insert;
+import com.google.api.services.storage.StorageScopes;
+import com.google.api.services.storage.model.ObjectAccessControl;
+import com.google.api.services.storage.model.StorageObject;
+import org.apache.airavata.mft.core.ConnectorContext;
+import org.apache.airavata.mft.core.api.Connector;
+import org.apache.airavata.mft.resource.client.ResourceServiceClient;
+import org.apache.airavata.mft.resource.service.GCSResource;
+import org.apache.airavata.mft.resource.service.GCSResourceGetRequest;
+import org.apache.airavata.mft.resource.service.ResourceServiceGrpc;
+import org.apache.airavata.mft.secret.client.SecretServiceClient;
+import org.apache.airavata.mft.secret.service.GCSSecret;
+import org.apache.airavata.mft.secret.service.GCSSecretGetRequest;
+import org.apache.airavata.mft.secret.service.SecretServiceGrpc;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.ByteArrayInputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.Collection;
+
+
+public class GCSSender implements Connector {
+
+    private static final Logger logger = 
LoggerFactory.getLogger(GCSSender.class);
+
+    private GCSResource gcsResource;
+    private Storage storage;
+
+    @Override
+    public void init(String resourceId, String credentialToken, String 
resourceServiceHost, int resourceServicePort, String secretServiceHost, int 
secretServicePort) throws Exception {
+
+        ResourceServiceGrpc.ResourceServiceBlockingStub resourceClient = 
ResourceServiceClient.buildClient(resourceServiceHost, resourceServicePort);
+        this.gcsResource = 
resourceClient.getGCSResource(GCSResourceGetRequest.newBuilder().setResourceId(resourceId).build());
+
+        SecretServiceGrpc.SecretServiceBlockingStub secretClient = 
SecretServiceClient.buildClient(secretServiceHost, secretServicePort);
+        GCSSecret gcsSecret = 
secretClient.getGCSSecret(GCSSecretGetRequest.newBuilder().setSecretId(credentialToken).build());
+
+        HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport();
+        JsonFactory jsonFactory = new JacksonFactory();
+        String jsonString = gcsSecret.getJsonCredentialsFilePath();
+        GoogleCredential credential = GoogleCredential.fromStream(new 
ByteArrayInputStream(jsonString.getBytes(StandardCharsets.UTF_8)));
+        if (credential.createScopedRequired()) {
+            Collection<String> scopes = StorageScopes.all();
+            credential = credential.createScoped(scopes);
+        }
+
+        storage = new Storage.Builder(transport, jsonFactory, 
credential).build();
+    }
+
+    @Override
+    public void destroy() {
+
+    }
+
+    @Override
+    public void startStream(ConnectorContext context) throws Exception {
+        logger.info("Starting GCS Sender stream for transfer {}", 
context.getTransferId());
+        logger.info("Content length for transfer {} {}", 
context.getTransferId(), context.getMetadata().getResourceSize());
+
+        InputStreamContent contentStream = new InputStreamContent(
+                "text/plain", context.getStreamBuffer().getInputStream());

Review comment:
       Could we pass the type as "null"?
   GCS implementation is the only type of transport which requires content type 
of its stream. The only way to fetch this information involves changing the 
resource meta data class which would eventually affect all the other transport 
implementations. Can we pass null instead for GCP alone ? This would show up 
the transferred file content type as empty. 
   
![image](https://user-images.githubusercontent.com/46901933/80026082-8db7d600-84af-11ea-9046-8f95122abf29.png)
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to