SkillAgentSearch skills...

SmartConfig

No description available

Install / Use

/learn @SergeyBudnik/SmartConfig
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

SmartConfig

Maven Central

Maven Central

About

TBD

Main features

  1. True typesafe configuration
  2. Strong properties validation
  3. Possibility to subscribe to properties change

Integration

Lets imagine that you are developing a java-based server, which reads currencies from the database and distributes them to your website through Rest service.

You should be able to configure server to work in three environments: SIT, UAT, Prod Also your production servers are located in different countries: Russia, USA and India

You want to configure:

  1. Database URL
  2. Language that you want to use for your Rest services response

So, lets get started!

First, create a space configuration file (located: ${project.basedir}/src/main/resources/config-spaces.conf)

space {
    env: [sit, uat, prod]
    location: [no_location, rus, usa, india]
}

points [
    {env: sit, location: no_location},
    {env: uat, location: no_location},
    {env: prod, location: rus},
    {env: prod, location: usa},
    {env: prod, location: india},
]

Now, create a configuration file with the values (located: ${project.basedir}/src/main/resources/config.conf)

database.url {
    ~sit: 'my_sit_database'
    ~uat: 'my_uat_database'
    ~prod: 'my_prod_database'
}

language {
    ~default: 'eng' // ~default - special keyword for default values
    ~rus: 'russia'
}

Add the following lines to your project pom.xml

<properties>
    <smart.config.csvProperties>${project.basedir}/src/main/resources/config.conf</smart.config.csvProperties>
    <smart.config.dimensions>${project.basedir}/src/main/resources/config-spaces.conf</smart.config.dimensions>
</properties>

<dependencies>
    <dependency>
        <groupId>com.github.sergeybudnik</groupId>
        <artifactId>smart.config.data</artifactId>
        <version>3.1.0</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>com.github.sergeybudnik</groupId>
            <artifactId>smart.config</artifactId>
            <version>3.1.0</version>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>jenesis4java</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <relativeDirectory>/smart-generated-sources/smart-config</relativeDirectory> <!-- Optional -->
                <csvProperties>${project.basedir}/src/main/resources/smart-config-test.conf</csvProperties> <!-- Required -->
                <dimensions>${project.basedir}/src/main/resources/smart-config-dimensions.conf</dimensions> <!-- Required -->
            </configuration>
        </plugin>
    </plugins>
</build>

Finish!

Run 'mvn clean install'

After plugin execution, you will be able to work with properties in a following way:

SmartConfig smartConfig = SmartConfigProperties.getConfig("prod", "usa");

String databaseUrl = smartConfig.getDatabaseUrl();
SmartConfigValue<String> databaseUrlConfig = smartConfig.getDatabaseUrlConfig();

System.out.println(databaseUrl); // Prints 'my_prod_database'

Related Skills

View on GitHub
GitHub Stars14
CategoryDevelopment
Updated1y ago
Forks1

Languages

Java

Security Score

55/100

Audited on Oct 22, 2024

No findings