Search in sources :

Example 1 with ConfigFile

use of com.yahoo.elide.modelconfig.store.models.ConfigFile in project elide by yahoo.

the class FileLoader method loadResources.

/**
 * Load resources from the filesystem/classpath.
 * @return A map from the path to the resource.
 * @throws IOException If something goes boom.
 */
public Map<String, ConfigFile> loadResources() throws IOException {
    Map<String, ConfigFile> resourceMap = new LinkedHashMap<>();
    int configDirURILength = resolver.getResources(this.rootURL)[0].getURI().toString().length();
    Resource[] hjsonResources = resolver.getResources(this.rootURL + HJSON_EXTN);
    for (Resource resource : hjsonResources) {
        if (!resource.exists()) {
            log.error("Missing resource during HJSON configuration load: {}", resource.getURI());
            continue;
        }
        String path = resource.getURI().toString().substring(configDirURILength);
        resourceMap.put(path, ConfigFile.builder().type(toType(path)).contentProvider(() -> CONTENT_PROVIDER.apply(resource)).path(path).version(NO_VERSION).build());
    }
    return resourceMap;
}
Also used : ConfigFile(com.yahoo.elide.modelconfig.store.models.ConfigFile) Resource(org.springframework.core.io.Resource) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with ConfigFile

use of com.yahoo.elide.modelconfig.store.models.ConfigFile in project elide by yahoo.

the class ConfigDataStoreTest method testUpdate.

@Test
public void testUpdate(@TempDir Path configPath) {
    String configRoot = configPath.toFile().getPath();
    Validator validator = new DynamicConfigValidator(DefaultClassScanner.getInstance(), configRoot);
    ConfigDataStore store = new ConfigDataStore(configRoot, validator);
    createFile("test", store, false);
    ConfigFile updateFile = updateFile(configRoot, store);
    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(updateFile, loaded));
}
Also used : ConfigFile(com.yahoo.elide.modelconfig.store.models.ConfigFile) RequestScope(com.yahoo.elide.core.RequestScope) DynamicConfigValidator(com.yahoo.elide.modelconfig.validator.DynamicConfigValidator) Validator(com.yahoo.elide.modelconfig.validator.Validator) DynamicConfigValidator(com.yahoo.elide.modelconfig.validator.DynamicConfigValidator) Test(org.junit.jupiter.api.Test)

Example 3 with ConfigFile

use of com.yahoo.elide.modelconfig.store.models.ConfigFile in project elide by yahoo.

the class ConfigDataStoreTest method testUpdateWithPermissionError.

@Test
public void testUpdateWithPermissionError(@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;
    }
    assertThrows(UnsupportedOperationException.class, () -> updateFile(configRoot, store));
}
Also used : ConfigFile(com.yahoo.elide.modelconfig.store.models.ConfigFile) ConfigFile(com.yahoo.elide.modelconfig.store.models.ConfigFile) File(java.io.File) DynamicConfigValidator(com.yahoo.elide.modelconfig.validator.DynamicConfigValidator) Validator(com.yahoo.elide.modelconfig.validator.Validator) DynamicConfigValidator(com.yahoo.elide.modelconfig.validator.DynamicConfigValidator) Test(org.junit.jupiter.api.Test)

Example 4 with ConfigFile

use of com.yahoo.elide.modelconfig.store.models.ConfigFile in project elide by yahoo.

the class ConfigDataStoreTest method testCreateValidateOnly.

@Test
public void testCreateValidateOnly(@TempDir Path configPath) {
    String configRoot = configPath.toFile().getPath();
    Validator validator = new DynamicConfigValidator(DefaultClassScanner.getInstance(), configRoot);
    ConfigDataStore store = new ConfigDataStore(configRoot, validator);
    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);
    assertNull(loaded);
}
Also used : ConfigFile(com.yahoo.elide.modelconfig.store.models.ConfigFile) RequestScope(com.yahoo.elide.core.RequestScope) DynamicConfigValidator(com.yahoo.elide.modelconfig.validator.DynamicConfigValidator) Validator(com.yahoo.elide.modelconfig.validator.Validator) DynamicConfigValidator(com.yahoo.elide.modelconfig.validator.DynamicConfigValidator) Test(org.junit.jupiter.api.Test)

Example 5 with ConfigFile

use of com.yahoo.elide.modelconfig.store.models.ConfigFile in project elide by yahoo.

the class ConfigDataStoreTransaction method createObject.

@Override
public <T> void createObject(T entity, RequestScope scope) {
    ConfigFile file = (ConfigFile) entity;
    if (readOnly || !canCreate(file.getPath())) {
        log.error("Attempt to modify a read only configuration");
        throw new UnsupportedOperationException("Configuration is read only.");
    }
    dirty.add(file);
    todo.add(() -> {
        // We have to assign the ID here during commit so it gets sent back in the response.
        file.setId(ConfigFile.toId(file.getPath(), file.getVersion()));
        createFile(file.getPath());
        updateFile(file.getPath(), file.getContent());
    });
}
Also used : ConfigFile(com.yahoo.elide.modelconfig.store.models.ConfigFile)

Aggregations

ConfigFile (com.yahoo.elide.modelconfig.store.models.ConfigFile)16 RequestScope (com.yahoo.elide.core.RequestScope)10 DynamicConfigValidator (com.yahoo.elide.modelconfig.validator.DynamicConfigValidator)8 Validator (com.yahoo.elide.modelconfig.validator.Validator)8 Test (org.junit.jupiter.api.Test)8 File (java.io.File)2 Include (com.yahoo.elide.annotation.Include)1 SecurityCheck (com.yahoo.elide.annotation.SecurityCheck)1 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)1 NO_VERSION (com.yahoo.elide.core.dictionary.EntityDictionary.NO_VERSION)1 EntityPermissions (com.yahoo.elide.core.dictionary.EntityPermissions)1 BadRequestException (com.yahoo.elide.core.exceptions.BadRequestException)1 Check (com.yahoo.elide.core.security.checks.Check)1 FilterExpressionCheck (com.yahoo.elide.core.security.checks.FilterExpressionCheck)1 UserCheck (com.yahoo.elide.core.security.checks.UserCheck)1 Type (com.yahoo.elide.core.type.Type)1 ClassScanner (com.yahoo.elide.core.utils.ClassScanner)1 DefaultClassScanner (com.yahoo.elide.core.utils.DefaultClassScanner)1 Config (com.yahoo.elide.modelconfig.Config)1 DynamicConfigHelpers (com.yahoo.elide.modelconfig.DynamicConfigHelpers)1