Skip to content

Lift4: Support for Env Vars in configuration #2011

Open

Description

@dpp

Lift's properties/configuration mechanism is based on named files. However, this means storing secrets (e.g., DB credentials, etc.) in files and potentially checking those files into source control systems. Yikes!!

The industry is moving to using Env Vars for configuration/secrets.

The proposal is to extend Lift's configuration system to support referencing Env Vars from configuration files (Rust has an env!(...) macro.

Thus if a line in a configuration file looks like:

foo.bar.baz=env!("VAR_NAME")

Lift's configuration system will read the env var and if the env var isn't define, the config system will throw an exception which will halt the Lift boot cycle.

Activity

  1. added
    Lift5
    on Oct 19, 2023
  2. self-assigned this
    on Oct 19, 2023
  3. andreak commented on Oct 19, 2023

    @andreak
    Member

    Many projects use Spring Boot and use its properties-loading mechanism.; It'd be nice if we could weave in some kind of interop with Spring Boot's properties.

  4. dpp commented on Oct 19, 2023

    @dpp
    MemberAuthor

    Do you have a pointer to the Spring Boot properties package? Lemme see if I can do something with reflection so if it's there, it'll be used.

  5. andreak commented on Oct 19, 2023

    @andreak
    Member

    We inject Spring's org.springframework.core.env.Environment in Boot:

    @Configurable
    class Boot extends VisenaLoggable {
    
    	@Resource(name = "origoDecoratorProvider")
    	val decoratorProvider: ExecutionTaskDecoratorProvider = null
    	@Resource(name = "liftSchedulerExecutor")
    	val liftSchedulerExecutor: ExecutorService = null
    	@Resource
    	val springEnvironment: Environment = null
    
    	def boot(): Unit = {
    
    ....
    ....
    		LiftRules.ajaxRetryCount = Full(springEnvironment.getProperty("ajax.retryCount", classOf[Int]))
    
    

    https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/core/env/Environment.html

    We use AspectJ's META-INF/aop.xml to configure how Spring should process "non-Spring managed classes":

    <aspectj>
        <weaver options="-verbose -showWeaveInfo -XmessageHandlerClass:org.springframework.aop.aspectj.AspectJWeaverMessageHandler">
            <!--
            Only weave @Configurable stuff
            -->
            <include within="@org.springframework.beans.factory.annotation.Configurable no.officenet.origo..*"/>
            <include within="@org.springframework.beans.factory.annotation.Configurable com.visena..*"/>
    		<include within="@org.springframework.beans.factory.annotation.Configurable bootstrap.liftweb.Boot"/>
    	</weaver>
    
    </aspectj>
    
  6. lvitaly commented on Oct 19, 2023

    @lvitaly
    Contributor

    Maybe it is worth supporting different config providers? For example, lightbend/config supports env variable out of the box.

  7. dpp commented on Oct 20, 2023

    @dpp
    MemberAuthor

    I am suggesting a very simple extension to the existing Props mechanism that allows injection of environment variables into properties.

    There's nothing in Lift that defaults to using the Props system... it's mostly stand-alone.

    If there are other properties systems that are used with other systems, why not use those natively in the Lift app rather than trying to wrap Props (which is simple and dumb by design) around them?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Lift5

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions