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 <Jayan1@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;
+
[email protected]( 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;
+
[email protected]( 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;
+
[email protected]( 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);
+}