Search in sources :

Example 6 with ConfigFile

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());
}
Also used : Arrays(java.util.Arrays) DynamicConfiguration(com.yahoo.elide.modelconfig.DynamicConfiguration) Include(com.yahoo.elide.annotation.Include) FileLoader(com.yahoo.elide.modelconfig.io.FileLoader) DefaultParser(org.apache.commons.cli.DefaultParser) Matcher(java.util.regex.Matcher) ClassScanner(com.yahoo.elide.core.utils.ClassScanner) Locale(java.util.Locale) Map(java.util.Map) DynamicConfigHelpers(com.yahoo.elide.modelconfig.DynamicConfigHelpers) Named(com.yahoo.elide.modelconfig.model.Named) Join(com.yahoo.elide.modelconfig.model.Join) TableSource(com.yahoo.elide.modelconfig.model.TableSource) ElideSecurityConfig(com.yahoo.elide.modelconfig.model.ElideSecurityConfig) Argument(com.yahoo.elide.modelconfig.model.Argument) DefaultClassScanner(com.yahoo.elide.core.utils.DefaultClassScanner) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) SecurityCheck(com.yahoo.elide.annotation.SecurityCheck) Objects(java.util.Objects) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) Stream(java.util.stream.Stream) DynamicConfigSchemaValidator(com.yahoo.elide.modelconfig.DynamicConfigSchemaValidator) Pattern(java.util.regex.Pattern) NamespaceConfig(com.yahoo.elide.modelconfig.model.NamespaceConfig) Getter(lombok.Getter) ElideTableConfig(com.yahoo.elide.modelconfig.model.ElideTableConfig) Table(com.yahoo.elide.modelconfig.model.Table) ConfigFile(com.yahoo.elide.modelconfig.store.models.ConfigFile) Options(org.apache.commons.cli.Options) ElideDBConfig(com.yahoo.elide.modelconfig.model.ElideDBConfig) HashMap(java.util.HashMap) UserCheck(com.yahoo.elide.core.security.checks.UserCheck) ElideNamespaceConfig(com.yahoo.elide.modelconfig.model.ElideNamespaceConfig) HelpFormatter(org.apache.commons.cli.HelpFormatter) ElideSQLDBConfig(com.yahoo.elide.modelconfig.model.ElideSQLDBConfig) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) CollectionUtils(org.apache.commons.collections.CollectionUtils) NO_VERSION(com.yahoo.elide.core.dictionary.EntityDictionary.NO_VERSION) Config(com.yahoo.elide.modelconfig.Config) CommandLine(org.apache.commons.cli.CommandLine) ParseTree(org.antlr.v4.runtime.tree.ParseTree) FilterExpressionCheck(com.yahoo.elide.core.security.checks.FilterExpressionCheck) Option(org.apache.commons.cli.Option) Check(com.yahoo.elide.core.security.checks.Check) Dimension(com.yahoo.elide.modelconfig.model.Dimension) IOException(java.io.IOException) DBConfig(com.yahoo.elide.modelconfig.model.DBConfig) BadRequestException(com.yahoo.elide.core.exceptions.BadRequestException) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) EntityPermissions(com.yahoo.elide.core.dictionary.EntityPermissions) Type(com.yahoo.elide.core.type.Type) Collections(java.util.Collections) Measure(com.yahoo.elide.modelconfig.model.Measure) ElideSecurityConfig(com.yahoo.elide.modelconfig.model.ElideSecurityConfig) IOException(java.io.IOException)

Example 7 with ConfigFile

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()));
}
Also used : ConfigFile(com.yahoo.elide.modelconfig.store.models.ConfigFile)

Example 8 with ConfigFile

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()));
}
Also used : ConfigFile(com.yahoo.elide.modelconfig.store.models.ConfigFile)

Example 9 with ConfigFile

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));
}
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 10 with ConfigFile

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));
}
Also used : ConfigFile(com.yahoo.elide.modelconfig.store.models.ConfigFile) ConfigFile(com.yahoo.elide.modelconfig.store.models.ConfigFile) File(java.io.File) 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)

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