dinukadesilva commented on a change in pull request #11:
URL: https://github.com/apache/airavata-mft/pull/11#discussion_r418400874
##########
File path: services/secret-service/server/pom.xml
##########
@@ -47,7 +47,7 @@
<dependency>
<groupId>org.apache.airavata</groupId>
<artifactId>airavata-credential-store-stubs</artifactId>
- <version>0.19-SNAPSHOT</version>
+ <version>0.17</version>
Review comment:
Why?
##########
File path:
transport/gdrive-transport/src/main/java/org/apache/airavata/mft/transport/gdrive/GDriveReceiver.java
##########
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.airavata.mft.transport.gdrive;
+
+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.json.JsonFactory;
+import com.google.api.client.json.jackson2.JacksonFactory;
+import com.google.api.services.drive.Drive;
+import com.google.api.services.drive.DriveScopes;
+import com.google.api.services.drive.model.File;
+import com.google.api.services.drive.model.FileList;
+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.GDriveResource;
+import org.apache.airavata.mft.resource.service.GDriveResourceGetRequest;
+import org.apache.airavata.mft.resource.service.ResourceServiceGrpc;
+import org.apache.airavata.mft.secret.client.SecretServiceClient;
+import org.apache.airavata.mft.secret.service.GDriveSecret;
+import org.apache.airavata.mft.secret.service.GDriveSecretGetRequest;
+import org.apache.airavata.mft.secret.service.SecretServiceGrpc;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.Collection;
+
+public class GDriveReceiver implements Connector {
+
+ private static final Logger logger =
LoggerFactory.getLogger(GDriveReceiver.class);
+
+ private GDriveResource gdriveResource;
+ private Drive drive;
+
+ @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.gdriveResource =
resourceClient.getGDriveResource(GDriveResourceGetRequest.newBuilder().setResourceId(resourceId).build());
+
+ SecretServiceGrpc.SecretServiceBlockingStub secretClient =
SecretServiceClient.buildClient(secretServiceHost, secretServicePort);
+ GDriveSecret gdriveSecret =
secretClient.getGDriveSecret(GDriveSecretGetRequest.newBuilder().setSecretId(credentialToken).build());
+
+ HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport();
+ JsonFactory jsonFactory = new JacksonFactory();
+ String jsonString = gdriveSecret.getCredentialsJson();
+ GoogleCredential credential = GoogleCredential.fromStream(new
ByteArrayInputStream(jsonString.getBytes(StandardCharsets.UTF_8)), transport,
jsonFactory);
+ if (credential.createScopedRequired()) {
+ Collection<String> scopes = DriveScopes.all();
+ credential = credential.createScoped(scopes);
+ }
+ drive = new Drive.Builder(transport, jsonFactory, credential).build();
+ }
+
+ @Override
+ public void destroy() {
+ }
+
+ @Override
+ public void startStream(ConnectorContext context) throws Exception {
+ logger.info("Starting GDrive Receiver stream for transfer {}",
context.getTransferId());
+
+ String id = null;
+ FileList fileList = drive.files().list()
+ .setQ("name = '"+gdriveResource.getResourcePath()+"'")
+ .setFields("files(id,name,modifiedTime,md5Checksum,size)")
+ .execute();
+
+ for (File f : fileList.getFiles()) {
+ id = f.getId();
+ }
+
+ if (id == null) {
+ throw new IllegalStateException("GDrive Receiver was unable to
retrieve the resource");
+ }
+
+ InputStream inputStream =
drive.files().get(id).executeMediaAsInputStream();
+ OutputStream outputStream =
context.getStreamBuffer().getOutputStream();
+ int read;
+ long bytes = 0;
+ long fileSize = context.getMetadata().getResourceSize();
+ byte[] buf = new byte[1024];
+ while (true) {
+ int bufSize = 0;
Review comment:
No need of zero here.
##########
File path:
services/resource-service/server/src/main/resources/distribution/conf/resources.json
##########
@@ -59,5 +59,10 @@
"type": "DROPBOX",
"resourceId": "",
"resourcePath": ""
+ },
+ {
+ "type": "GDRIVE",
+ "resourceId": "gdrive-file",
+ "resourcePath": "nsagdrive.txt"
Review comment:
Google drive allows same directory/file name in the same path. Is there
need of the path here?
##########
File path:
services/secret-service/server/src/main/resources/distribution/conf/secrets.json
##########
@@ -31,5 +31,10 @@
"type": "DROPBOX",
"secretId": "dropbox-cred",
"accessToken": ""
+ },
+ {
+ "type": "GDRIVE",
+ "secretId": "gdrive-cred",
+ "credentialsJson": ""
Review comment:
1) From where is this JSON is retrieved. And what's included in it.
----------------------------------------------------------------
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]