PitchHut logo
Log in / Sign up
rapier
by aleph0io
Streamline Google Dagger configuration with automated code generation.
Pitch

Rapier is a companion library designed to reduce boilerplate in Google Dagger projects. By automatically generating Dagger modules from annotations, it simplifies the process of retrieving configuration data from various sources such as environment variables and system parameters. Focus on building features while Rapier handles the setup.

Description

Rapier is a powerful code generation library designed to enhance the efficiency of using Dagger by significantly reducing boilerplate code associated with common configuration sources. This library automates the generation of Dagger modules, enabling developers to effortlessly integrate configuration data from various sources such as environment variables, system parameters, AWS Systems Manager parameter store, and command-line interface (CLI) arguments.

Features of Rapier

Rapier streamlines the code generation process by providing annotations that automatically create Dagger modules. For instance, consider the following Dagger component definition:

@Component(modules = {RapierExampleComponentEnvironmentVariableModule.class})
public interface ExampleComponent {
    /**
     * Retrieve timeout in milliseconds from the environment variable TIMEOUT, or default to 30000 if not present
     */
    @EnvironmentVariable(value="TIMEOUT", defaultValue="30000")
    public long getTimeout();
}

In this example, Rapier will generate the RapierExampleComponentEnvironmentVariableModule class, which implements the logic required to access the TIMEOUT environment variable, using a default of 30000 when the variable is absent.

Quickstart Guidance

To utilize Rapier for code generation, ensure the associated annotation processor is configured properly in your build system. The following is an example of how to set up a Maven project:

<properties>
  <rapier.version>0.0.0-b0</rapier.version>
  <dagger.version>2.52</dagger.version>
</properties>
<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <configuration>
        <source>11</source>
        <target>11</target>
        <annotationProcessorPaths>
          <path>
            <groupId>com.sigpwned</groupId>
            <artifactId>rapier-environment-variable-compiler</artifactId>
            <version>${rapier.version}</version>
          </path>
          <path>
            <groupId>com.google.dagger</groupId>
            <artifactId>dagger-compiler</artifactId>
            <version>${dagger.version}</version>
          </path>
        </annotationProcessorPaths>
      </configuration>
    </plugin>
  </plugins>
</build>

Users can define Dagger components that reference generated modules, thereby seamlessly integrating configuration retrieval without hassle.

Supported Configuration Sources

Rapier supports code generation for multiple configuration sources, including but not limited to:

  • Environment Variables (@EnvironmentVariable)
  • System Properties (@SystemProperty)
  • AWS Systems Manager Parameter Store (@AwsSsmStringParameter)
  • CLI Arguments (@CliPositionalParameter, @CliOptionParameter, @CliFlagParameter)

Advanced Features

Rapier includes advanced functionality for data type conversion and templating, which allows users to dynamically specify configuration coordinate names using environment variables and system properties. This flexibility enhances integration capabilities, ensuring that applications can adapt based on varying deployment settings.

Example of Templating

Given the need for dynamic configuration based on environment variables:

@Component(modules = RapierExampleComponentAwsSsmModule.class)
public interface ExampleComponent {
    @AwsSsmStringParameter("${env.STAGE}.databaseHost")
    public String databaseHostname();
}

This component will load configuration based on the current deployment stage, allowing easy adaptation to different environments.

Testing and Beta Versioning

Rapier is designed with testing in mind, providing features that allow custom configuration values for test scenarios. The library is currently in beta phase, focusing on stability while still evolving to meet user needs.

For those interested in exploring real-world applications, the rapier-examples module offers various usage examples to guide implementation.

Contribution Opportunities

Rapier welcomes contributions to improve and enhance the library further. Interested individuals can participate by sharing feedback, reporting bugs, or contributing code. Every input is valuable and contributes to the library's growth.

0 comments

No comments yet.

Sign in to be the first to comment.