removed ScopeProvider and several deprecated classes
This commit is contained in:
parent
ad8aef1b52
commit
857fd1bdf8
|
@ -4,7 +4,8 @@
|
||||||
* removed slf4j implementations, added slf4j-simple;
|
* removed slf4j implementations, added slf4j-simple;
|
||||||
* Discovering serviceEndpoint with category Storage
|
* Discovering serviceEndpoint with category Storage
|
||||||
* moved version from 3.1.0-SNAPSHOT to 4.0.0-SNAPSHOT
|
* moved version from 3.1.0-SNAPSHOT to 4.0.0-SNAPSHOT
|
||||||
|
* upgrade to gcube-bom 3 and ScopeProvider removed
|
||||||
|
* removed environment variable scope
|
||||||
|
|
||||||
## [v3.0.1-SNAPSHOT]
|
## [v3.0.1-SNAPSHOT]
|
||||||
* removed http protocol;
|
* removed http protocol;
|
||||||
|
|
4
pom.xml
4
pom.xml
|
@ -16,13 +16,15 @@
|
||||||
</scm>
|
</scm>
|
||||||
<properties>
|
<properties>
|
||||||
<distroDirectory>${project.basedir}/distro</distroDirectory>
|
<distroDirectory>${project.basedir}/distro</distroDirectory>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.distribution</groupId>
|
<groupId>org.gcube.distribution</groupId>
|
||||||
<artifactId>gcube-bom</artifactId>
|
<artifactId>gcube-bom</artifactId>
|
||||||
<version>2.0.1</version>
|
<version>3.0.0-SNAPSHOT</version>
|
||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
|
@ -2,35 +2,15 @@ package org.gcube.common.scope.impl;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check the validity of a given scope
|
* Utility class
|
||||||
* @author Roberto Cirillo (ISTI-CNR)
|
* @author Roberto Cirillo (ISTI-CNR)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ServiceMapScannerMediator {
|
public class ServiceMapScannerMediator {
|
||||||
|
|
||||||
/**
|
|
||||||
* The validation has been removed
|
|
||||||
* @param scope
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public static boolean isValid(String scope){
|
|
||||||
// log.debug("validating scope "+scope);
|
|
||||||
String currentScope=ScopeProvider.instance.get();
|
|
||||||
ScopeProvider.instance.set(scope);
|
|
||||||
try{
|
|
||||||
new ScopedServiceMap().scope();
|
|
||||||
|
|
||||||
}catch(Exception e){
|
|
||||||
return false;
|
|
||||||
}finally{
|
|
||||||
ScopeProvider.instance.set(currentScope);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static Set<String> getScopeKeySet(){
|
public static Set<String> getScopeKeySet(){
|
||||||
|
|
|
@ -1,155 +0,0 @@
|
||||||
package org.gcube.contentmanager.storageclient.model.protocol;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
//import org.gcube.common.core.scope.GCUBEScope;
|
|
||||||
//import org.gcube.common.core.scope.GCUBEScopeManager;
|
|
||||||
import org.gcube.contentmanager.storageclient.model.protocol.smp.Handler;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility methods for content URI creation and manipulation.
|
|
||||||
* @author Fabio Simeoni (University of Strathclyde)
|
|
||||||
* @author Roberto Cirillo (ISTI-CNR)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class URIs {
|
|
||||||
|
|
||||||
static {
|
|
||||||
Handler.activateProtocol();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**Scheme of cms URIs.*/
|
|
||||||
public static final String PROTOCOL="smp";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicates whether a URI is a valid content URI.
|
|
||||||
* @param uri the URI.
|
|
||||||
* @throws URISyntaxException if the URI fails validation.
|
|
||||||
*/
|
|
||||||
public static void validate(URI uri) throws URISyntaxException {
|
|
||||||
if (!PROTOCOL.equals(uri.getScheme()) ||
|
|
||||||
uri.getAuthority()==null ||
|
|
||||||
uri.getPath()==null ||
|
|
||||||
uri.getPath().length()<2)
|
|
||||||
throw new IllegalArgumentException(new URISyntaxException(uri.toString(),"uri is not a well-formed content URI"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a content URI from a collection identifiers and one or more node identifiers.
|
|
||||||
* @param collectionID the collection identifier.
|
|
||||||
* @param identifiers the node identifiers.
|
|
||||||
* @return the URI.
|
|
||||||
* @throws IllegalArgumentException if the input is <code>null</code> or empty.
|
|
||||||
*/
|
|
||||||
public static URI make(String collectionID, String ... identifiers) throws IllegalArgumentException {
|
|
||||||
|
|
||||||
if (collectionID==null || identifiers==null || identifiers.length==0)
|
|
||||||
throw new IllegalArgumentException("null or empty input");
|
|
||||||
|
|
||||||
StringBuilder path = new StringBuilder();
|
|
||||||
for (Object id : identifiers)
|
|
||||||
path.append("/"+id.toString());
|
|
||||||
|
|
||||||
URI uri = null;
|
|
||||||
try {
|
|
||||||
uri = new URI(PROTOCOL,collectionID,path.toString(),null);
|
|
||||||
}
|
|
||||||
catch(URISyntaxException e) {
|
|
||||||
throw new RuntimeException("error in generation uri with "+PROTOCOL+","+collectionID+","+path,e);
|
|
||||||
}
|
|
||||||
return uri;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the collection identifier in a <code>sm</code> URI.
|
|
||||||
* @param uri the URI.
|
|
||||||
* @return the identifier.
|
|
||||||
* @throws URISyntaxException if the URI is not a content URI.
|
|
||||||
*/
|
|
||||||
public static String collectionID(URI uri) throws URISyntaxException {
|
|
||||||
validate(uri);
|
|
||||||
return uri.getAuthority();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the document identifier in a content URI.
|
|
||||||
* @param uri the URI.
|
|
||||||
* @return the identifier.
|
|
||||||
* @throws URISyntaxException if the URI is not a content URI.
|
|
||||||
*/
|
|
||||||
public static String documentID(URI uri) throws URISyntaxException {
|
|
||||||
validate(uri);
|
|
||||||
String p = uri.getPath().substring(1);
|
|
||||||
if (p.endsWith("/"))
|
|
||||||
p = p.substring(0,p.length()-1);
|
|
||||||
int index = p.indexOf("/");
|
|
||||||
return p.substring(0,index>0?index:p.length());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the identifier of the node identified by a content URI.
|
|
||||||
* @param uri the URI.
|
|
||||||
* @return the identifier.
|
|
||||||
* @throws URISyntaxException if the URI is not a content URI.
|
|
||||||
*/
|
|
||||||
public static String nodeID(URI uri) throws URISyntaxException {
|
|
||||||
validate(uri);
|
|
||||||
return uri.getPath().substring(uri.getPath().lastIndexOf("/")+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the identifiers in a content URI.
|
|
||||||
* @param uri the URI.
|
|
||||||
* @return the identifiers.
|
|
||||||
* @throws URISyntaxException if the URI is not a content URI.
|
|
||||||
*/
|
|
||||||
public static String[] nodeIDs(URI uri) throws URISyntaxException {
|
|
||||||
validate(uri);
|
|
||||||
List<String> ids = new ArrayList<String>();
|
|
||||||
for (String s : uri.getPath().substring(1).split("/")) //will be validated here
|
|
||||||
ids.add(s);
|
|
||||||
return ids.toArray(new String[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a content URI for the parent of the node identified by another content URI.
|
|
||||||
* @param uri the input URI.
|
|
||||||
* @return the parent URI.
|
|
||||||
* @throws URISyntaxException if the input URI is not a content URL.
|
|
||||||
*/
|
|
||||||
public static URI parentURI(URI uri) throws URISyntaxException {
|
|
||||||
validate(uri);
|
|
||||||
String u = uri.getPath();
|
|
||||||
return make(uri.getAuthority(),u.substring(1,u.lastIndexOf("/")).split("/"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a content URI for the document of the node identified by another content URI.
|
|
||||||
* @param uri the input URI.
|
|
||||||
* @return the document URI.
|
|
||||||
* @throws URISyntaxException if the input URI is not a content URI.
|
|
||||||
*/
|
|
||||||
public static URI documentURI(URI uri) throws URISyntaxException {
|
|
||||||
validate(uri);
|
|
||||||
return make(uri.getAuthority(),documentID(uri));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a URL connection in a given scope.
|
|
||||||
* @param uri a content URI.
|
|
||||||
* @param scope the scope.
|
|
||||||
* @return the connection.
|
|
||||||
* @throws IOException if the connections could not be established.
|
|
||||||
* @throws URISyntaxException if the URI is not a content URI or if the protocol handler for the <code>smp</code> scheme is not active.
|
|
||||||
* @deprecated since 2.3.1. Use {@link URLConnection} normally in current scope.
|
|
||||||
*/
|
|
||||||
public static URLConnection connection(URI uri, String scope) throws IOException, URISyntaxException {
|
|
||||||
validate(uri);
|
|
||||||
URLConnection connection = uri.toURL().openConnection();
|
|
||||||
return connection;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
package org.gcube.contentmanager.storageclient.model.protocol.smp;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.net.URLStreamHandler;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A handler for the <code>smp</code> protocol.
|
|
||||||
* @author Fabio Simeoni (University of Strathclyde)
|
|
||||||
* @author Roberto Cirillo (ISTI-CNR)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class Handler extends URLStreamHandler {
|
|
||||||
|
|
||||||
/**{@inheritDoc}*/
|
|
||||||
@Override
|
|
||||||
protected URLConnection openConnection(URL u) throws IOException {
|
|
||||||
return SMPURLConnectionFactory.getSmp(u);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers the protocol with the JVM.
|
|
||||||
*/
|
|
||||||
public static void activateProtocol() {
|
|
||||||
|
|
||||||
String pkgs_name="java.protocol.handler.pkgs";
|
|
||||||
String pkgs = System.getProperty(pkgs_name);
|
|
||||||
String pkg = "org.gcube.contentmanager.storageclient.model.protocol";
|
|
||||||
if (pkgs==null)
|
|
||||||
pkgs = pkg ;
|
|
||||||
else if (!pkgs.contains(pkg))
|
|
||||||
pkgs = pkgs+"|"+pkg;
|
|
||||||
System.setProperty(pkgs_name, pkgs);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,60 +0,0 @@
|
||||||
package org.gcube.contentmanager.storageclient.model.protocol.smp;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
|
||||||
import org.gcube.contentmanager.storageclient.wrapper.ISClientConnector;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An extension of URLConnection used for smp url
|
|
||||||
* @author Roberto Cirillo (ISTI-CNR)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public abstract class SMPConnection extends URLConnection {
|
|
||||||
|
|
||||||
Logger logger= LoggerFactory.getLogger(SMPURLConnection.class);
|
|
||||||
|
|
||||||
public SMPConnection(URL url) {
|
|
||||||
super(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract URLConnection init(URL url);
|
|
||||||
|
|
||||||
/**{@inheritDoc}*/
|
|
||||||
@Override
|
|
||||||
public synchronized void connect() throws IOException {
|
|
||||||
connected=true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public abstract InputStream getInputStream() throws IOException;
|
|
||||||
|
|
||||||
|
|
||||||
protected abstract InputStream storageClient(String url) throws Exception;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method has been moved in Configuration class
|
|
||||||
* @param rootScope
|
|
||||||
* @return
|
|
||||||
* @throws Exception
|
|
||||||
* @see org.gcube.contentmanager.storageclient.wrapper.Configuration
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
protected String retrieveEncryptionPhrase() throws Exception {
|
|
||||||
String currentScope=ScopeProvider.instance.get();
|
|
||||||
logger.debug("retrieve encryption prhase on scope: "+currentScope);
|
|
||||||
String encryptedKey=null;
|
|
||||||
ISClientConnector isclient=new ISClientConnector();
|
|
||||||
encryptedKey=isclient.retrievePropertyValue("PassPhrase", currentScope);
|
|
||||||
String decryptString=org.gcube.common.encryption.StringEncrypter.getEncrypter().decrypt(encryptedKey);
|
|
||||||
return decryptString;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,47 +0,0 @@
|
||||||
package org.gcube.contentmanager.storageclient.model.protocol.smp;
|
|
||||||
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* This is invoked by the platform with a URL of the right protocol.
|
|
||||||
* @author Fabio Simeoni (University of Strathclyde), @author Roberto Cirillo (ISTI-CNR)
|
|
||||||
* @deprecated this class will be deleted and will be changed with the factory class invocation: SMPURLConnectionFactory
|
|
||||||
* @see SMPURLConnectionFactory
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class SMPURLConnection extends URLConnection {
|
|
||||||
|
|
||||||
SMPConnection smp;
|
|
||||||
Logger logger= LoggerFactory.getLogger(SMPURLConnection.class);
|
|
||||||
/**
|
|
||||||
* Constructs a new instance for a given <code>sm</code> URL.
|
|
||||||
* @deprecated reason this method is deprecated </br>
|
|
||||||
* {will be removed in next version} </br>
|
|
||||||
* use {@link #SMPURLConnectionFactory.getSmp(url)}
|
|
||||||
* @param url the URL.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public SMPURLConnection(URL url) {
|
|
||||||
super(url);
|
|
||||||
this.smp=SMPURLConnectionFactory.getSmp(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**{@inheritDoc}*/
|
|
||||||
@Override
|
|
||||||
public synchronized void connect() throws IOException {
|
|
||||||
connected=true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**{@inheritDoc}*/
|
|
||||||
@Override
|
|
||||||
public synchronized InputStream getInputStream() throws IOException {
|
|
||||||
return smp.getInputStream();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,115 +0,0 @@
|
||||||
package org.gcube.contentmanager.storageclient.model.protocol.smp;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
import org.apache.commons.codec.binary.Base64;
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
|
||||||
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
|
||||||
import org.gcube.contentmanagement.blobstorage.service.operation.GetHttpUrl;
|
|
||||||
import org.gcube.contentmanagement.blobstorage.service.operation.GetUrl;
|
|
||||||
import org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants;
|
|
||||||
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
|
|
||||||
import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
|
|
||||||
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is invoked by the platform with a URL of the smp protocol with new format (>= 2.2.0 version) .
|
|
||||||
* @author Roberto Cirillo (ISTI-CNR)
|
|
||||||
*
|
|
||||||
* Example: smp://data.gcube.org?uhdnfounhcfnshfnrhbvyaeegytf6dfawiuawgcyg
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class SMPURLConnectionById extends SMPConnection {
|
|
||||||
|
|
||||||
private Logger logger= LoggerFactory.getLogger(SMPURLConnectionOld.class);
|
|
||||||
private String serviceClass="Storage-manager";
|
|
||||||
private String serviceName="resolver-uri";
|
|
||||||
private String owner="storage-manager";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new instance for a given <code>sm</code> URL.
|
|
||||||
* @param url the URL.
|
|
||||||
*/
|
|
||||||
public SMPURLConnectionById(URL url) {
|
|
||||||
super(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SMPConnection init(URL url){
|
|
||||||
return new SMPURLConnectionById(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**{@inheritDoc}
|
|
||||||
* internal handler implementation
|
|
||||||
* */
|
|
||||||
@Override
|
|
||||||
public synchronized InputStream getInputStream() throws IOException {
|
|
||||||
if (!connected)
|
|
||||||
this.connect();
|
|
||||||
try {
|
|
||||||
return storageClient(this.url.toString());
|
|
||||||
}
|
|
||||||
catch(Exception e) {
|
|
||||||
IOException ioe = new IOException();
|
|
||||||
ioe.initCause(e);
|
|
||||||
throw ioe;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a StorageManager instance from url
|
|
||||||
*/
|
|
||||||
|
|
||||||
protected InputStream storageClient(String url) throws Exception {
|
|
||||||
logger.info("url :" + url);
|
|
||||||
String [] urlParam=url.split(Costants.URL_SEPARATOR);
|
|
||||||
String protocol=urlParam[0];
|
|
||||||
protocol=protocol.substring(0, protocol.length()-1);
|
|
||||||
logger.debug("protocol is "+protocol);
|
|
||||||
if(ScopeProvider.instance.get() == null){
|
|
||||||
throw new RuntimeException("Scope not set");
|
|
||||||
}
|
|
||||||
String encrypted=retrieveStringEncrypted(urlParam);
|
|
||||||
MemoryType memory=null;
|
|
||||||
if(encrypted.contains(Costants.VOLATILE_URL_IDENTIFICATOR)){
|
|
||||||
memory=MemoryType.VOLATILE;
|
|
||||||
encrypted=encrypted.replace(Costants.VOLATILE_URL_IDENTIFICATOR, "");
|
|
||||||
}
|
|
||||||
logger.debug("String encrypted "+encrypted);
|
|
||||||
String phrase=retrieveEncryptionPhrase();
|
|
||||||
String location=null;
|
|
||||||
if(Base64.isBase64(encrypted) && (protocol.equalsIgnoreCase("http"))){
|
|
||||||
byte[] valueDecoded= Base64.decodeBase64(encrypted);
|
|
||||||
String encryptedID = new String(valueDecoded);
|
|
||||||
location=new StringDecrypter("DES", phrase).decrypt(encryptedID);
|
|
||||||
}else{
|
|
||||||
location=new StringDecrypter("DES", phrase).decrypt(encrypted);
|
|
||||||
}
|
|
||||||
IClient client=null;
|
|
||||||
if(memory!=null)
|
|
||||||
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, memory).getClient();
|
|
||||||
else
|
|
||||||
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED).getClient();
|
|
||||||
InputStream is=null;
|
|
||||||
is=client.get().RFileAsInputStream(location);
|
|
||||||
return is;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String retrieveStringEncrypted(String[] urlParam) {
|
|
||||||
String encrypted=urlParam[3];
|
|
||||||
int i=4;
|
|
||||||
while(i < urlParam.length){
|
|
||||||
encrypted=encrypted+Costants.URL_SEPARATOR+urlParam[i];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return encrypted;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,120 +0,0 @@
|
||||||
package org.gcube.contentmanager.storageclient.model.protocol.smp;
|
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.ServiceLoader;
|
|
||||||
|
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
|
||||||
import org.gcube.common.scope.impl.ScopeBean;
|
|
||||||
import org.gcube.common.scope.impl.ScopeBean.Type;
|
|
||||||
import org.gcube.contentmanagement.blobstorage.service.operation.GetUrl;
|
|
||||||
import org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants;
|
|
||||||
import org.gcube.contentmanager.storageclient.protocol.utils.Utils;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Factory class used to determine the right smp url protocol: old format(<2.2.0 version), new format (>= 2.2.0-SNAPSHOT)
|
|
||||||
* @author Roberto Cirillo (ISTI-CNR)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class SMPURLConnectionFactory {
|
|
||||||
|
|
||||||
static Logger logger=LoggerFactory.getLogger(SMPURLConnectionFactory.class);
|
|
||||||
|
|
||||||
public static SMPConnection getSmp(URL url) {
|
|
||||||
String urlString=url.toString();
|
|
||||||
Utils.checkScopeProvider();
|
|
||||||
if(isNewSmpFormat(urlString)|| isIntermediateType(urlString)){
|
|
||||||
logger.info("detected new smp format "+url);
|
|
||||||
SMPConnection connection=load(url);
|
|
||||||
if (connection!= null)
|
|
||||||
return connection;
|
|
||||||
return new SMPURLConnectionById(url);
|
|
||||||
}else{
|
|
||||||
logger.info("detected old smp format "+url);
|
|
||||||
return new SMPURLConnectionOld(url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* patch method for a particular smp uri: smp://data.gcube.org/8TFLhJ991DF1M/Ae8rGamC3CgCjAXlnVGmbP5+HKCzc=
|
|
||||||
* @param urlString
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private static boolean isIntermediateType(String urlString) {
|
|
||||||
String [] urlParam=urlString.split(Costants.URL_SEPARATOR);
|
|
||||||
String infraHost=urlParam[2];
|
|
||||||
if(Utils.isScopeProviderMatch(infraHost))
|
|
||||||
return true;
|
|
||||||
String infra=Utils.getInfraFromResolverHost(infraHost);
|
|
||||||
String rootScope="/"+infra;
|
|
||||||
ScopeBean scope=new ScopeBean(rootScope);
|
|
||||||
if(scope.is(Type.INFRASTRUCTURE)){
|
|
||||||
return Utils.validationScope2(rootScope);
|
|
||||||
}else{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isNewSmpFormat(String urlString) {
|
|
||||||
logger.debug("check format: "+urlString);
|
|
||||||
String httpString=urlString;
|
|
||||||
httpString=httpString.replace("smp://", "https://");
|
|
||||||
logger.debug("httpsUrl conversion: "+httpString);
|
|
||||||
URL httpsUrl=null;
|
|
||||||
try {
|
|
||||||
httpsUrl=new URL(httpString);
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
List<ServiceEndpoint> services=Utils.queryServiceEndpoint(Utils.URI_RESOLVER_RESOURCE_CATEGORY, Utils.URI_RESOLVER_RESOURCE_NAME);
|
|
||||||
String host=null;
|
|
||||||
if(services != null && services.size()>0){
|
|
||||||
host=Utils.getResolverHost(services.get(0));
|
|
||||||
}
|
|
||||||
logger.debug("uri-resolver host: "+host+" in scope: "+ScopeProvider.instance.get());
|
|
||||||
if((host!=null) && (host.equals(httpsUrl.getHost()))){
|
|
||||||
return true;
|
|
||||||
}else{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load a backend driver from classpath
|
|
||||||
* @param url
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private static SMPConnection load(URL url){
|
|
||||||
ServiceLoader<SMPConnection> loader = ServiceLoader.load(SMPConnection.class);
|
|
||||||
Iterator<SMPConnection> iterator = loader.iterator();
|
|
||||||
List<SMPConnection> impls = new ArrayList<SMPConnection>();
|
|
||||||
while(iterator.hasNext())
|
|
||||||
impls.add(iterator.next());
|
|
||||||
int implementationCounted=impls.size();
|
|
||||||
// System.out.println("size: "+implementationCounted);
|
|
||||||
if(implementationCounted==0){
|
|
||||||
logger.info(" 0 implementation found. Load default implementation of SMPConnection");
|
|
||||||
return null;
|
|
||||||
}else if(implementationCounted>0){
|
|
||||||
SMPConnection connection = impls.get(0);
|
|
||||||
logger.info("1 implementation of TransportManager found. ");
|
|
||||||
connection.init(url);
|
|
||||||
return connection;
|
|
||||||
}else{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,147 +0,0 @@
|
||||||
package org.gcube.contentmanager.storageclient.model.protocol.smp;
|
|
||||||
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
|
||||||
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
|
||||||
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
|
|
||||||
import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
|
|
||||||
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* This is invoked by the platform with a URL of the right protocol.
|
|
||||||
* @author Fabio Simeoni (University of Strathclyde), @author Roberto Cirillo (ISTI-CNR)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class SMPURLConnectionOld extends SMPConnection{
|
|
||||||
|
|
||||||
|
|
||||||
Logger logger= LoggerFactory.getLogger(SMPURLConnectionOld.class);
|
|
||||||
/**
|
|
||||||
* Constructs a new instance for a given <code>sm</code> URL.
|
|
||||||
* @param url the URL.
|
|
||||||
*/
|
|
||||||
public SMPURLConnectionOld(URL url) {
|
|
||||||
super(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SMPConnection init(URL url){
|
|
||||||
return new SMPURLConnectionOld(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**{@inheritDoc}*/
|
|
||||||
@Override
|
|
||||||
public synchronized InputStream getInputStream() throws IOException {
|
|
||||||
if (!connected)
|
|
||||||
this.connect();
|
|
||||||
try {
|
|
||||||
return storageClient(this.url.toString());
|
|
||||||
}
|
|
||||||
catch(Exception e) {
|
|
||||||
IOException ioe = new IOException();
|
|
||||||
ioe.initCause(e);
|
|
||||||
throw ioe;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected InputStream storageClient(String url) throws Exception {
|
|
||||||
logger.info("url :" + url);
|
|
||||||
String [] urlParam=url.split("\\?");
|
|
||||||
logger.info("String encrypted "+urlParam[1]);
|
|
||||||
String param=new StringDecrypter("DES", retrieveEncryptionPhrase()).decrypt(urlParam[1]);
|
|
||||||
logger.info("String decrypted: "+param);
|
|
||||||
String [] getParam=param.split("\\&");
|
|
||||||
String serviceClass=null;
|
|
||||||
String serviceName=null;
|
|
||||||
String owner=null;
|
|
||||||
String accessType=null;
|
|
||||||
String memoryType=null;
|
|
||||||
String scopeType=null;
|
|
||||||
AccessType type = null;
|
|
||||||
MemoryType mType = null;
|
|
||||||
String server= null;
|
|
||||||
String [] par1;
|
|
||||||
for(String par : getParam){
|
|
||||||
if(par.contains("ServiceClass")){
|
|
||||||
par1=par.split("=");
|
|
||||||
serviceClass=par1[1];
|
|
||||||
}else if(par.contains("ServiceName")){
|
|
||||||
par1=par.split("=");
|
|
||||||
serviceName=par1[1];
|
|
||||||
}else if(par.contains("owner")){
|
|
||||||
par1=par.split("=");
|
|
||||||
owner=par1[1];
|
|
||||||
}else if(par.contains("scope")){
|
|
||||||
par1=par.split("=");
|
|
||||||
scopeType=par1[1];
|
|
||||||
}else if(par.contains("server")){
|
|
||||||
par1=par.split("=");
|
|
||||||
server=par1[1];
|
|
||||||
}else if(par.contains("AccessType")){
|
|
||||||
par1=par.split("=");
|
|
||||||
accessType=par1[1];
|
|
||||||
if(accessType.equalsIgnoreCase("public")){
|
|
||||||
type=AccessType.PUBLIC;
|
|
||||||
}else if(accessType.equalsIgnoreCase("shared")){
|
|
||||||
type=AccessType.SHARED;
|
|
||||||
}
|
|
||||||
}else if(par.contains("MemoryType")){
|
|
||||||
par1=par.split("=");
|
|
||||||
memoryType=par1[1];
|
|
||||||
if(memoryType.equalsIgnoreCase("VOLATILE")){
|
|
||||||
mType=MemoryType.VOLATILE;
|
|
||||||
}else{
|
|
||||||
mType=MemoryType.PERSISTENT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// throw an exception if one or more uri parameters are invalid
|
|
||||||
if((serviceName==null) || (serviceClass==null) || (owner == null) || (scopeType==null) || (type == null)){
|
|
||||||
logger.error("Bad Parameter in URI");
|
|
||||||
if (type == null){
|
|
||||||
logger.error("URI generated from a private file");
|
|
||||||
throw new MalformedURLException("The uri is generated from a private file. It cannot be accessed");
|
|
||||||
}
|
|
||||||
if (serviceName==null) throw new MalformedURLException("The uri generated has an invalid serviceName");
|
|
||||||
if (serviceClass==null) throw new MalformedURLException("The uri generated has an invalid serviceClass");
|
|
||||||
if (owner==null) throw new MalformedURLException("The uri generated has an invalid owner");
|
|
||||||
if (scopeType==null) throw new MalformedURLException("The uri is generated has an invalid scopeType.");
|
|
||||||
}
|
|
||||||
String location=extractLocation(urlParam[0]);
|
|
||||||
logger.info("Parameters from URI "+serviceClass+" "+serviceName+" "+owner+" "+type+" "+mType +" location: "+urlParam[0]+" scope: "+scopeType);
|
|
||||||
IClient client=null;
|
|
||||||
String currentScope=ScopeProvider.instance.get();
|
|
||||||
logger.info("current scope used: "+currentScope+". scope found on url is: "+ scopeType);
|
|
||||||
// ScopeProvider.instance.set(scopeType);
|
|
||||||
if(mType != null){
|
|
||||||
if(server!=null)
|
|
||||||
client=new StorageClient(serviceClass, serviceName, owner, type, mType, server).getClient();
|
|
||||||
else
|
|
||||||
client=new StorageClient(serviceClass, serviceName, owner, type, mType).getClient();
|
|
||||||
}else{
|
|
||||||
if (server != null)
|
|
||||||
client=new StorageClient(serviceClass, serviceName, owner, server, type ).getClient();
|
|
||||||
else
|
|
||||||
client=new StorageClient(serviceClass, serviceName, owner, type).getClient();
|
|
||||||
}
|
|
||||||
InputStream is=null;
|
|
||||||
is=client.get().RFileAsInputStream(location);
|
|
||||||
// ScopeProvider.instance.set(currentScope);
|
|
||||||
return is;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String extractLocation(String url) {
|
|
||||||
String [] loc=url.split("//");
|
|
||||||
logger.info("url extracted: "+loc[1]);
|
|
||||||
return loc[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,137 +0,0 @@
|
||||||
package org.gcube.contentmanager.storageclient.model.protocol.smp;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import org.gcube.contentmanager.storageclient.model.protocol.smp.SMPURLConnectionFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Allow to the end user to manage a smp url as an url with a configured stream handler
|
|
||||||
* @author Roberto Cirillo (ISTI-CNR)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class SMPUrl extends java.net.URLStreamHandler{
|
|
||||||
|
|
||||||
private java.net.URL url;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* map a url string as a normal url
|
|
||||||
* @param u url string
|
|
||||||
* @throws MalformedURLException
|
|
||||||
*/
|
|
||||||
public SMPUrl(String u) throws MalformedURLException{
|
|
||||||
this.url=new java.net.URL(null, u, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public URLConnection openConnection() throws IOException{
|
|
||||||
return this.openConnection(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected URLConnection openConnection(java.net.URL u) throws IOException {
|
|
||||||
if(u.getProtocol().equalsIgnoreCase("smp")){
|
|
||||||
return SMPURLConnectionFactory.getSmp(u);
|
|
||||||
}else{
|
|
||||||
return new java.net.URL(null, u.toString()).openConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getHost(){
|
|
||||||
return this.url.getHost();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the path part of this <code>URL</code>.
|
|
||||||
*
|
|
||||||
* @return the path part of this <code>URL</code>, or an
|
|
||||||
* empty string if one does not exist
|
|
||||||
* @since 1.3
|
|
||||||
*/
|
|
||||||
public String getPath() {
|
|
||||||
return url.getPath();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the userInfo part of this <code>URL</code>.
|
|
||||||
*
|
|
||||||
* @return the userInfo part of this <code>URL</code>, or
|
|
||||||
* <CODE>null</CODE> if one does not exist
|
|
||||||
* @since 1.3
|
|
||||||
*/
|
|
||||||
public String getUserInfo() {
|
|
||||||
return url.getUserInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the authority part of this <code>URL</code>.
|
|
||||||
*
|
|
||||||
* @return the authority part of this <code>URL</code>
|
|
||||||
* @since 1.3
|
|
||||||
*/
|
|
||||||
public String getAuthority() {
|
|
||||||
return url.getAuthority();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the port number of this <code>URL</code>.
|
|
||||||
*
|
|
||||||
* @return the port number, or -1 if the port is not set
|
|
||||||
*/
|
|
||||||
public int getPort() {
|
|
||||||
return url.getPort();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the default port number of the protocol associated
|
|
||||||
* with this <code>URL</code>. If the URL scheme or the URLStreamHandler
|
|
||||||
* for the URL do not define a default port number,
|
|
||||||
* then -1 is returned.
|
|
||||||
*
|
|
||||||
* @return the port number
|
|
||||||
* @since 1.4
|
|
||||||
*/
|
|
||||||
public int getDefaultPort() {
|
|
||||||
return url.getDefaultPort();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the protocol name of this <code>URL</code>.
|
|
||||||
*
|
|
||||||
* @return the protocol of this <code>URL</code>.
|
|
||||||
*/
|
|
||||||
public String getProtocol() {
|
|
||||||
return url.getProtocol();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the file name of this <code>URL</code>.
|
|
||||||
* The returned file portion will be
|
|
||||||
* the same as <CODE>getPath()</CODE>, plus the concatenation of
|
|
||||||
* the value of <CODE>getQuery()</CODE>, if any. If there is
|
|
||||||
* no query portion, this method and <CODE>getPath()</CODE> will
|
|
||||||
* return identical results.
|
|
||||||
*
|
|
||||||
* @return the file name of this <code>URL</code>,
|
|
||||||
* or an empty string if one does not exist
|
|
||||||
*/
|
|
||||||
public String getFile() {
|
|
||||||
return url.getFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the anchor (also known as the "reference") of this
|
|
||||||
* <code>URL</code>.
|
|
||||||
*
|
|
||||||
* @return the anchor (also known as the "reference") of this
|
|
||||||
* <code>URL</code>, or <CODE>null</CODE> if one does not exist
|
|
||||||
*/
|
|
||||||
public String getRef() {
|
|
||||||
return url.getRef();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -97,7 +97,7 @@ public class StringDecrypter {
|
||||||
{
|
{
|
||||||
SecretKey key = keyFactory.generateSecret( keySpec );
|
SecretKey key = keyFactory.generateSecret( keySpec );
|
||||||
cipher.init( Cipher.DECRYPT_MODE, key );
|
cipher.init( Cipher.DECRYPT_MODE, key );
|
||||||
return org.gcube.common.encryption.StringEncrypter.getEncrypter().decrypt(encryptedString, key);
|
return org.gcube.common.encryption.encrypter.StringEncrypter.getEncrypter().decrypt(encryptedString, key);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -98,7 +98,7 @@ public class StringEncrypter {
|
||||||
{
|
{
|
||||||
SecretKey key = keyFactory.generateSecret( keySpec );
|
SecretKey key = keyFactory.generateSecret( keySpec );
|
||||||
cipher.init( Cipher.ENCRYPT_MODE, key );
|
cipher.init( Cipher.ENCRYPT_MODE, key );
|
||||||
return org.gcube.common.encryption.StringEncrypter.getEncrypter().encrypt(unencryptedString, key);
|
return org.gcube.common.encryption.encrypter.StringEncrypter.getEncrypter().encrypt(unencryptedString, key);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,10 +9,8 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
|
||||||
import org.gcube.common.scope.impl.ScopeBean;
|
|
||||||
import org.gcube.common.scope.impl.ScopeBean.Type;
|
|
||||||
import org.gcube.common.scope.impl.ServiceMapScannerMediator;
|
import org.gcube.common.scope.impl.ServiceMapScannerMediator;
|
||||||
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -38,45 +36,7 @@ public class Utils {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(Utils.class);
|
private static final Logger logger = LoggerFactory.getLogger(Utils.class);
|
||||||
|
|
||||||
|
|
||||||
public static boolean validationScope2(String scope){
|
|
||||||
ScopeBean scopeBean=new ScopeBean(scope);
|
|
||||||
if((scopeBean.is(Type.VRE)))
|
|
||||||
scope=scopeBean.enclosingScope().toString();
|
|
||||||
return ServiceMapScannerMediator.isValid(scope);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ArrayList<String> getVOScopes(String scope){
|
|
||||||
ArrayList<String> vos=new ArrayList<String>();
|
|
||||||
ScopeBean scopeBean=new ScopeBean(scope);
|
|
||||||
//retrieve INFRA scope
|
|
||||||
while(!scopeBean.is(Type.INFRASTRUCTURE)){
|
|
||||||
logger.debug("the scope "+scope+" is not an INFRA scope ");
|
|
||||||
scopeBean=new ScopeBean(scopeBean.enclosingScope().toString());
|
|
||||||
}
|
|
||||||
scope=scopeBean.toString();
|
|
||||||
if(scopeBean.is(Type.INFRASTRUCTURE)){
|
|
||||||
Set<String> scopeSet=ServiceMapScannerMediator.getScopeKeySet();
|
|
||||||
for(String scopeItem : scopeSet){
|
|
||||||
//retrieve all Vo scopes
|
|
||||||
logger.debug("scope scanned: "+scopeItem);
|
|
||||||
if(scopeItem.contains(scope) && (new ScopeBean(scopeItem).is(Type.VO))){
|
|
||||||
logger.debug("found vo scope: "+scopeItem);
|
|
||||||
vos.add(scopeItem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return vos;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String extractInfrastructureNewVersion(String urlParam){
|
|
||||||
logger.debug("urlParam: "+urlParam);
|
|
||||||
String infra= checkVarEnv(INFRASTRUCTURE_ENV_VARIABLE_NAME);
|
|
||||||
if (infra != null)
|
|
||||||
return infra;
|
|
||||||
else
|
|
||||||
//only for test return the infra from the uri. In prod will be throws a runtime exception
|
|
||||||
return getInfraFromResolverHost(urlParam);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getInfraFromResolverHost(String resolverHost) {
|
public static String getInfraFromResolverHost(String resolverHost) {
|
||||||
if(resolverHost.equals(GCUBE_RESOLVER_HOST)){
|
if(resolverHost.equals(GCUBE_RESOLVER_HOST)){
|
||||||
|
@ -86,48 +46,6 @@ public class Utils {
|
||||||
}else return resolverHost;
|
}else return resolverHost;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String checkVarEnv(String name){
|
|
||||||
Map<String, String> env = System.getenv();
|
|
||||||
TreeSet<String> keys = new TreeSet<String>(env.keySet());
|
|
||||||
Iterator<String> iter = keys.iterator();
|
|
||||||
String value=null;
|
|
||||||
while(iter.hasNext())
|
|
||||||
{
|
|
||||||
String key = iter.next();
|
|
||||||
if(key.equalsIgnoreCase(name)){
|
|
||||||
value=env.get(key);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isScopeProviderMatch(String infraHost) {
|
|
||||||
String currentScope=ScopeProvider.instance.get();
|
|
||||||
if(currentScope != null){
|
|
||||||
//get vo scope
|
|
||||||
String voScope=Utils.getVOScope(currentScope);
|
|
||||||
// get the uri resolver host
|
|
||||||
List<ServiceEndpoint> services=queryServiceEndpoint(URI_RESOLVER_RESOURCE_CATEGORY, URI_RESOLVER_RESOURCE_NAME);
|
|
||||||
String host=null;
|
|
||||||
if(services != null && services.size()>0){
|
|
||||||
host=getResolverHost(services.get(0));
|
|
||||||
if(host!=null){
|
|
||||||
if(infraHost.equalsIgnoreCase(host)){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getVOScope(String currentScope) {
|
|
||||||
ScopeBean scopeBean=new ScopeBean(currentScope);
|
|
||||||
if((scopeBean.is(Type.VRE)))
|
|
||||||
currentScope=scopeBean.enclosingScope().toString();
|
|
||||||
return currentScope;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<ServiceEndpoint> queryServiceEndpoint(String category, String name){
|
public static List<ServiceEndpoint> queryServiceEndpoint(String category, String name){
|
||||||
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
||||||
|
@ -137,25 +55,6 @@ public class Utils {
|
||||||
return resources;
|
return resources;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* if the scope provider is not set then check if the env variable: SCOPE is set and set the scopeProvider
|
|
||||||
*/
|
|
||||||
public static void checkScopeProvider(){
|
|
||||||
String scopeProvided=ScopeProvider.instance.get();
|
|
||||||
logger.info("check scope: scope found "+scopeProvided);
|
|
||||||
if ((scopeProvided==null) || (scopeProvided.isEmpty())){
|
|
||||||
logger.debug("scope not correctly set on ScopeProvider");
|
|
||||||
logger.info("scope: check variable");
|
|
||||||
scopeProvided=Utils.checkVarEnv("SCOPE");
|
|
||||||
if (scopeProvided != null){
|
|
||||||
ScopeProvider.instance.set(scopeProvided);
|
|
||||||
}else{
|
|
||||||
throw new RuntimeException("Scope not set ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static String getResolverHost(ServiceEndpoint serviceEndpoint) {
|
public static String getResolverHost(ServiceEndpoint serviceEndpoint) {
|
||||||
return serviceEndpoint.profile().runtime().hostedOn();
|
return serviceEndpoint.profile().runtime().hostedOn();
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,7 @@ import java.util.Objects;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
import org.gcube.common.scope.impl.ScopeBean;
|
|
||||||
import org.gcube.common.scope.impl.ScopeBean.Type;
|
|
||||||
import org.gcube.contentmanagement.blobstorage.service.impl.ServiceEngine;
|
import org.gcube.contentmanagement.blobstorage.service.impl.ServiceEngine;
|
||||||
import org.gcube.contentmanager.storageclient.protocol.utils.Utils;
|
import org.gcube.contentmanager.storageclient.protocol.utils.Utils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -108,16 +106,14 @@ public class Configuration {
|
||||||
*/
|
*/
|
||||||
public void getConfiguration(){
|
public void getConfiguration(){
|
||||||
String[] newServer=null;
|
String[] newServer=null;
|
||||||
String currentScope=ScopeProvider.instance.get();
|
String currentScope;
|
||||||
|
currentScope = SecretManagerProvider.instance.get().getContext();
|
||||||
logger.debug("Scope found on ScopeProvider instance is "+currentScope);
|
logger.debug("Scope found on ScopeProvider instance is "+currentScope);
|
||||||
if(RRScope == null){
|
logger.debug("Manually scope was set to"+RRScope+" it doesn't take effect");
|
||||||
RRScope=currentScope;
|
|
||||||
}
|
|
||||||
logger.debug("RuntimeResource scope "+RRScope);
|
|
||||||
//if a specific backend is not passed as input param then take the default one
|
//if a specific backend is not passed as input param then take the default one
|
||||||
if (Objects.isNull(getBackendType()))
|
if (Objects.isNull(getBackendType()))
|
||||||
setBackendType(DEFAULT_BACKEND_TYPE);
|
setBackendType(DEFAULT_BACKEND_TYPE);
|
||||||
ServiceEndpoint resource=getISClient(getBackendType()).getStorageEndpoint(RRScope);
|
ServiceEndpoint resource=getISClient(getBackendType()).getStorageEndpoint();
|
||||||
if(resource ==null )
|
if(resource ==null )
|
||||||
throw new IllegalStateException("the storage resource is not present on IS in scope: "+RRScope);
|
throw new IllegalStateException("the storage resource is not present on IS in scope: "+RRScope);
|
||||||
List<ServiceEndpoint> resolverResource =getISClient(getBackendType()).getServiceEndpoint(Utils.URI_RESOLVER_RESOURCE_CATEGORY, Utils.URI_RESOLVER_RESOURCE_NAME);
|
List<ServiceEndpoint> resolverResource =getISClient(getBackendType()).getServiceEndpoint(Utils.URI_RESOLVER_RESOURCE_CATEGORY, Utils.URI_RESOLVER_RESOURCE_NAME);
|
||||||
|
@ -181,20 +177,6 @@ public class Configuration {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Retrieve a valid configuration from IS for instantiating the engine
|
|
||||||
// */
|
|
||||||
// public void getConfiguration2(){
|
|
||||||
// String currentScope=ScopeProvider.instance.get();
|
|
||||||
// ServiceEndpoint resource=getISClient().getStorageEndpoint(currentScope);
|
|
||||||
// if((getMemoryType() != null) && ((getMemoryType().equals(MemoryType.VOLATILE.toString()) || (getMemoryType().equals(MemoryType.BOTH.toString()))))){
|
|
||||||
// setVolatileHost(isclient.getVolatileHost(resource));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void setServerHosts(String[] newServer, ISClientConnector isclient, ServiceEndpoint resource) {
|
private void setServerHosts(String[] newServer, ISClientConnector isclient, ServiceEndpoint resource) {
|
||||||
if((getMemoryType() != null) && ((getMemoryType().equals(MemoryType.VOLATILE.toString()) || (getMemoryType().equals(MemoryType.BOTH.toString()))))){
|
if((getMemoryType() != null) && ((getMemoryType().equals(MemoryType.VOLATILE.toString()) || (getMemoryType().equals(MemoryType.BOTH.toString()))))){
|
||||||
setVolatileHost(isclient.getVolatileHost(resource));
|
setVolatileHost(isclient.getVolatileHost(resource));
|
||||||
|
@ -224,7 +206,7 @@ public class Configuration {
|
||||||
|
|
||||||
private String getHomeLibraryContext(){
|
private String getHomeLibraryContext(){
|
||||||
String area=null;
|
String area=null;
|
||||||
String scope=ScopeProvider.instance.get();
|
String scope= SecretManagerProvider.instance.get().getContext();
|
||||||
String context=null;
|
String context=null;
|
||||||
if (scope.startsWith("/gcube"))
|
if (scope.startsWith("/gcube"))
|
||||||
context= HL_CONTEXT_DEV;
|
context= HL_CONTEXT_DEV;
|
||||||
|
@ -242,18 +224,18 @@ public class Configuration {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void getOptionalPropertiesFromRR( String currentScope, ServiceEngine engine) {
|
protected void getOptionalPropertiesFromRR( ServiceEngine engine) {
|
||||||
String write=null;
|
String write=null;
|
||||||
String read=null;
|
String read=null;
|
||||||
String [] dbNames=null;
|
String [] dbNames=null;
|
||||||
String dbString=null;
|
String dbString=null;
|
||||||
// check optional properties only if it is not a volatile storage instance
|
// check optional properties only if it is not a volatile storage instance
|
||||||
if((getMemoryType() != null) && (!(getMemoryType().equals(MemoryType.VOLATILE.toString())))){
|
if((getMemoryType() != null) && (!(getMemoryType().equals(MemoryType.VOLATILE.toString())))){
|
||||||
write=getISClient(getBackendType()).retrievePropertyValue(WRITE_CONCERN_PROPERTY_NAME, currentScope);
|
write=getISClient(getBackendType()).retrievePropertyValue(WRITE_CONCERN_PROPERTY_NAME);
|
||||||
logger.debug("read preference: read from service endpoint");
|
logger.debug("read preference: read from service endpoint");
|
||||||
read=getISClient(getBackendType()).retrievePropertyValue(READ_PREFERENCE_PROPERTY_NAME, currentScope);
|
read=getISClient(getBackendType()).retrievePropertyValue(READ_PREFERENCE_PROPERTY_NAME);
|
||||||
logger.debug(" write preference: read from service endpoint");
|
logger.debug(" write preference: read from service endpoint");
|
||||||
dbString=getISClient(getBackendType()).retrievePropertyValue(DB_PROPERTY_NAME, currentScope);
|
dbString=getISClient(getBackendType()).retrievePropertyValue(DB_PROPERTY_NAME);
|
||||||
if((write!=null) && (read!=null)){
|
if((write!=null) && (read!=null)){
|
||||||
engine.setWriteConcern(write);
|
engine.setWriteConcern(write);
|
||||||
engine.setReadConcern(read);
|
engine.setReadConcern(read);
|
||||||
|
@ -272,7 +254,7 @@ public class Configuration {
|
||||||
}
|
}
|
||||||
// added db check also on volatile are
|
// added db check also on volatile are
|
||||||
}else if((getMemoryType().equals(MemoryType.VOLATILE.toString()))){
|
}else if((getMemoryType().equals(MemoryType.VOLATILE.toString()))){
|
||||||
dbString=getISClient(getBackendType()).retrievePropertyValue(DB_PROPERTY_NAME, currentScope);
|
dbString=getISClient(getBackendType()).retrievePropertyValue(DB_PROPERTY_NAME);
|
||||||
if(dbString!=null){
|
if(dbString!=null){
|
||||||
if (dbString.contains(DB_STRING_SEPARATOR)){
|
if (dbString.contains(DB_STRING_SEPARATOR)){
|
||||||
logger.debug("more than one collection read from ServiceEnpoint");
|
logger.debug("more than one collection read from ServiceEnpoint");
|
||||||
|
@ -386,26 +368,26 @@ public class Configuration {
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public String retrieveEncryptionPhrase() throws Exception {
|
public String retrieveEncryptionPhrase() throws Exception {
|
||||||
String currentScope=ScopeProvider.instance.get();
|
String currentScope=SecretManagerProvider.instance.get().getContext();
|
||||||
logger.debug("retrieve encryption prhase on scope: "+currentScope);
|
logger.debug("retrieve encryption prhase on scope: "+currentScope);
|
||||||
String encryptedKey=null;
|
String encryptedKey=null;
|
||||||
// ISClientConnector isclient=getISClient();
|
// ISClientConnector isclient=getISClient();
|
||||||
logger.info("retrieve encryption phrase from scope "+currentScope);
|
logger.info("retrieve encryption phrase from scope "+currentScope);
|
||||||
encryptedKey=getISClient(getBackendType()).retrievePropertyValue("PassPhrase", currentScope);
|
encryptedKey=getISClient(getBackendType()).retrievePropertyValue("PassPhrase");
|
||||||
logger.info("encrypted prhase is "+encryptedKey);
|
logger.info("encrypted prhase is "+encryptedKey);
|
||||||
String decryptString=org.gcube.common.encryption.StringEncrypter.getEncrypter().decrypt(encryptedKey);
|
String decryptString=org.gcube.common.encryption.encrypter.StringEncrypter.getEncrypter().decrypt(encryptedKey);
|
||||||
return decryptString;
|
return decryptString;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String retrieveEncryptionField(String fieldName) throws Exception {
|
public String retrieveEncryptionField(String fieldName) throws Exception {
|
||||||
String currentScope=ScopeProvider.instance.get();
|
String currentScope=SecretManagerProvider.instance.get().getContext();
|
||||||
logger.debug("retrieve encryption prhase on scope: "+currentScope);
|
logger.debug("retrieve encryption prhase on scope: "+currentScope);
|
||||||
String encryptedKey=null;
|
String encryptedKey=null;
|
||||||
// ISClientConnector isclient=getISClient();
|
// ISClientConnector isclient=getISClient();
|
||||||
logger.info("retrieve encryption phrase from scope "+currentScope);
|
logger.info("retrieve encryption phrase from scope "+currentScope);
|
||||||
encryptedKey=getISClient(getBackendType()).retrievePropertyValue(fieldName, currentScope);
|
encryptedKey=getISClient(getBackendType()).retrievePropertyValue(fieldName);
|
||||||
logger.info("encrypted prhase is "+encryptedKey);
|
logger.info("encrypted prhase is "+encryptedKey);
|
||||||
String decryptString=(!Objects.isNull(encryptedKey))?org.gcube.common.encryption.StringEncrypter.getEncrypter().decrypt(encryptedKey):null;
|
String decryptString=(!Objects.isNull(encryptedKey))?org.gcube.common.encryption.encrypter.StringEncrypter.getEncrypter().decrypt(encryptedKey):null;
|
||||||
return decryptString;
|
return decryptString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,12 +10,13 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.gcube.common.encryption.StringEncrypter;
|
import org.gcube.common.encryption.encrypter.StringEncrypter;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
||||||
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
import org.gcube.contentmanager.storageclient.wrapper.BackendType;
|
import org.gcube.contentmanager.storageclient.wrapper.BackendType;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
|
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
|
||||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -67,31 +68,21 @@ public class ISClientConnector {
|
||||||
return resources;
|
return resources;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServiceEndpoint getStorageEndpoint(String scope) {
|
public ServiceEndpoint getStorageEndpoint() {
|
||||||
//if the serviceEndpoint has been already discovered and selected, I'm going to use that
|
//if the serviceEndpoint has been already discovered and selected, I'm going to use that
|
||||||
// otherwise I'm going to discovered it from IS
|
// otherwise I'm going to discovered it from IS
|
||||||
if(getStorageResource() == null){
|
if(getStorageResource() == null){
|
||||||
logger.debug("discovering service endpoint");
|
logger.debug("discovering service endpoint");
|
||||||
String savedScope=null;
|
|
||||||
if(scope!=null){
|
|
||||||
savedScope=ScopeProvider.instance.get();
|
|
||||||
logger.debug("set scopeProvider to scope "+scope+" scope provider scope is "+savedScope);
|
|
||||||
ScopeProvider.instance.set(scope);
|
|
||||||
}
|
|
||||||
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
||||||
query.addCondition("$resource/Profile/Category/text() eq '"+CATEGORY+"' and $resource/Profile/Name eq '"+NAME+"' ");
|
query.addCondition("$resource/Profile/Category/text() eq '"+CATEGORY+"' and $resource/Profile/Name eq '"+NAME+"' ");
|
||||||
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
||||||
List<ServiceEndpoint> resources = client.submit(query);
|
List<ServiceEndpoint> resources = client.submit(query);
|
||||||
if(scope!=null){
|
|
||||||
logger.debug("reset scopeProvider to scope "+scope);
|
|
||||||
ScopeProvider.instance.set(savedScope);
|
|
||||||
}
|
|
||||||
if (resources.size()>0){
|
if (resources.size()>0){
|
||||||
ServiceEndpoint storageResource = getPriorityResource(resources);
|
ServiceEndpoint storageResource = getPriorityResource(resources);
|
||||||
setStorageResource(storageResource);
|
setStorageResource(storageResource);
|
||||||
return storageResource;
|
return storageResource;
|
||||||
}else
|
}else
|
||||||
throw new RuntimeException("Storage ServiceEndpoint not found under scope: "+scope);
|
throw new RuntimeException("Storage ServiceEndpoint not found under scope: "+SecretManagerProvider.instance.get().getContext());
|
||||||
}else{
|
}else{
|
||||||
logger.debug("service endpoint already discovered");
|
logger.debug("service endpoint already discovered");
|
||||||
return getStorageResource();
|
return getStorageResource();
|
||||||
|
@ -207,8 +198,8 @@ public class ISClientConnector {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String retrievePropertyValue(String name, String scope) {
|
public String retrievePropertyValue(String name) {
|
||||||
ServiceEndpoint res = getStorageEndpoint(scope);
|
ServiceEndpoint res = getStorageEndpoint();
|
||||||
Iterator<AccessPoint> it= res.profile().accessPoints().iterator();
|
Iterator<AccessPoint> it= res.profile().accessPoints().iterator();
|
||||||
String value=null;
|
String value=null;
|
||||||
while(it.hasNext()){
|
while(it.hasNext()){
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
package org.gcube.contentmanager.storageclient.wrapper;
|
package org.gcube.contentmanager.storageclient.wrapper;
|
||||||
|
|
||||||
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
import org.gcube.contentmanager.storageclient.wrapper.BackendType;
|
import org.gcube.contentmanager.storageclient.wrapper.BackendType;
|
||||||
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
|
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
|
||||||
//import org.gcube.contentmanagement.blobstorage.resource.MemoryType;
|
//import org.gcube.contentmanagement.blobstorage.resource.MemoryType;
|
||||||
import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
|
import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
|
||||||
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
||||||
import org.gcube.contentmanagement.blobstorage.service.impl.ServiceEngine;
|
import org.gcube.contentmanagement.blobstorage.service.impl.ServiceEngine;
|
||||||
import org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants;
|
import org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants;
|
||||||
|
@ -41,53 +40,20 @@ public class StorageClient {
|
||||||
private static final String DEFAULT_SERVICE_NAME="Default";
|
private static final String DEFAULT_SERVICE_NAME="Default";
|
||||||
private static final MemoryType DEFAULT_MEMORY_TYPE=MemoryType.PERSISTENT;
|
private static final MemoryType DEFAULT_MEMORY_TYPE=MemoryType.PERSISTENT;
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor without optional argument created for gcube infrastructure internal use
|
|
||||||
* @param ServiceClass
|
|
||||||
* @param ServiceName
|
|
||||||
* @param owner
|
|
||||||
* @param typeAccess
|
|
||||||
* @param scope scope identifier
|
|
||||||
* @param forceScope if true the scope used is the scope specified in scope parameter, else the scope specified in the parameter scope is used only for discovering the RuntimeResource
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public StorageClient(String serviceClass, String serviceName, String owner, AccessType accessType, String scope, boolean forceScope){
|
|
||||||
checkScopeProvider();
|
|
||||||
if(forceScope){
|
|
||||||
this.currentScope=ScopeProvider.instance.get();
|
|
||||||
ScopeProvider.instance.set(scope);
|
|
||||||
this.scopeString=ScopeProvider.instance.get();
|
|
||||||
}else{
|
|
||||||
this.RRScope=scope;
|
|
||||||
this.scopeString=ScopeProvider.instance.get();
|
|
||||||
}
|
|
||||||
String id=owner;
|
|
||||||
this.owner=owner;
|
|
||||||
if(accessType!=null)
|
|
||||||
this.typeAccess=accessType;
|
|
||||||
else throw new RuntimeException("AccessType parameter must be not null");
|
|
||||||
this.memoryType=MemoryType.BOTH;
|
|
||||||
this.serviceClass=serviceClass;
|
|
||||||
this.serviceName=serviceName;
|
|
||||||
setClientId(serviceClass, serviceName, id);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor without optional argument created for gcube infrastructure internal use
|
* Constructor without optional argument created for gcube infrastructure internal use
|
||||||
* @param ServiceClass
|
* @param serviceClass
|
||||||
* @param ServiceName
|
* @param serviceName
|
||||||
* @param owner
|
* @param owner
|
||||||
* @param typeAccess
|
* @param accessType
|
||||||
* @param scope
|
|
||||||
*/
|
*/
|
||||||
public StorageClient(String serviceClass, String serviceName, String owner, AccessType accessType){
|
public StorageClient(String serviceClass, String serviceName, String owner, AccessType accessType){
|
||||||
checkScopeProvider();
|
|
||||||
String id=owner;
|
String id=owner;
|
||||||
this.owner=owner;
|
this.owner=owner;
|
||||||
this.scopeString=ScopeProvider.instance.get();
|
this.scopeString=SecretManagerProvider.instance.get().getContext();
|
||||||
if(accessType!=null)
|
if(accessType!=null)
|
||||||
this.typeAccess=accessType;
|
this.typeAccess=accessType;
|
||||||
else throw new RuntimeException("AccessType parameter must be not null");
|
else throw new RuntimeException("AccessType parameter must be not null");
|
||||||
|
@ -103,17 +69,15 @@ public class StorageClient {
|
||||||
* New constructor with another optional argument created for gcube infrastructure internal use.
|
* New constructor with another optional argument created for gcube infrastructure internal use.
|
||||||
* Available in v1.6.0
|
* Available in v1.6.0
|
||||||
* It's possible to specify a specific backend.
|
* It's possible to specify a specific backend.
|
||||||
* @param ServiceClass
|
* @param serviceClass
|
||||||
* @param ServiceName
|
* @param serviceName
|
||||||
* @param owner
|
* @param owner
|
||||||
* @param typeAccess
|
* @param accessType
|
||||||
* @param scope
|
|
||||||
*/
|
*/
|
||||||
public StorageClient(String serviceClass, String serviceName, String owner, AccessType accessType, BackendType backend){
|
public StorageClient(String serviceClass, String serviceName, String owner, AccessType accessType, BackendType backend){;
|
||||||
checkScopeProvider();
|
|
||||||
String id=owner;
|
String id=owner;
|
||||||
this.owner=owner;
|
this.owner=owner;
|
||||||
this.scopeString=ScopeProvider.instance.get();
|
this.scopeString=SecretManagerProvider.instance.get().getContext();
|
||||||
if(accessType!=null)
|
if(accessType!=null)
|
||||||
this.typeAccess=accessType;
|
this.typeAccess=accessType;
|
||||||
else throw new RuntimeException("AccessType parameter must be not null");
|
else throw new RuntimeException("AccessType parameter must be not null");
|
||||||
|
@ -130,15 +94,13 @@ public class StorageClient {
|
||||||
/**
|
/**
|
||||||
* Constructor created for external use
|
* Constructor created for external use
|
||||||
* @param owner
|
* @param owner
|
||||||
* @param typeAccess
|
* @param accessType
|
||||||
* @param memory defines the kind of memory: VOLATILE or PERSISTENT
|
* @param memory defines the kind of memory: VOLATILE or PERSISTENT
|
||||||
* @param scope
|
|
||||||
*/
|
*/
|
||||||
public StorageClient(String owner, AccessType accessType, MemoryType memory){
|
public StorageClient(String owner, AccessType accessType, MemoryType memory){
|
||||||
checkScopeProvider();
|
|
||||||
String id=owner;
|
String id=owner;
|
||||||
this.owner=owner;
|
this.owner=owner;
|
||||||
this.scopeString=ScopeProvider.instance.get();
|
this.scopeString=SecretManagerProvider.instance.get().getContext();
|
||||||
if(accessType!=null)
|
if(accessType!=null)
|
||||||
this.typeAccess=accessType;
|
this.typeAccess=accessType;
|
||||||
else throw new RuntimeException("AccessType parameter must be not null");
|
else throw new RuntimeException("AccessType parameter must be not null");
|
||||||
|
@ -153,18 +115,16 @@ public class StorageClient {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor with optional argument server
|
* Constructor with optional argument server
|
||||||
* @param ServiceClass
|
* @param serviceClass
|
||||||
* @param ServiceName
|
* @param serviceName
|
||||||
* @param owner
|
* @param owner
|
||||||
* @param typeAccess
|
* @param accessType
|
||||||
* @param scope
|
|
||||||
* @param server: define the mongoDBserver
|
* @param server: define the mongoDBserver
|
||||||
*/
|
*/
|
||||||
public StorageClient(String serviceClass, String serviceName, String owner, String server, AccessType accessType){
|
public StorageClient(String serviceClass, String serviceName, String owner, String server, AccessType accessType){
|
||||||
checkScopeProvider();
|
|
||||||
String id=owner;
|
String id=owner;
|
||||||
this.owner=owner;
|
this.owner=owner;
|
||||||
this.scopeString=ScopeProvider.instance.get();
|
this.scopeString=SecretManagerProvider.instance.get().getContext();
|
||||||
if(accessType!=null)
|
if(accessType!=null)
|
||||||
this.typeAccess=accessType;
|
this.typeAccess=accessType;
|
||||||
else throw new RuntimeException("AccessType parameter must be not null");
|
else throw new RuntimeException("AccessType parameter must be not null");
|
||||||
|
@ -179,18 +139,16 @@ public class StorageClient {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor with optional argument memoryType
|
* Constructor with optional argument memoryType
|
||||||
* @param ServiceClass
|
* @param serviceClass
|
||||||
* @param ServiceName
|
* @param serviceName
|
||||||
* @param owner
|
* @param owner
|
||||||
* @param typeAccess
|
* @param accessType
|
||||||
* @param memory defines the kind of memory: VOLATILE or PERSISTENT
|
* @param memory defines the kind of memory: VOLATILE or PERSISTENT
|
||||||
* @param scope
|
|
||||||
*/
|
*/
|
||||||
public StorageClient(String serviceClass, String serviceName, String owner, AccessType accessType, MemoryType memory){
|
public StorageClient(String serviceClass, String serviceName, String owner, AccessType accessType, MemoryType memory){
|
||||||
checkScopeProvider();
|
|
||||||
String id=owner;
|
String id=owner;
|
||||||
this.owner=owner;
|
this.owner=owner;
|
||||||
this.scopeString=ScopeProvider.instance.get();
|
this.scopeString=SecretManagerProvider.instance.get().getContext();
|
||||||
if(accessType!=null)
|
if(accessType!=null)
|
||||||
this.typeAccess=accessType;
|
this.typeAccess=accessType;
|
||||||
else throw new RuntimeException("AccessType parameter must be not null");
|
else throw new RuntimeException("AccessType parameter must be not null");
|
||||||
|
@ -206,19 +164,17 @@ public class StorageClient {
|
||||||
/**
|
/**
|
||||||
* Available in v1.6.0
|
* Available in v1.6.0
|
||||||
* It's possible to specify a specific backend.
|
* It's possible to specify a specific backend.
|
||||||
* @param ServiceClass
|
* @param serviceClass
|
||||||
* @param ServiceName
|
* @param serviceName
|
||||||
* @param owner
|
* @param owner
|
||||||
* @param typeAccess
|
* @param accessType
|
||||||
* @param backend: specify mongodb (default) or s3
|
* @param backend: specify mongodb (default) or s3
|
||||||
* @param memory defines the kind of memory: VOLATILE or PERSISTENT
|
* @param memory defines the kind of memory: VOLATILE or PERSISTENT
|
||||||
* @param scope
|
|
||||||
*/
|
*/
|
||||||
public StorageClient(String serviceClass, String serviceName, String owner, AccessType accessType, MemoryType memory, BackendType backend){
|
public StorageClient(String serviceClass, String serviceName, String owner, AccessType accessType, MemoryType memory, BackendType backend){
|
||||||
checkScopeProvider();
|
|
||||||
String id=owner;
|
String id=owner;
|
||||||
this.owner=owner;
|
this.owner=owner;
|
||||||
this.scopeString=ScopeProvider.instance.get();
|
this.scopeString=SecretManagerProvider.instance.get().getContext();
|
||||||
if(accessType!=null)
|
if(accessType!=null)
|
||||||
this.typeAccess=accessType;
|
this.typeAccess=accessType;
|
||||||
else throw new RuntimeException("AccessType parameter must be not null");
|
else throw new RuntimeException("AccessType parameter must be not null");
|
||||||
|
@ -235,19 +191,17 @@ public class StorageClient {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor with optional arguments server and memory
|
* Constructor with optional arguments server and memory
|
||||||
* @param ServiceClass
|
* @param serviceClass
|
||||||
* @param ServiceName
|
* @param serviceName
|
||||||
* @param owner
|
* @param owner
|
||||||
* @param typeAccess
|
* @param accessType
|
||||||
* @param memory defines the kind of memory: VOLATILE or PERSISTENT
|
* @param memory defines the kind of memory: VOLATILE or PERSISTENT
|
||||||
* @param server: define the mongoDBserver
|
* @param server: define the mongoDBserver
|
||||||
* @param scope
|
|
||||||
*/
|
*/
|
||||||
public StorageClient(String serviceClass, String serviceName, String owner, AccessType accessType, MemoryType memory, String server){
|
public StorageClient(String serviceClass, String serviceName, String owner, AccessType accessType, MemoryType memory, String server){
|
||||||
checkScopeProvider();
|
|
||||||
String id=owner;
|
String id=owner;
|
||||||
this.owner=owner;
|
this.owner=owner;
|
||||||
this.scopeString=ScopeProvider.instance.get();
|
this.scopeString=SecretManagerProvider.instance.get().getContext();
|
||||||
if(accessType!=null)
|
if(accessType!=null)
|
||||||
this.typeAccess=accessType;
|
this.typeAccess=accessType;
|
||||||
else throw new RuntimeException("AccessType parameter must be not null");
|
else throw new RuntimeException("AccessType parameter must be not null");
|
||||||
|
@ -289,11 +243,13 @@ public class StorageClient {
|
||||||
}
|
}
|
||||||
if(getMemoryType() !=null)
|
if(getMemoryType() !=null)
|
||||||
engine.setGcubeMemoryType(getMemoryType().toString());
|
engine.setGcubeMemoryType(getMemoryType().toString());
|
||||||
engine.setGcubeScope(ScopeProvider.instance.get());
|
engine.setGcubeScope(SecretManagerProvider.instance.get().getContext());
|
||||||
engine.setOwnerGcube(owner);
|
engine.setOwnerGcube(owner);
|
||||||
cfg.getOptionalPropertiesFromRR( getCurrentScope(), engine);
|
cfg.getOptionalPropertiesFromRR(engine);
|
||||||
if(getCurrentScope()!=null)
|
if(getCurrentScope()!=null){
|
||||||
ScopeProvider.instance.set(getCurrentScope());
|
if(!getCurrentScope().equals(SecretManagerProvider.instance.get().getContext()))
|
||||||
|
logger.warn("scope force to "+getCurrentScope()+"doesn't take effect. The current scope is set to"+SecretManagerProvider.instance.get().getContext());
|
||||||
|
}
|
||||||
return engine;
|
return engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,23 +267,6 @@ public class StorageClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* if the scope provider is not set then check if the env variable: SCOPE is set and set the scopeProvider
|
|
||||||
*/
|
|
||||||
private void checkScopeProvider(){
|
|
||||||
String scopeProvided=ScopeProvider.instance.get();
|
|
||||||
if (scopeProvided==null){
|
|
||||||
scopeProvided=Utils.checkVarEnv("SCOPE");
|
|
||||||
if (scopeProvided != null){
|
|
||||||
ScopeProvider.instance.set(scopeProvided);
|
|
||||||
}else{
|
|
||||||
throw new RuntimeException("Scope not set ");
|
|
||||||
}
|
|
||||||
}else setCurrentScope(scopeProvided);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public String getClientID() {
|
public String getClientID() {
|
||||||
return clientID;
|
return clientID;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package org.gcube.contentmanager.storageclient.test;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
||||||
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
||||||
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
|
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
|
||||||
|
@ -37,7 +37,7 @@ public class CopyDirTest {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void getClient() throws RemoteBackendException{
|
public static void getClient() throws RemoteBackendException{
|
||||||
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
|
SecretManagerProvider.instance.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,19 @@
|
||||||
package org.gcube.contentmanager.storageclient.test;
|
package org.gcube.contentmanager.storageclient.test;
|
||||||
|
|
||||||
|
import static org.gcube.contentmanager.storageclient.test.utils.Costants.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
|
||||||
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
|
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
|
||||||
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
||||||
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
||||||
import org.gcube.contentmanager.storageclient.test.utils.Costants;
|
import org.gcube.contentmanager.storageclient.test.utils.Costants;
|
||||||
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
|
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
|
||||||
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
|
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -38,10 +39,9 @@ public class CopyTest {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void getClient() throws RemoteBackendException{
|
public void getClient() throws RemoteBackendException{
|
||||||
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
|
SecretManagerProvider.instance.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, DEFAULT_MEMORY_TYPE).getClient();
|
||||||
assertNotNull(client);
|
assertNotNull(client);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
package org.gcube.contentmanager.storageclient.test;
|
package org.gcube.contentmanager.storageclient.test;
|
||||||
|
|
||||||
|
import static org.gcube.contentmanager.storageclient.test.utils.Costants.DEFAULT_SCOPE_STRING;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
||||||
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
||||||
import org.gcube.contentmanager.storageclient.test.utils.Costants;
|
import org.gcube.contentmanager.storageclient.test.utils.Costants;
|
||||||
|
@ -25,7 +26,7 @@ public class CountingTest {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void getClient() throws RemoteBackendException{
|
public void getClient() throws RemoteBackendException{
|
||||||
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
|
SecretManagerProvider.instance.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
|
||||||
try {
|
try {
|
||||||
client=new StorageClient(serviceClass, serviceName, owner, AccessType.PUBLIC, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
client=new StorageClient(serviceClass, serviceName, owner, AccessType.PUBLIC, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
||||||
assertNotNull(client);
|
assertNotNull(client);
|
||||||
|
|
|
@ -9,7 +9,7 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.bson.types.ObjectId;
|
import org.bson.types.ObjectId;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
|
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
|
||||||
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
||||||
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
||||||
|
@ -42,7 +42,7 @@ public class DownloadsTest {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void getClient() throws RemoteBackendException{
|
public static void getClient() throws RemoteBackendException{
|
||||||
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
|
SecretManagerProvider.instance.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
|
||||||
// ScopeProvider.instance.set(scope);
|
// ScopeProvider.instance.set(scope);
|
||||||
try {
|
try {
|
||||||
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE, Costants.BACKEND_TYPE).getClient();
|
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE, Costants.BACKEND_TYPE).getClient();
|
||||||
|
|
|
@ -9,7 +9,7 @@ import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
|
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
|
||||||
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
||||||
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
||||||
|
@ -43,7 +43,7 @@ public class DuplicateTest {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void getClient() throws RemoteBackendException{
|
public void getClient() throws RemoteBackendException{
|
||||||
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
|
SecretManagerProvider.instance.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
||||||
|
|
|
@ -3,7 +3,8 @@ package org.gcube.contentmanager.storageclient.test;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
|
||||||
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
|
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
|
||||||
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
||||||
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
||||||
|
@ -36,7 +37,7 @@ public class ForceCloseTest {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void getClient(){
|
public void getClient(){
|
||||||
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
|
SecretManagerProvider.instance.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
|
||||||
try {
|
try {
|
||||||
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
||||||
assertNotNull(client);
|
assertNotNull(client);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.gcube.contentmanager.storageclient.test;
|
package org.gcube.contentmanager.storageclient.test;
|
||||||
|
|
||||||
|
import static org.gcube.contentmanager.storageclient.test.utils.Costants.DEFAULT_SCOPE_STRING;
|
||||||
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.gcube.resources.discovery.icclient.ICFactory.*;
|
import static org.gcube.resources.discovery.icclient.ICFactory.*;
|
||||||
|
@ -8,7 +9,8 @@ import java.util.List;
|
||||||
import org.gcube.common.resources.gcore.GenericResource;
|
import org.gcube.common.resources.gcore.GenericResource;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
|
||||||
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
import org.gcube.contentmanager.storageclient.test.utils.Costants;
|
import org.gcube.contentmanager.storageclient.test.utils.Costants;
|
||||||
import org.gcube.contentmanager.storageclient.wrapper.ISClientConnector;
|
import org.gcube.contentmanager.storageclient.wrapper.ISClientConnector;
|
||||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||||
|
@ -22,11 +24,10 @@ import org.w3c.dom.NodeList;
|
||||||
|
|
||||||
public class FwsQueryTest {
|
public class FwsQueryTest {
|
||||||
|
|
||||||
String scope=Costants.DEFAULT_SCOPE_STRING;//"/gcube/devsec";
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setscope(){
|
public void setscope(){
|
||||||
ScopeProvider.instance.set(scope);
|
SecretManagerProvider.instance.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
// @Test
|
||||||
|
@ -93,7 +94,7 @@ public class FwsQueryTest {
|
||||||
public void getRR() throws Exception{
|
public void getRR() throws Exception{
|
||||||
System.out.println("retrieve server from RuntimeResource");
|
System.out.println("retrieve server from RuntimeResource");
|
||||||
ISClientConnector isConnector= new ISClientConnector();
|
ISClientConnector isConnector= new ISClientConnector();
|
||||||
ServiceEndpoint resource = isConnector.getStorageEndpoint(scope);
|
ServiceEndpoint resource = isConnector.getStorageEndpoint();
|
||||||
assertNotNull(resource);
|
assertNotNull(resource);
|
||||||
String[] server=isConnector.retrieveConnectionInfo(resource);
|
String[] server=isConnector.retrieveConnectionInfo(resource);
|
||||||
for(int j=0; j<server.length; j++){
|
for(int j=0; j<server.length; j++){
|
||||||
|
|
|
@ -5,7 +5,7 @@ import static org.junit.Assert.*;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
import org.gcube.contentmanagement.blobstorage.resource.RequestObject;
|
import org.gcube.contentmanagement.blobstorage.resource.RequestObject;
|
||||||
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
|
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
|
||||||
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
||||||
|
@ -36,7 +36,7 @@ public class GetMetaFileTest {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void getClient() throws RemoteBackendException{
|
public static void getClient() throws RemoteBackendException{
|
||||||
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
|
SecretManagerProvider.instance.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
|
||||||
try {
|
try {
|
||||||
client=new StorageClient(serviceClass, serviceName, owner, AccessType.PUBLIC, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
client=new StorageClient(serviceClass, serviceName, owner, AccessType.PUBLIC, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
||||||
assertNotNull(client);
|
assertNotNull(client);
|
||||||
|
|
|
@ -8,7 +8,7 @@ import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
import org.gcube.contentmanager.storageclient.test.utils.Costants;
|
import org.gcube.contentmanager.storageclient.test.utils.Costants;
|
||||||
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
|
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
|
||||||
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
|
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
|
||||||
|
@ -37,10 +37,10 @@ public class HLcheckTest {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void getClient() throws RemoteBackendException{
|
public void getClient() throws RemoteBackendException{
|
||||||
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
|
SecretManagerProvider.instance.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
|
||||||
// ScopeProvider.instance.set(scope);
|
// ScopeProvider.instance.set(scope);
|
||||||
try {
|
try {
|
||||||
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_SCOPE_STRING, false).getClient();
|
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED).getClient();
|
||||||
assertNotNull(client);
|
assertNotNull(client);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
package org.gcube.contentmanager.storageclient.test;
|
||||||
|
|
||||||
|
import org.gcube.common.security.Owner;
|
||||||
|
import org.gcube.common.security.secrets.Secret;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class ICSecret extends Secret{
|
||||||
|
|
||||||
|
private String context;
|
||||||
|
|
||||||
|
protected ICSecret(String context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Owner getOwner() {
|
||||||
|
return new Owner("guest", Collections.emptyList(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getContext() {
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> getHTTPAuthorizationHeaders() {
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isExpired() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -5,7 +5,7 @@ import static org.junit.Assert.*;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
|
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
|
||||||
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
||||||
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
||||||
|
@ -32,7 +32,7 @@ public class LinkTest {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void getClient() throws RemoteBackendException{
|
public void getClient() throws RemoteBackendException{
|
||||||
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
|
SecretManagerProvider.instance.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.gcube.contentmanager.storageclient.test;
|
package org.gcube.contentmanager.storageclient.test;
|
||||||
|
|
||||||
|
import static org.gcube.contentmanager.storageclient.test.utils.Costants.DEFAULT_SCOPE_STRING;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
@ -7,7 +8,7 @@ import static org.junit.Assert.assertTrue;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
|
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
|
||||||
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
||||||
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
||||||
|
@ -37,7 +38,7 @@ public class LockTest {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void getClient(){
|
public void getClient(){
|
||||||
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
|
SecretManagerProvider.instance.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
|
||||||
try {
|
try {
|
||||||
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
||||||
assertNotNull(client);
|
assertNotNull(client);
|
||||||
|
|
|
@ -4,7 +4,8 @@ import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
|
||||||
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
||||||
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
||||||
import org.gcube.contentmanager.storageclient.test.utils.Costants;
|
import org.gcube.contentmanager.storageclient.test.utils.Costants;
|
||||||
|
@ -33,7 +34,7 @@ public class MoveDirTest {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void getClient() throws RemoteBackendException{
|
public static void getClient() throws RemoteBackendException{
|
||||||
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
|
SecretManagerProvider.instance.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
||||||
|
|
|
@ -3,7 +3,8 @@ package org.gcube.contentmanager.storageclient.test;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
|
||||||
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
||||||
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
||||||
import org.gcube.contentmanager.storageclient.test.utils.Costants;
|
import org.gcube.contentmanager.storageclient.test.utils.Costants;
|
||||||
|
@ -29,7 +30,7 @@ public class MoveTest {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void getClient() throws RemoteBackendException{
|
public void getClient() throws RemoteBackendException{
|
||||||
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
|
SecretManagerProvider.instance.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
package org.gcube.contentmanager.storageclient.test;
|
package org.gcube.contentmanager.storageclient.test;
|
||||||
|
|
||||||
|
import static org.gcube.contentmanager.storageclient.test.utils.Costants.DEFAULT_SCOPE_STRING;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
import org.gcube.contentmanagement.blobstorage.resource.RequestObject;
|
import org.gcube.contentmanagement.blobstorage.resource.RequestObject;
|
||||||
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
|
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
|
||||||
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
||||||
|
@ -34,7 +35,7 @@ public class PropertiesTest {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void getClient() throws RemoteBackendException{
|
public static void getClient() throws RemoteBackendException{
|
||||||
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
|
SecretManagerProvider.instance.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
|
||||||
try {
|
try {
|
||||||
client=new StorageClient(serviceClass, serviceName, owner, AccessType.PUBLIC, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
client=new StorageClient(serviceClass, serviceName, owner, AccessType.PUBLIC, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
||||||
assertNotNull(client);
|
assertNotNull(client);
|
||||||
|
|
|
@ -5,7 +5,7 @@ import static org.junit.Assert.*;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
|
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
|
||||||
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
||||||
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
||||||
|
@ -33,7 +33,7 @@ public class RemoveTest {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void getClient() throws RemoteBackendException{
|
public void getClient() throws RemoteBackendException{
|
||||||
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
|
SecretManagerProvider.instance.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
|
||||||
try {
|
try {
|
||||||
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
||||||
assertNotNull(client);
|
assertNotNull(client);
|
||||||
|
|
|
@ -7,7 +7,7 @@ import static org.junit.Assert.*;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
|
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
|
||||||
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
||||||
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
||||||
|
@ -33,8 +33,7 @@ public class RemoveVolatileArea {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void getClient() throws RemoteBackendException{
|
public void getClient() throws RemoteBackendException{
|
||||||
// ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
|
SecretManagerProvider.instance.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
|
||||||
ScopeProvider.instance.set(scope);
|
|
||||||
try {
|
try {
|
||||||
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
||||||
assertNotNull(client);
|
assertNotNull(client);
|
||||||
|
|
|
@ -3,12 +3,14 @@
|
||||||
*/
|
*/
|
||||||
package org.gcube.contentmanager.storageclient.test;
|
package org.gcube.contentmanager.storageclient.test;
|
||||||
|
|
||||||
|
import static org.gcube.contentmanager.storageclient.test.utils.Costants.DEFAULT_SCOPE_STRING;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
|
||||||
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
|
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
|
||||||
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
||||||
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
||||||
|
@ -42,7 +44,7 @@ public class ReplaceFileTest {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void getClient(){
|
public void getClient(){
|
||||||
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
|
SecretManagerProvider.instance.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
|
||||||
try {
|
try {
|
||||||
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
||||||
assertNotNull(client);
|
assertNotNull(client);
|
||||||
|
|
|
@ -8,7 +8,7 @@ import static org.junit.Assert.*;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
|
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
|
||||||
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
||||||
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
||||||
|
@ -47,7 +47,7 @@ public class SoftCopyTest {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void getClient() throws RemoteBackendException{
|
public static void getClient() throws RemoteBackendException{
|
||||||
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
|
SecretManagerProvider.instance.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
||||||
|
|
|
@ -10,7 +10,7 @@ import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
|
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
|
||||||
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
||||||
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
||||||
|
@ -39,7 +39,7 @@ public class UploadsTest {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void getClient(){
|
public static void getClient(){
|
||||||
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
|
SecretManagerProvider.instance.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
|
||||||
try {
|
try {
|
||||||
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
||||||
assertNotNull(client);
|
assertNotNull(client);
|
||||||
|
|
|
@ -10,14 +10,12 @@ import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
|
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
|
||||||
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
||||||
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
||||||
import org.gcube.contentmanager.storageclient.model.protocol.smp.Handler;
|
|
||||||
import org.gcube.contentmanager.storageclient.test.utils.Costants;
|
import org.gcube.contentmanager.storageclient.test.utils.Costants;
|
||||||
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
|
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
|
||||||
import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
|
|
||||||
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
|
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -45,7 +43,7 @@ public class UrlResolverByIdTest {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void init() throws RemoteBackendException{
|
public void init() throws RemoteBackendException{
|
||||||
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
|
SecretManagerProvider.instance.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
|
||||||
try {
|
try {
|
||||||
client = new StorageClient(serviceClass, serviceName, owner , AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
client = new StorageClient(serviceClass, serviceName, owner , AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -65,12 +63,6 @@ public class UrlResolverByIdTest {
|
||||||
String url=client.getHttpsUrl(true).RFile(id);
|
String url=client.getHttpsUrl(true).RFile(id);
|
||||||
System.out.println("httpsUrl generated: "+url);
|
System.out.println("httpsUrl generated: "+url);
|
||||||
assertNotNull(url);
|
assertNotNull(url);
|
||||||
// id=client.put(true).LFile(absoluteLocalPath).RFile(remotePath);
|
|
||||||
|
|
||||||
|
|
||||||
// System.out.println("id retrieved: "+id);
|
|
||||||
// client.moveFile().from(remotePath).to(newPath);
|
|
||||||
verifyUrl(url);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -84,7 +76,6 @@ public class UrlResolverByIdTest {
|
||||||
assertNotNull(url);
|
assertNotNull(url);
|
||||||
System.out.println("id retrieved: "+id);
|
System.out.println("id retrieved: "+id);
|
||||||
client.moveFile().from(remotePath).to(newPath);
|
client.moveFile().from(remotePath).to(newPath);
|
||||||
verifyUrl(url);
|
|
||||||
client.moveFile().from(newPath).to(remotePath);
|
client.moveFile().from(newPath).to(remotePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,57 +89,15 @@ public class UrlResolverByIdTest {
|
||||||
System.out.println("id encrypted: "+id);
|
System.out.println("id encrypted: "+id);
|
||||||
client.get().RFileAsInputStream(remotePath);
|
client.get().RFileAsInputStream(remotePath);
|
||||||
client.moveFile().from(remotePath).to(newPath);
|
client.moveFile().from(remotePath).to(newPath);
|
||||||
verifyUrl(url);
|
|
||||||
client.moveFile().from(newPath).to(remotePath);
|
client.moveFile().from(newPath).to(remotePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* download the file and verify if the file exist
|
|
||||||
* @param url
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
private void verifyUrl(String url) {
|
|
||||||
Handler.activateProtocol();
|
|
||||||
URL smsHome = null;
|
|
||||||
try {
|
|
||||||
smsHome = new URL(url);
|
|
||||||
} catch (MalformedURLException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
URLConnection uc = null;
|
|
||||||
File f=null;
|
|
||||||
try {
|
|
||||||
uc = ( URLConnection ) smsHome.openConnection ( );
|
|
||||||
InputStream is=uc.getInputStream();
|
|
||||||
f=new File(localNewPath);
|
|
||||||
FileOutputStream out=new FileOutputStream(f);
|
|
||||||
byte buf[]=new byte[1024];
|
|
||||||
int len=0;
|
|
||||||
System.out.println("InputStream "+is);
|
|
||||||
while((len=is.read(buf))>0){
|
|
||||||
out.write(buf,0,len);
|
|
||||||
}
|
|
||||||
out.close();
|
|
||||||
is.close();
|
|
||||||
}catch(Exception e ){
|
|
||||||
e.printStackTrace();
|
|
||||||
assertTrue(false);
|
|
||||||
}
|
|
||||||
assertTrue(f.exists());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void removeRemoteFile() throws RemoteBackendException{
|
public void removeRemoteFile() throws RemoteBackendException{
|
||||||
String id=client.remove().RFile(remotePath);
|
String id=client.remove().RFile(remotePath);
|
||||||
List<StorageObject> list=client.showDir().RDir("Uritest/img");
|
List<StorageObject> list=client.showDir().RDir("Uritest/img");
|
||||||
assertTrue(list.isEmpty());
|
assertTrue(list.isEmpty());
|
||||||
// String id2=client.remove().RFile(newPath);
|
|
||||||
// List<StorageObject> list2=client.showDir().RDir("Uritest/img5");
|
|
||||||
// assertTrue(list.isEmpty());
|
|
||||||
removeLocalFiles();
|
removeLocalFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,14 @@
|
||||||
package org.gcube.contentmanager.storageclient.test;
|
package org.gcube.contentmanager.storageclient.test;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
|
|
||||||
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
||||||
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
||||||
import org.gcube.contentmanager.storageclient.test.utils.Costants;
|
import org.gcube.contentmanager.storageclient.test.utils.Costants;
|
||||||
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
|
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
|
||||||
import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
|
|
||||||
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
|
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -31,7 +26,7 @@ public class UrlResolverTest {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void init() throws RemoteBackendException{
|
public void init() throws RemoteBackendException{
|
||||||
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
|
SecretManagerProvider.instance.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
|
||||||
try {
|
try {
|
||||||
client = new StorageClient(serviceClass, serviceName, owner , AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
client = new StorageClient(serviceClass, serviceName, owner , AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -43,12 +38,6 @@ public class UrlResolverTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getUrl() throws RemoteBackendException {
|
|
||||||
String url=client.getUrl().RFile(remotePath);
|
|
||||||
System.out.println("url generated: "+url);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getHttpsUrl() throws RemoteBackendException {
|
public void getHttpsUrl() throws RemoteBackendException {
|
||||||
String url=client.getHttpsUrl().RFile(remotePath);
|
String url=client.getHttpsUrl().RFile(remotePath);
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
package org.gcube.contentmanager.storageclient.test;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import org.gcube.common.scope.impl.ServiceMapScannerMediator;
|
|
||||||
import org.gcube.contentmanager.storageclient.test.utils.Costants;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class scopeValidationTest {
|
|
||||||
|
|
||||||
static ServiceMapScannerMediator scanner;
|
|
||||||
// String scope="/gcube";
|
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
public static void init(){
|
|
||||||
scanner=new ServiceMapScannerMediator();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test() {
|
|
||||||
assertTrue(scanner.isValid(Costants.DEFAULT_SCOPE_STRING));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue