use of com.yahoo.elide.modelconfig.store.models.ConfigFile in project elide by yahoo.
the class DynamicConfigValidator method readSecurityConfig.
/**
* Read and validates security config file.
*/
private ElideSecurityConfig readSecurityConfig(Map<String, ConfigFile> resourceMap) {
return resourceMap.entrySet().stream().filter(entry -> entry.getKey().startsWith(Config.SECURITY.getConfigPath())).map(entry -> {
try {
String content = entry.getValue().getContent();
validateConfigForMissingVariables(content, this.modelVariables);
return DynamicConfigHelpers.stringToElideSecurityPojo(entry.getKey(), content, this.modelVariables, schemaValidator);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}).findAny().orElse(new ElideSecurityConfig());
}
use of com.yahoo.elide.modelconfig.store.models.ConfigFile in project elide by yahoo.
the class ConfigDataStoreTransaction method save.
@Override
public <T> void save(T entity, RequestScope scope) {
ConfigFile file = (ConfigFile) entity;
boolean canWrite;
if (scope.isNewResource(file)) {
canWrite = canCreate(file.getPath());
} else {
canWrite = canModify(file.getPath());
}
if (readOnly || !canWrite) {
log.error("Attempt to modify a read only configuration");
throw new UnsupportedOperationException("Configuration is read only.");
}
dirty.add(file);
todo.add(() -> updateFile(file.getPath(), file.getContent()));
}
use of com.yahoo.elide.modelconfig.store.models.ConfigFile in project elide by yahoo.
the class ConfigDataStoreTransaction method delete.
@Override
public <T> void delete(T entity, RequestScope scope) {
ConfigFile file = (ConfigFile) entity;
if (readOnly || !canModify(file.getPath())) {
log.error("Attempt to modify a read only configuration");
throw new UnsupportedOperationException("Configuration is read only.");
}
dirty.add(file);
deleted.add(file.getPath());
todo.add(() -> deleteFile(file.getPath()));
}
use of com.yahoo.elide.modelconfig.store.models.ConfigFile in project elide by yahoo.
the class ConfigDataStoreTest method testCreate.
@Test
public void testCreate(@TempDir Path configPath) {
String configRoot = configPath.toFile().getPath();
Validator validator = new DynamicConfigValidator(DefaultClassScanner.getInstance(), configRoot);
ConfigDataStore store = new ConfigDataStore(configRoot, validator);
ConfigFile newFile = createFile("test", store, false);
ConfigDataStoreTransaction readTx = store.beginReadTransaction();
RequestScope scope = mock(RequestScope.class);
ConfigFile loaded = readTx.loadObject(EntityProjection.builder().type(ClassType.of(ConfigFile.class)).build(), toId("models/tables/test.hjson", NO_VERSION), scope);
assertTrue(compare(newFile, loaded));
}
use of com.yahoo.elide.modelconfig.store.models.ConfigFile in project elide by yahoo.
the class ConfigDataStoreTest method testDeleteWithPermissionError.
@Test
public void testDeleteWithPermissionError(@TempDir Path configPath) {
String configRoot = configPath.toFile().getPath();
Validator validator = new DynamicConfigValidator(DefaultClassScanner.getInstance(), configRoot);
ConfigDataStore store = new ConfigDataStore(configRoot, validator);
ConfigFile createdFile = createFile("test", store, false);
String createdFilePath = Path.of(configPath.toFile().getPath(), createdFile.getPath()).toFile().getPath();
File file = new File(createdFilePath);
boolean blockFailed = blockWrites(file);
if (blockFailed) {
// We can't actually test because setting permissions isn't working.
return;
}
ConfigDataStoreTransaction tx = store.beginTransaction();
RequestScope scope = mock(RequestScope.class);
assertThrows(UnsupportedOperationException.class, () -> tx.delete(createdFile, scope));
}
Aggregations