GithubHelp home page GithubHelp logo

karlazzampersonal / ktor-vault Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 69 KB

A hashicorp vault plugin for ktor

License: Apache License 2.0

Kotlin 100.00%
vault ktor ktor-feature ktor-plugin hashicorp-vault

ktor-vault's Introduction

Ktor vault plugin

Publish License: Apache 2.0

A Ktor installable plugin for vault that allows you to inject vault secrets into your project.

The vault token is the only supported login mechanism

Usage

Set up in Kotlin Gradle:
repositories {
    mavenCentral()
    // Need a GH access token with read package scope
    maven {
        name = "GitHubPackages"
        url = uri("https://maven.pkg.github.com/karlazzampersonal/ktor-vault")
        credentials {
            username = props.getProperty("USERNAME")
            password = props.getProperty("TOKEN")
        }
    }
}

dependencies {
    implementation("com.levels:ktor-vault:$ktor_vault_version")
}

First, Add the feature to your Application module

// Get the vault token and engine from environment variables
val env = System.getenv("ENV")
install(Vault) {
    token = System.getenv("VAULT_TOKEN")
    engine =  System.getenv("ENGINE")
    // Specify all the secret paths to look in
    secretPaths = listOf(
        "shared/".plus(env),
        "my-service/".plus(env)
    )
} 

Create an env singleton and fetch your secrets via the secret name

object Env {
    val awsRegion: String = Vault.getSecret("aws.region")

    val kafkaBootstrapServer: String = Vault.getSecret("kafka.bootstrap-server")
   
    // and your other secrets .....
}

Use your env variables in another part of the code

    install(Kafka) {
        kafka { 
            bootstrapServer = Env.kafkaBootstrapServer
        } 
    }

License

This project is licensed under the Apache 2.0 license

Contributing

We welcome any contributions, please submit an issue or PR.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.