You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by di...@apache.org on 2022/12/08 14:37:49 UTC

[airavata-mft] branch master updated (60ed0a4 -> 07212a2)

This is an automated email from the ASF dual-hosted git repository.

dimuthuupe pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/airavata-mft.git


    from 60ed0a4  Removing dependency between agent and secret/resource services
     new 4a4b981  Adding GCS service command-line support
     new 07212a2  Change GCS Secret attributes by removing credentials json

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../airavata/mft/command/line/MainRunner.java      |   3 +-
 .../mft/command/line/sub/gcs/GCSAddSubCommand.java |  94 ++++++++++++++++++
 .../command/line/sub/gcs/GCSRemoteSubCommand.java  | 106 +++++++++++++++++++++
 .../mft/command/line/sub/gcs/GCSSubCommand.java    |   9 +-
 .../server/backend/sql/SQLResourceBackend.java     |  28 ++++--
 ...ataStorageEntity.java => GCSStorageEntity.java} |  37 ++++---
 ...geRepository.java => GCSStorageRepository.java} |  10 +-
 .../resource/server/handler/GCSServiceHandler.java |  18 ++++
 .../server/backend/sql/SQLSecretBackend.java       |  14 ++-
 .../{SCPSecretEntity.java => GCSSecretEntity.java} |  65 +++++++------
 ...retRepository.java => GCSSecretRepository.java} |  11 ++-
 .../src/main/resources/secrets.json.template       |   4 +-
 .../stub/src/main/proto/gcs/GCSCredential.proto    |   6 +-
 13 files changed, 332 insertions(+), 73 deletions(-)
 create mode 100644 command-line/src/main/java/org/apache/airavata/mft/command/line/sub/gcs/GCSAddSubCommand.java
 create mode 100644 command-line/src/main/java/org/apache/airavata/mft/command/line/sub/gcs/GCSRemoteSubCommand.java
 copy core/src/main/java/org/apache/airavata/mft/core/ResourceTypes.java => command-line/src/main/java/org/apache/airavata/mft/command/line/sub/gcs/GCSSubCommand.java (75%)
 copy services/resource-service/server/src/main/java/org/apache/airavata/mft/resource/server/backend/sql/entity/{ODataStorageEntity.java => GCSStorageEntity.java} (72%)
 copy services/resource-service/server/src/main/java/org/apache/airavata/mft/resource/server/backend/sql/repository/{ResolveStorageRepository.java => GCSStorageRepository.java} (80%)
 copy services/secret-service/server/src/main/java/org/apache/airavata/mft/secret/server/backend/sql/entity/{SCPSecretEntity.java => GCSSecretEntity.java} (62%)
 copy services/secret-service/server/src/main/java/org/apache/airavata/mft/secret/server/backend/sql/repository/{FTPSecretRepository.java => GCSSecretRepository.java} (85%)


[airavata-mft] 01/02: Adding GCS service command-line support

Posted by di...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dimuthuupe pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata-mft.git

commit 4a4b9815515d33696c8495dce988158a2946ab82
Author: jayancv <Ja...@gmail>
AuthorDate: Sun Dec 4 00:14:09 2022 +0530

    Adding GCS service command-line support
---
 .../airavata/mft/command/line/MainRunner.java      |   3 +-
 .../mft/command/line/sub/gcs/GCSAddSubCommand.java |  85 +++++++++++++++++
 .../command/line/sub/gcs/GCSRemoteSubCommand.java  | 106 +++++++++++++++++++++
 .../mft/command/line/sub/gcs/GCSSubCommand.java    |  24 +++++
 .../server/backend/sql/SQLResourceBackend.java     |  28 ++++--
 .../backend/sql/entity/GCSStorageEntity.java       |  72 ++++++++++++++
 .../sql/repository/GCSStorageRepository.java       |  29 ++++++
 .../resource/server/handler/GCSServiceHandler.java |  18 ++++
 .../server/backend/sql/SQLSecretBackend.java       |  14 ++-
 .../server/backend/sql/entity/GCSSecretEntity.java |  59 ++++++++++++
 .../sql/repository/GCSSecretRepository.java        |  28 ++++++
 11 files changed, 456 insertions(+), 10 deletions(-)

diff --git a/command-line/src/main/java/org/apache/airavata/mft/command/line/MainRunner.java b/command-line/src/main/java/org/apache/airavata/mft/command/line/MainRunner.java
index b1002e9..0a6764b 100644
--- a/command-line/src/main/java/org/apache/airavata/mft/command/line/MainRunner.java
+++ b/command-line/src/main/java/org/apache/airavata/mft/command/line/MainRunner.java
@@ -1,5 +1,6 @@
 package org.apache.airavata.mft.command.line;
 
+import org.apache.airavata.mft.command.line.sub.gcs.GCSSubCommand;
 import org.apache.airavata.mft.command.line.sub.odata.ODataSubCommand;
 import org.apache.airavata.mft.command.line.sub.s3.S3SubCommand;
 import org.apache.airavata.mft.command.line.sub.swift.SwiftSubCommand;
@@ -9,7 +10,7 @@ import picocli.CommandLine.Command;
 
 @Command(name = "checksum", mixinStandardHelpOptions = true, version = "checksum 4.0",
         description = "Prints the checksum (SHA-256 by default) of a file to STDOUT.",
-        subcommands = {S3SubCommand.class, TransferSubCommand.class, SwiftSubCommand.class, ODataSubCommand.class})
+        subcommands = {S3SubCommand.class, TransferSubCommand.class, SwiftSubCommand.class, ODataSubCommand.class, GCSSubCommand.class})
 class MainRunner {
 
     public static void main(String... args) {
diff --git a/command-line/src/main/java/org/apache/airavata/mft/command/line/sub/gcs/GCSAddSubCommand.java b/command-line/src/main/java/org/apache/airavata/mft/command/line/sub/gcs/GCSAddSubCommand.java
new file mode 100644
index 0000000..c45fcc7
--- /dev/null
+++ b/command-line/src/main/java/org/apache/airavata/mft/command/line/sub/gcs/GCSAddSubCommand.java
@@ -0,0 +1,85 @@
+/*
+ * 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.command.line.sub.gcs;
+
+import org.apache.airavata.mft.api.client.MFTApiClient;
+import org.apache.airavata.mft.common.AuthToken;
+import org.apache.airavata.mft.credential.stubs.gcs.GCSSecret;
+import org.apache.airavata.mft.credential.stubs.gcs.GCSSecretCreateRequest;
+import org.apache.airavata.mft.resource.service.gcs.GCSStorageServiceGrpc;
+import org.apache.airavata.mft.resource.stubs.gcs.storage.GCSStorage;
+import org.apache.airavata.mft.resource.stubs.gcs.storage.GCSStorageCreateRequest;
+import org.apache.airavata.mft.storage.stubs.storagesecret.StorageSecret;
+import org.apache.airavata.mft.storage.stubs.storagesecret.StorageSecretCreateRequest;
+import org.apache.airavata.mft.storage.stubs.storagesecret.StorageSecretServiceGrpc;
+import picocli.CommandLine;
+
+import java.util.concurrent.Callable;
+
+@CommandLine.Command( name = "add" )
+public class GCSAddSubCommand implements Callable<Integer>
+{
+
+    @CommandLine.Option( names = {"-n", "--name"}, description = "Storage Name" )
+    private String name;
+
+    @CommandLine.Option( names = {"-b", "--bucket"}, description = "Bucket Name" )
+    private String bucket;
+
+    @CommandLine.Option( names = {"-s", "--storageId"}, description = "Storage ID" )
+    private String storageId;
+
+    @CommandLine.Option( names = {"-c", "--credentials"}, description = "Credentials" )
+    private String credentials;
+
+
+    @Override
+    public Integer call() throws Exception
+    {
+        AuthToken authToken = AuthToken.newBuilder().build();
+
+        MFTApiClient mftApiClient = MFTApiClient.MFTApiClientBuilder.newBuilder().build();
+
+        GCSSecret gcsSecret = mftApiClient.getSecretServiceClient().gcs().
+                createGCSSecret( GCSSecretCreateRequest.newBuilder().
+                        setCredentialsJson( credentials ).
+                        setAuthzToken( authToken ).build() );
+
+        System.out.println( "Created the gcs secret " + gcsSecret.getSecretId() );
+
+        GCSStorageServiceGrpc.GCSStorageServiceBlockingStub gcsStorageClient =
+                mftApiClient.getStorageServiceClient().gcs();
+
+        GCSStorage gcsStorage = gcsStorageClient.createGCSStorage( GCSStorageCreateRequest.newBuilder()
+                .setStorageId( storageId )
+                .setBucketName( bucket )
+                .setName( name ).build() );
+        System.out.println( "Created gcs storage " + gcsStorage.getStorageId() );
+
+        StorageSecretServiceGrpc.StorageSecretServiceBlockingStub storageSecretClient =
+                mftApiClient.getStorageServiceClient().storageSecret();
+        StorageSecret storageSecret = storageSecretClient.createStorageSecret( StorageSecretCreateRequest.newBuilder()
+                .setStorageId( gcsStorage.getStorageId() )
+                .setSecretId( gcsSecret.getSecretId() )
+                .setType( StorageSecret.StorageType.GCS ).build() );
+
+        System.out.println( "Storage Id " + gcsStorage.getStorageId() );
+
+        return 0;
+    }
+}
diff --git a/command-line/src/main/java/org/apache/airavata/mft/command/line/sub/gcs/GCSRemoteSubCommand.java b/command-line/src/main/java/org/apache/airavata/mft/command/line/sub/gcs/GCSRemoteSubCommand.java
new file mode 100644
index 0000000..08a7801
--- /dev/null
+++ b/command-line/src/main/java/org/apache/airavata/mft/command/line/sub/gcs/GCSRemoteSubCommand.java
@@ -0,0 +1,106 @@
+/*
+ * 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.command.line.sub.gcs;
+
+import org.apache.airavata.mft.api.client.MFTApiClient;
+import org.apache.airavata.mft.command.line.CommandLineUtil;
+import org.apache.airavata.mft.resource.stubs.gcs.storage.GCSStorage;
+import org.apache.airavata.mft.resource.stubs.gcs.storage.GCSStorageDeleteRequest;
+import org.apache.airavata.mft.resource.stubs.gcs.storage.GCSStorageDeleteResponse;
+import org.apache.airavata.mft.resource.stubs.gcs.storage.GCSStorageGetRequest;
+import org.apache.airavata.mft.resource.stubs.gcs.storage.GCSStorageListRequest;
+import org.apache.airavata.mft.resource.stubs.gcs.storage.GCSStorageListResponse;
+import picocli.CommandLine;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@CommandLine.Command( name = "remote", subcommands = {GCSAddSubCommand.class} )
+public class GCSRemoteSubCommand
+{
+
+    @CommandLine.Command( name = "get" )
+    void getGSCResource( @CommandLine.Parameters( index = "0" ) String resourceId )
+    {
+        System.out.println( "Getting GCS Resource " + resourceId );
+        MFTApiClient mftApiClient = MFTApiClient.MFTApiClientBuilder.newBuilder().build();
+
+        GCSStorage gcsStorage = mftApiClient.getStorageServiceClient().gcs()
+                .getGCSStorage( GCSStorageGetRequest.newBuilder().setStorageId( resourceId ).build() );
+
+        List<GCSStorage> storagesList = new ArrayList<>();
+        storagesList.add( gcsStorage );
+
+        int[] columnWidth = {40, 15, 15};
+        String[][] content = new String[storagesList.size() + 1][3];
+        String[] headers = {"STORAGE ID", "NAME", "BUCKET"};
+        content[0] = headers;
+
+        for ( int i = 1; i <= storagesList.size(); i++ )
+        {
+            GCSStorage gcs= storagesList.get( i - 1 );
+            content[i][0] = gcs.getStorageId();
+            content[i][1] = gcs.getName();
+            content[i][2] = gcs.getBucketName();
+        }
+        CommandLineUtil.printTable( columnWidth, content );
+    }
+
+    @CommandLine.Command( name = "delete" )
+    void deleteGCSResource( @CommandLine.Parameters( index = "0" ) String resourceId )
+    {
+        System.out.println( "Deleting GCS Resource " + resourceId );
+        MFTApiClient mftApiClient = MFTApiClient.MFTApiClientBuilder.newBuilder().build();
+
+        GCSStorageDeleteResponse gcsStorageDeleteResponse = mftApiClient.getStorageServiceClient().gcs()
+                .deleteGCSStorage( GCSStorageDeleteRequest.newBuilder().setStorageId( resourceId ).build() );
+        System.out.println( "Delete GCS Resource status : " + gcsStorageDeleteResponse.getStatus() );
+
+    }
+
+    @CommandLine.Command( name = "list" )
+    void listS3Resource()
+    {
+        System.out.println( "Listing GSC Resource" );
+        MFTApiClient mftApiClient = MFTApiClient.MFTApiClientBuilder.newBuilder().build();
+
+        GCSStorageListResponse gcsStorageListResponse = mftApiClient.getStorageServiceClient().gcs()
+                .listGCSStorage( GCSStorageListRequest.newBuilder().setOffset( 0 ).setLimit( 10 ).build() );
+
+        List<GCSStorage> storagesList = gcsStorageListResponse.getStoragesList();
+
+        int[] columnWidth = {40, 15, 15};
+        String[][] content = new String[storagesList.size() + 1][3];
+        String[] headers = {"STORAGE ID", "NAME", "BUCKET"};
+        content[0] = headers;
+
+
+        for ( int i = 1; i <= storagesList.size(); i++ )
+        {
+            GCSStorage gcsStorage = storagesList.get( i - 1 );
+            content[i][0] = gcsStorage.getStorageId();
+            content[i][1] = gcsStorage.getName();
+            content[i][2] = gcsStorage.getBucketName();
+
+        }
+
+        CommandLineUtil.printTable( columnWidth, content );
+    }
+
+
+}
diff --git a/command-line/src/main/java/org/apache/airavata/mft/command/line/sub/gcs/GCSSubCommand.java b/command-line/src/main/java/org/apache/airavata/mft/command/line/sub/gcs/GCSSubCommand.java
new file mode 100644
index 0000000..bdacccb
--- /dev/null
+++ b/command-line/src/main/java/org/apache/airavata/mft/command/line/sub/gcs/GCSSubCommand.java
@@ -0,0 +1,24 @@
+/*
+ * 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.command.line.sub.gcs;
+
+import picocli.CommandLine;
+
+@CommandLine.Command( name = "gcs", description = "Manage GCS resources and credentials",
+                      subcommands = {GCSRemoteSubCommand.class} )
+public class GCSSubCommand {
+}
diff --git a/services/resource-service/server/src/main/java/org/apache/airavata/mft/resource/server/backend/sql/SQLResourceBackend.java b/services/resource-service/server/src/main/java/org/apache/airavata/mft/resource/server/backend/sql/SQLResourceBackend.java
index 29de806..a47a993 100644
--- a/services/resource-service/server/src/main/java/org/apache/airavata/mft/resource/server/backend/sql/SQLResourceBackend.java
+++ b/services/resource-service/server/src/main/java/org/apache/airavata/mft/resource/server/backend/sql/SQLResourceBackend.java
@@ -57,6 +57,9 @@ public class SQLResourceBackend implements ResourceBackend {
     @Autowired
     private S3StorageRepository s3StorageRepository;
 
+    @Autowired
+    private GCSStorageRepository gcsStorageRepository;
+
     @Autowired
     private SwiftStorageRepository swiftStorageRepository;
 
@@ -413,27 +416,40 @@ public class SQLResourceBackend implements ResourceBackend {
 
     @Override
     public GCSStorageListResponse listGCSStorage(GCSStorageListRequest request) throws Exception {
-        throw new UnsupportedOperationException("Operation is not supported in backend");
+        GCSStorageListResponse.Builder respBuilder = GCSStorageListResponse.newBuilder();
+        List<GCSStorageEntity> all = gcsStorageRepository.findAll(PageRequest.of(request.getOffset(), request.getLimit()));
+        all.forEach(ety -> respBuilder.addStorages(mapper.map(ety, GCSStorage.newBuilder().getClass())));
+        return respBuilder.build();
     }
 
     @Override
     public Optional<GCSStorage> getGCSStorage(GCSStorageGetRequest request) throws Exception {
-        throw new UnsupportedOperationException("Operation is not supported in backend");
-    }
+        Optional<GCSStorageEntity> entity = gcsStorageRepository.findById(request.getStorageId());
+        return entity.map(e -> mapper.map(e, GCSStorage.newBuilder().getClass()).build());    }
 
     @Override
     public GCSStorage createGCSStorage(GCSStorageCreateRequest request) throws Exception {
-        throw new UnsupportedOperationException("Operation is not supported in backend");
+        GCSStorageEntity savedEntity = gcsStorageRepository.save(mapper.map(request, GCSStorageEntity.class));
+
+        ResolveStorageEntity storageTypeEty = new ResolveStorageEntity();
+        storageTypeEty.setStorageId(savedEntity.getStorageId());
+        storageTypeEty.setStorageType(ResolveStorageEntity.StorageType.GCS);
+        resolveStorageRepository.save(storageTypeEty);
+
+        return mapper.map(savedEntity, GCSStorage.newBuilder().getClass()).build();
     }
 
     @Override
     public boolean updateGCSStorage(GCSStorageUpdateRequest request) throws Exception {
-        throw new UnsupportedOperationException("Operation is not supported in backend");
+        gcsStorageRepository.save(mapper.map(request, GCSStorageEntity.class));
+        return true;
     }
 
     @Override
     public boolean deleteGCSStorage(GCSStorageDeleteRequest request) throws Exception {
-        throw new UnsupportedOperationException("Operation is not supported in backend");
+        gcsStorageRepository.deleteById(request.getStorageId());
+        resourceRepository.deleteByStorageIdAndStorageType(request.getStorageId(), GenericResourceEntity.StorageType.GCS);
+        return true;
     }
 
     @Override
diff --git a/services/resource-service/server/src/main/java/org/apache/airavata/mft/resource/server/backend/sql/entity/GCSStorageEntity.java b/services/resource-service/server/src/main/java/org/apache/airavata/mft/resource/server/backend/sql/entity/GCSStorageEntity.java
new file mode 100644
index 0000000..413d32b
--- /dev/null
+++ b/services/resource-service/server/src/main/java/org/apache/airavata/mft/resource/server/backend/sql/entity/GCSStorageEntity.java
@@ -0,0 +1,72 @@
+/*
+ * 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.resource.server.backend.sql.entity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+import org.hibernate.annotations.GenericGenerator;
+
+@Entity
+public class GCSStorageEntity
+{
+
+    @Id
+    @Column(name = "GCS_STORAGE_ID")
+    @GeneratedValue(generator = "uuid")
+    @GenericGenerator( name = "uuid", strategy = "uuid2")
+    private String storageId;
+
+    @Column(name = "BUCKET_NAME")
+    private String bucketName;
+
+    @Column(name = "STORAGE_NAME")
+    private String name;
+
+    public String getStorageId()
+    {
+        return storageId;
+    }
+
+    public void setStorageId( String storageId )
+    {
+        this.storageId = storageId;
+    }
+
+    public String getBucketName()
+    {
+        return bucketName;
+    }
+
+    public void setBucketName( String bucketName )
+    {
+        this.bucketName = bucketName;
+    }
+
+    public String getName()
+    {
+        return name;
+    }
+
+    public void setName( String name )
+    {
+        this.name = name;
+    }
+}
diff --git a/services/resource-service/server/src/main/java/org/apache/airavata/mft/resource/server/backend/sql/repository/GCSStorageRepository.java b/services/resource-service/server/src/main/java/org/apache/airavata/mft/resource/server/backend/sql/repository/GCSStorageRepository.java
new file mode 100644
index 0000000..6def035
--- /dev/null
+++ b/services/resource-service/server/src/main/java/org/apache/airavata/mft/resource/server/backend/sql/repository/GCSStorageRepository.java
@@ -0,0 +1,29 @@
+/*
+ * 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.resource.server.backend.sql.repository;
+
+import java.util.List;
+
+import org.apache.airavata.mft.resource.server.backend.sql.entity.GCSStorageEntity;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.repository.CrudRepository;
+
+public interface GCSStorageRepository extends CrudRepository<GCSStorageEntity, String>
+{
+    List<GCSStorageEntity> findAll( Pageable pageable);
+}
diff --git a/services/resource-service/server/src/main/java/org/apache/airavata/mft/resource/server/handler/GCSServiceHandler.java b/services/resource-service/server/src/main/java/org/apache/airavata/mft/resource/server/handler/GCSServiceHandler.java
index 1f33f46..5722043 100644
--- a/services/resource-service/server/src/main/java/org/apache/airavata/mft/resource/server/handler/GCSServiceHandler.java
+++ b/services/resource-service/server/src/main/java/org/apache/airavata/mft/resource/server/handler/GCSServiceHandler.java
@@ -103,4 +103,22 @@ public class GCSServiceHandler extends GCSStorageServiceGrpc.GCSStorageServiceIm
                     .asRuntimeException());
         }
     }
+
+    @Override
+    public void listGCSStorage( GCSStorageListRequest request, StreamObserver<GCSStorageListResponse> responseObserver )
+    {
+        try
+        {
+            GCSStorageListResponse response = this.backend.listGCSStorage( request );
+            responseObserver.onNext( response );
+            responseObserver.onCompleted();
+        }
+        catch ( Exception e )
+        {
+            logger.error( "Failed in retrieving GCS storage list", e );
+            responseObserver.onError( Status.INTERNAL.withCause( e ).
+                    withDescription( "Failed in retrieving GCS storage list" ).asRuntimeException() );
+        }
+    }
+
 }
diff --git a/services/secret-service/server/src/main/java/org/apache/airavata/mft/secret/server/backend/sql/SQLSecretBackend.java b/services/secret-service/server/src/main/java/org/apache/airavata/mft/secret/server/backend/sql/SQLSecretBackend.java
index fff66d8..2a6cd22 100644
--- a/services/secret-service/server/src/main/java/org/apache/airavata/mft/secret/server/backend/sql/SQLSecretBackend.java
+++ b/services/secret-service/server/src/main/java/org/apache/airavata/mft/secret/server/backend/sql/SQLSecretBackend.java
@@ -28,6 +28,7 @@ import org.apache.airavata.mft.credential.stubs.scp.*;
 import org.apache.airavata.mft.credential.stubs.swift.*;
 import org.apache.airavata.mft.secret.server.backend.SecretBackend;
 import org.apache.airavata.mft.secret.server.backend.sql.entity.FTPSecretEntity;
+import org.apache.airavata.mft.secret.server.backend.sql.entity.GCSSecretEntity;
 import org.apache.airavata.mft.secret.server.backend.sql.entity.ODataSecretEntity;
 import org.apache.airavata.mft.secret.server.backend.sql.entity.S3SecretEntity;
 import org.apache.airavata.mft.secret.server.backend.sql.entity.SCPSecretEntity;
@@ -35,6 +36,7 @@ import org.apache.airavata.mft.secret.server.backend.sql.entity.swift.SwiftAuthC
 import org.apache.airavata.mft.secret.server.backend.sql.entity.swift.SwiftPasswordSecretEntity;
 import org.apache.airavata.mft.secret.server.backend.sql.entity.swift.SwiftSecretEntity;
 import org.apache.airavata.mft.secret.server.backend.sql.repository.FTPSecretRepository;
+import org.apache.airavata.mft.secret.server.backend.sql.repository.GCSSecretRepository;
 import org.apache.airavata.mft.secret.server.backend.sql.repository.ODataSecretRepository;
 import org.apache.airavata.mft.secret.server.backend.sql.repository.S3SecretRepository;
 import org.apache.airavata.mft.secret.server.backend.sql.repository.SCPSecretRepository;
@@ -73,6 +75,9 @@ public class SQLSecretBackend implements SecretBackend {
     @Autowired
     private ODataSecretRepository odataSecretRepository;
 
+    @Autowired
+    private GCSSecretRepository gcsSecretRepository;
+
     private DozerBeanMapper mapper = new DozerBeanMapper();
 
     @Override
@@ -174,13 +179,16 @@ public class SQLSecretBackend implements SecretBackend {
     }
 
     @Override
-    public Optional<GCSSecret> getGCSSecret(GCSSecretGetRequest request) throws Exception {
-        throw new UnsupportedOperationException("Operation is not supported in backend");
+    public Optional<GCSSecret> getGCSSecret( GCSSecretGetRequest request ) throws Exception
+    {
+        Optional<GCSSecretEntity> secretEty = gcsSecretRepository.findBySecretId( request.getSecretId() );
+        return secretEty.map( gcsSecretEntity -> mapper.map( gcsSecretEntity, GCSSecret.newBuilder().getClass() ).build() );
     }
 
     @Override
     public GCSSecret createGCSSecret(GCSSecretCreateRequest request) throws Exception {
-        throw new UnsupportedOperationException("Operation is not supported in backend");
+        GCSSecretEntity savedEntity = gcsSecretRepository.save(mapper.map(request, GCSSecretEntity.class));
+        return mapper.map(savedEntity, GCSSecret.newBuilder().getClass()).build();
     }
 
     @Override
diff --git a/services/secret-service/server/src/main/java/org/apache/airavata/mft/secret/server/backend/sql/entity/GCSSecretEntity.java b/services/secret-service/server/src/main/java/org/apache/airavata/mft/secret/server/backend/sql/entity/GCSSecretEntity.java
new file mode 100644
index 0000000..24805af
--- /dev/null
+++ b/services/secret-service/server/src/main/java/org/apache/airavata/mft/secret/server/backend/sql/entity/GCSSecretEntity.java
@@ -0,0 +1,59 @@
+/*
+ * 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.secret.server.backend.sql.entity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+import org.hibernate.annotations.GenericGenerator;
+
+@Entity
+public class GCSSecretEntity
+{
+
+    @Id
+    @Column(name = "SECRET_ID")
+    @GeneratedValue(generator = "uuid")
+    @GenericGenerator( name = "uuid", strategy = "uuid2")
+    private String secretId;
+
+    @Column(name = "CREDENTIALS_JSON")
+    private String credentialsJson;
+
+    public String getSecretId()
+    {
+        return secretId;
+    }
+
+    public void setSecretId( String secretId )
+    {
+        this.secretId = secretId;
+    }
+
+    public String getCredentialsJson()
+    {
+        return credentialsJson;
+    }
+
+    public void setCredentialsJson( String credentialsJson )
+    {
+        this.credentialsJson = credentialsJson;
+    }
+}
diff --git a/services/secret-service/server/src/main/java/org/apache/airavata/mft/secret/server/backend/sql/repository/GCSSecretRepository.java b/services/secret-service/server/src/main/java/org/apache/airavata/mft/secret/server/backend/sql/repository/GCSSecretRepository.java
new file mode 100644
index 0000000..446d3e3
--- /dev/null
+++ b/services/secret-service/server/src/main/java/org/apache/airavata/mft/secret/server/backend/sql/repository/GCSSecretRepository.java
@@ -0,0 +1,28 @@
+/*
+ * 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.secret.server.backend.sql.repository;
+
+import java.util.Optional;
+
+import org.apache.airavata.mft.secret.server.backend.sql.entity.GCSSecretEntity;
+import org.springframework.data.repository.CrudRepository;
+
+public interface GCSSecretRepository extends CrudRepository<GCSSecretEntity, String>
+{
+    Optional<GCSSecretEntity> findBySecretId( String resourceId);
+}


[airavata-mft] 02/02: Change GCS Secret attributes by removing credentials json

Posted by di...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dimuthuupe pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata-mft.git

commit 07212a2d884881b85be14aa9c6ec3590b4f9d262
Author: jayancv <Ja...@gmail>
AuthorDate: Wed Dec 7 20:48:57 2022 +0530

    Change GCS Secret attributes by removing credentials json
---
 .../mft/command/line/sub/gcs/GCSAddSubCommand.java | 15 +++++++--
 .../server/backend/sql/entity/GCSSecretEntity.java | 39 ++++++++++++++++++----
 .../src/main/resources/secrets.json.template       |  4 ++-
 .../stub/src/main/proto/gcs/GCSCredential.proto    |  6 ++--
 4 files changed, 52 insertions(+), 12 deletions(-)

diff --git a/command-line/src/main/java/org/apache/airavata/mft/command/line/sub/gcs/GCSAddSubCommand.java b/command-line/src/main/java/org/apache/airavata/mft/command/line/sub/gcs/GCSAddSubCommand.java
index c45fcc7..de7f4ba 100644
--- a/command-line/src/main/java/org/apache/airavata/mft/command/line/sub/gcs/GCSAddSubCommand.java
+++ b/command-line/src/main/java/org/apache/airavata/mft/command/line/sub/gcs/GCSAddSubCommand.java
@@ -44,8 +44,15 @@ public class GCSAddSubCommand implements Callable<Integer>
     @CommandLine.Option( names = {"-s", "--storageId"}, description = "Storage ID" )
     private String storageId;
 
-    @CommandLine.Option( names = {"-c", "--credentials"}, description = "Credentials" )
-    private String credentials;
+    @CommandLine.Option( names = {"-pid", "--projectId"}, description = "Project Id", required = true )
+    private String projectId;
+
+    @CommandLine.Option( names = {"-p", "--privateKey"}, description = "Private Key", required = true )
+    private String privateKey;
+
+    @CommandLine.Option( names = {"-c", "--clientEmail"}, description = "Client Email", required = true )
+    private String clientEmail;
+
 
 
     @Override
@@ -57,7 +64,9 @@ public class GCSAddSubCommand implements Callable<Integer>
 
         GCSSecret gcsSecret = mftApiClient.getSecretServiceClient().gcs().
                 createGCSSecret( GCSSecretCreateRequest.newBuilder().
-                        setCredentialsJson( credentials ).
+                        setProjectId( projectId ).
+                        setPrivateKey( privateKey ).
+                        setClientEmail( clientEmail ).
                         setAuthzToken( authToken ).build() );
 
         System.out.println( "Created the gcs secret " + gcsSecret.getSecretId() );
diff --git a/services/secret-service/server/src/main/java/org/apache/airavata/mft/secret/server/backend/sql/entity/GCSSecretEntity.java b/services/secret-service/server/src/main/java/org/apache/airavata/mft/secret/server/backend/sql/entity/GCSSecretEntity.java
index 24805af..fd8bc80 100644
--- a/services/secret-service/server/src/main/java/org/apache/airavata/mft/secret/server/backend/sql/entity/GCSSecretEntity.java
+++ b/services/secret-service/server/src/main/java/org/apache/airavata/mft/secret/server/backend/sql/entity/GCSSecretEntity.java
@@ -34,8 +34,15 @@ public class GCSSecretEntity
     @GenericGenerator( name = "uuid", strategy = "uuid2")
     private String secretId;
 
-    @Column(name = "CREDENTIALS_JSON")
-    private String credentialsJson;
+    @Column(name = "PROJECT_ID")
+    private String projectId;
+
+    @Column(name = "PRIVATE_KEY")
+    private String privateKey;
+
+    @Column(name = "CLIENT_EMAIL")
+    private String clientEmail;
+
 
     public String getSecretId()
     {
@@ -47,13 +54,33 @@ public class GCSSecretEntity
         this.secretId = secretId;
     }
 
-    public String getCredentialsJson()
+    public String getProjectId()
+    {
+        return projectId;
+    }
+
+    public void setProjectId( String projectId )
+    {
+        this.projectId = projectId;
+    }
+
+    public String getPrivateKey()
+    {
+        return privateKey;
+    }
+
+    public void setPrivateKey( String privateKey )
+    {
+        this.privateKey = privateKey;
+    }
+
+    public String getClientEmail()
     {
-        return credentialsJson;
+        return clientEmail;
     }
 
-    public void setCredentialsJson( String credentialsJson )
+    public void setClientEmail( String clientEmail )
     {
-        this.credentialsJson = credentialsJson;
+        this.clientEmail = clientEmail;
     }
 }
diff --git a/services/secret-service/server/src/main/resources/secrets.json.template b/services/secret-service/server/src/main/resources/secrets.json.template
index dbda1eb..7a73d4a 100644
--- a/services/secret-service/server/src/main/resources/secrets.json.template
+++ b/services/secret-service/server/src/main/resources/secrets.json.template
@@ -26,7 +26,9 @@
   {
     "type": "GCS",
     "secretId": "gcs-cred",
-    "credentialsJson": ""
+    "projectId": "first-tine-364217",
+    "privateKey": "hoied0fq2u2cgnsr3ao6rfmbqb1d44js",
+    "clientEmail": "997596903830-hoied0fq2u2cgnsr3ao6rfmbqb1d44js.apps.googleusercontent.com"
   },
   {
     "type": "DROPBOX",
diff --git a/services/secret-service/stub/src/main/proto/gcs/GCSCredential.proto b/services/secret-service/stub/src/main/proto/gcs/GCSCredential.proto
index 0d7d2a0..a40b996 100644
--- a/services/secret-service/stub/src/main/proto/gcs/GCSCredential.proto
+++ b/services/secret-service/stub/src/main/proto/gcs/GCSCredential.proto
@@ -36,8 +36,10 @@ message GCSSecretGetRequest {
 }
 
 message GCSSecretCreateRequest {
-    string credentialsJson = 1;
-    org.apache.airavata.mft.common.AuthToken authzToken = 2;
+    string projectId = 1;
+    string privateKey = 2;
+    string clientEmail = 3;
+    org.apache.airavata.mft.common.AuthToken authzToken = 4;
 }
 
 message GCSSecretUpdateRequest {