Search in sources :

Example 1 with ShellOption

use of org.springframework.shell.standard.ShellOption in project cas by apereo.

the class ExportPropertiesCommand method exportProperties.

/**
 * Export properties.
 *
 * @param dir the directory for the configuration export
 * @throws Exception the exception
 */
@ShellMethod(key = "export-props", value = "Export CAS properties and settings from configuration metadata.")
public void exportProperties(@ShellOption(value = { "dir", "--dir" }, help = "Path to a directory where reference configuration files would be exported.", defaultValue = "./etc/cas/config") final String dir) throws Exception {
    val allProps = CasConfigurationMetadataCatalog.query(ConfigurationMetadataCatalogQuery.builder().queryType(ConfigurationMetadataCatalogQuery.QueryTypes.ALL).build());
    try (val writer = Files.newBufferedWriter(new File(dir, "all-properties.ref").toPath(), Charset.defaultCharset())) {
        allProps.properties().forEach(Unchecked.consumer(prop -> writeProperty(writer, prop)));
        writer.flush();
    }
    val casProps = CasConfigurationMetadataCatalog.query(ConfigurationMetadataCatalogQuery.builder().queryType(ConfigurationMetadataCatalogQuery.QueryTypes.CAS).build());
    try (val writer = Files.newBufferedWriter(new File(dir, "cas-properties.ref").toPath(), Charset.defaultCharset())) {
        casProps.properties().forEach(Unchecked.consumer(prop -> writeProperty(writer, prop)));
        writer.flush();
    }
    val thirdPartyProperties = CasConfigurationMetadataCatalog.query(ConfigurationMetadataCatalogQuery.builder().queryType(ConfigurationMetadataCatalogQuery.QueryTypes.THIRD_PARTY).build());
    try (val writer = Files.newBufferedWriter(new File(dir, "thirdparty-properties.ref").toPath(), Charset.defaultCharset())) {
        thirdPartyProperties.properties().forEach(Unchecked.consumer(prop -> writeProperty(writer, prop)));
        writer.flush();
    }
    LOGGER.info("Exported configuration properties to [{}]", new File(dir).getAbsolutePath());
}
Also used : lombok.val(lombok.val) ShellCommandGroup(org.springframework.shell.standard.ShellCommandGroup) Unchecked(org.jooq.lambda.Unchecked) Files(java.nio.file.Files) WordUtils(org.apache.commons.text.WordUtils) lombok.val(lombok.val) ConfigurationMetadataCatalogQuery(org.apereo.cas.metadata.ConfigurationMetadataCatalogQuery) ShellMethod(org.springframework.shell.standard.ShellMethod) StringUtils(org.apache.commons.lang3.StringUtils) ShellComponent(org.springframework.shell.standard.ShellComponent) ShellOption(org.springframework.shell.standard.ShellOption) File(java.io.File) Slf4j(lombok.extern.slf4j.Slf4j) Charset(java.nio.charset.Charset) Writer(java.io.Writer) CasConfigurationMetadataCatalog(org.apereo.cas.metadata.CasConfigurationMetadataCatalog) CasReferenceProperty(org.apereo.cas.metadata.CasReferenceProperty) File(java.io.File) ShellMethod(org.springframework.shell.standard.ShellMethod)

Aggregations

File (java.io.File)1 Writer (java.io.Writer)1 Charset (java.nio.charset.Charset)1 Files (java.nio.file.Files)1 Slf4j (lombok.extern.slf4j.Slf4j)1 lombok.val (lombok.val)1 StringUtils (org.apache.commons.lang3.StringUtils)1 WordUtils (org.apache.commons.text.WordUtils)1 CasConfigurationMetadataCatalog (org.apereo.cas.metadata.CasConfigurationMetadataCatalog)1 CasReferenceProperty (org.apereo.cas.metadata.CasReferenceProperty)1 ConfigurationMetadataCatalogQuery (org.apereo.cas.metadata.ConfigurationMetadataCatalogQuery)1 Unchecked (org.jooq.lambda.Unchecked)1 ShellCommandGroup (org.springframework.shell.standard.ShellCommandGroup)1 ShellComponent (org.springframework.shell.standard.ShellComponent)1 ShellMethod (org.springframework.shell.standard.ShellMethod)1 ShellOption (org.springframework.shell.standard.ShellOption)1