diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f2129d..161eb38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v2-7.0-SNAPSHOT] - 2022-01-31 + +**New** + +- [#22757] moved to storagehub-client-library 2.0.0[-SNAPSHOT] + ## [v2-6-1] - 2022-01-17 **New features** diff --git a/pom.xml b/pom.xml index 2595b76..cd6a154 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ org.gcube.data.transfer uri-resolver - 2.6.1 + 2.7.0-SNAPSHOT war The URI Resolver is an HTTP URI resolver implemented as an REST service which gives access trough HTTP to different gcube Resolvers and gCube Applications. @@ -123,7 +123,7 @@ org.gcube.common storagehub-client-library - [1.0.0, 2.0.0-SNAPSHOT) + [2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT) @@ -200,6 +200,12 @@ + + org.geotoolkit + geotk-xml-base + 3.20-geoapi-3.0 + + commons-lang commons-lang @@ -298,4 +304,4 @@ - \ No newline at end of file + diff --git a/src/test/java/org/gcube/datatransfer/test/ServiceEndpointReader.java b/src/test/java/org/gcube/datatransfer/test/ServiceEndpointReader.java new file mode 100644 index 0000000..8f5c0ce --- /dev/null +++ b/src/test/java/org/gcube/datatransfer/test/ServiceEndpointReader.java @@ -0,0 +1,116 @@ +package org.gcube.datatransfer.test; + +import static org.gcube.resources.discovery.icclient.ICFactory.clientFor; +import static org.gcube.resources.discovery.icclient.ICFactory.queryFor; + +import java.util.Collection; +import java.util.List; + +import org.apache.log4j.Logger; +import org.gcube.common.encryption.StringEncrypter; +import org.gcube.common.resources.gcore.ServiceEndpoint; +import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.datatransfer.resolver.services.exceptions.NotFoundException; +import org.gcube.resources.discovery.client.api.DiscoveryClient; +import org.gcube.resources.discovery.client.queries.api.SimpleQuery; + +/** + * The Class ServiceEndpointReader. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Jan 27, 2022 + */ +public class ServiceEndpointReader { + + private static final String RESOURCE_NAME = "DEV Geoserver"; + private static final String CATEGORY_NAME = "Gis"; + private static final String SCOPE = "/gcube/devsec/devVRE"; + + public static Logger LOG = Logger.getLogger(ServiceEndpointReader.class); + + + public static void main(String[] args) { + try { + readServiceEndpoint(SCOPE); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + /** + * Read service endpoint. + * + * @param req the req + * @param scope the scope + * @throws Exception + */ + public static void readServiceEndpoint(String scope) throws Exception{ + + String callerScope = null; + try{ + callerScope = ScopeProvider.instance.get(); + ScopeProvider.instance.set(scope); + LOG.info("Searching SE "+RESOURCE_NAME +" configurations in the scope: "+ScopeProvider.instance.get()); + + SimpleQuery query = queryFor(ServiceEndpoint.class); + query.addCondition("$resource/Profile/Name/text() eq '"+ RESOURCE_NAME +"'"); + query.addCondition("$resource/Profile/Category/text() eq '"+ CATEGORY_NAME +"'"); + + DiscoveryClient client = clientFor(ServiceEndpoint.class); + List toReturn = client.submit(query); + + LOG.info("The query returned "+toReturn.size()+ " ServiceEndpoint/s"); + + if(toReturn.size()==0){ + String errorMessage = String.format("Missing the RR with Name '%s' and Category '%s' in the scope '%s'. Please contact the support.",RESOURCE_NAME,CATEGORY_NAME,ScopeProvider.instance.get()); + LOG.error(errorMessage); + throw new Exception(errorMessage); + + } + + String accessPointUsername = null; + String accessPointPwd = null; + + ServiceEndpoint se = toReturn.get(0); + Collection theAccessPoints = se.profile().accessPoints().asCollection(); + for (AccessPoint accessPoint : theAccessPoints) { + accessPointUsername = accessPoint.username(); + System.out.println("AccessPoint username: "+accessPointPwd); + accessPointPwd = accessPoint.password(); + if(accessPointUsername!=null && accessPointPwd!=null) { + LOG.info("returning the access point with name: "+accessPoint.name()); + if (accessPointPwd != null) { + accessPointPwd = StringEncrypter.getEncrypter().decrypt(accessPointPwd); + LOG.info("Decrypted pwd registered into Access Point '" + accessPoint.name() + "' is: " + + accessPointPwd.substring(0,accessPointPwd.length()/2)+"..."); + + System.out.println("AccessPoint pwd is: "+accessPointPwd); + } + } + } + + + }catch(Exception e){ + + if(e instanceof NotFoundException) + throw e; + + String errorMessage = "Error occurred on reading the "+RESOURCE_NAME+" SE registered in the scope: "+ScopeProvider.instance.get(); + LOG.error(errorMessage, e); + throw new Exception(errorMessage); + + }finally{ + if(callerScope!=null){ + LOG.info("Setting to the callerScope scope: "+callerScope); + ScopeProvider.instance.set(callerScope); + }else{ + LOG.info("Reset scope"); + ScopeProvider.instance.reset(); + } + } + + } + +}