Fixed configuration issues

This commit is contained in:
Luca Frosini 2022-02-22 16:49:05 +01:00
parent ef2cb362f3
commit 8b43f00fb2
3 changed files with 27 additions and 12 deletions

View File

@ -520,9 +520,7 @@ public class GCoreISConfigurationProxy {
protected Property addProperty(Group<Property> properties, String name, String value, boolean encrypted) {
Property property = new Property();
property.nameAndValue(name, value);
if(encrypted) {
property.encrypted(encrypted);
}
property.encrypted(encrypted);
properties.add(property);
return property;
}
@ -538,10 +536,25 @@ public class GCoreISConfigurationProxy {
Iterator<String> iterator = jsonNode.fieldNames();
while (iterator.hasNext()) {
String key = iterator.next();
if(key.compareTo(CatalogueConfiguration.ID_KEY)==0) {
continue;
}
if(key.compareTo(CatalogueConfiguration.SYS_ADMIN_TOKEN_KEY)==0) {
addProperty(properties, key, catalogueConfiguration.getEncryptedSysAdminToken(), true);
continue;
}
JsonNode valueJsonNode = jsonNode.get(key);
String value = valueJsonNode.toString();
if(valueJsonNode.isTextual()) {
value = valueJsonNode.asText();
}
addProperty(properties, key, value);
}
return properties;
}

View File

@ -103,7 +103,7 @@ public class ServiceCatalogueConfiguration extends CatalogueConfiguration {
public ObjectNode toObjetcNode(boolean decryptedValues) throws JsonProcessingException {
ObjectNode configuration = mapper.valueToTree(this);
CKANUser ckanUser = CKANUserCache.getCurrrentCKANUser();
if(ckanUser.getRole() != Role.MANAGER) {
if(ckanUser.getRole().ordinal() < Role.MANAGER.ordinal()) {
configuration.remove(ServiceCatalogueConfiguration.SYS_ADMIN_TOKEN_KEY);
configuration.remove(ServiceCatalogueConfiguration.CKAN_DB_KEY);
}else {

View File

@ -8,16 +8,14 @@ import java.util.stream.Collectors;
import org.gcube.common.authorization.utils.manager.SecretManager;
import org.gcube.gcat.ContextTest;
import org.gcube.smartgears.ContextProvider;
import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
import org.gcube.smartgears.configuration.application.DefaultApplicationConfiguration;
import org.gcube.smartgears.context.application.ApplicationContext;
import org.gcube.smartgears.context.application.DefaultApplicationContext;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class GCoreISConfigurationProxyTest extends ContextTest {
private static final Logger logger = LoggerFactory.getLogger(GCoreISConfigurationProxyTest.class);
@ -27,18 +25,20 @@ public class GCoreISConfigurationProxyTest extends ContextTest {
ContextTest.setContextByName("/gcube/devNext/NextNext");
String context = SecretManager.instance.get().getContext();
GCoreISConfigurationProxy gCoreISConfigurationProxy = new GCoreISConfigurationProxy(context);
@SuppressWarnings("deprecation")
Set<String> organizations = gCoreISConfigurationProxy.getSupportedOrganizationsFromGenericResource();
Assert.assertTrue(organizations.size()>0);
}
@Test
public void testCatalogueConfiguration() throws Exception {
ContextTest.setContextByName("/gcube/devNext");
ContextTest.setContextByName("/gcube/devsec/devVRE");
String context = SecretManager.instance.get().getContext();
GCoreISConfigurationProxy gCoreISConfigurationProxy = new GCoreISConfigurationProxy(context);
ServiceCatalogueConfiguration catalogueConfiguration = gCoreISConfigurationProxy.getOLDCatalogueConfigurationFromIS();
ServiceCatalogueConfiguration catalogueConfiguration = gCoreISConfigurationProxy.getCatalogueConfigurationFromIS();
String json = catalogueConfiguration.toJsonString();
logger.info("Configuration in context {} is {}", context, json);
/*
ServiceCatalogueConfiguration secondCatalogueConfiguration = ServiceCatalogueConfiguration.getServiceCatalogueConfiguration(json);
String secondJson = secondCatalogueConfiguration.toJsonString();
logger.info("After marshalling and unmarshalling configuration in context {} is {}", context, secondJson);
@ -48,6 +48,7 @@ public class GCoreISConfigurationProxyTest extends ContextTest {
String thirdJson = thirdCatalogueConfiguration.toJsonString();
logger.info("After marshalling and unmarshalling decrypted configuration in context {} is {}", context, thirdJson);
logger.info("All as JsonArray [{},{},{},{}]", json, secondJson, decryptedJson, thirdJson);
*/
}
// @Test
@ -55,6 +56,7 @@ public class GCoreISConfigurationProxyTest extends ContextTest {
ContextTest.setContextByName("/gcube/devsec/devVRE");
String context = SecretManager.instance.get().getContext();
GCoreISConfigurationProxy gCoreISConfigurationProxy = new GCoreISConfigurationProxy(context);
@SuppressWarnings("deprecation")
ServiceCatalogueConfiguration catalogueConfiguration = gCoreISConfigurationProxy.getOLDCatalogueConfigurationFromIS();
String json = catalogueConfiguration.toJsonString();
logger.debug("Read configuration {}", json);
@ -65,7 +67,7 @@ public class GCoreISConfigurationProxyTest extends ContextTest {
public static String DEVVRE_CONFIG_JSON = "devvre.conf.json";
@Test
//@Test
public void createConfiguration() throws Exception {
ContextTest.setContextByName("/gcube/devsec/devVRE");
String context = SecretManager.instance.get().getContext();