Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to retrieve config data from HC Vault in Scala #256

Open
pforpramit opened this issue Feb 26, 2024 · 0 comments
Open

Unable to retrieve config data from HC Vault in Scala #256

pforpramit opened this issue Feb 26, 2024 · 0 comments

Comments

@pforpramit
Copy link

I am using below code to read config data from HC Vault,

package com.dell.eventreader.config
import com.bettercloud.vault.json.Json
import com.bettercloud.vault.{Vault, VaultConfig}

object VaultConfig {

  def main(args: Array[String]): Unit = {
  
    // Configuration properties
    val host = "vault.com"
    val port = 443
    val scheme = "https"
    val namespace = "my/namespace/path/"
    val roleId = "sample-role"
    val secretId = "sample-secret"

    // Initialize Vault configuration
    val vaultConfig = new VaultConfig()
      .address(s"$scheme://$host:$port")
      .nameSpace(namespace)
      .build()

    // Create a Vault client
    val vault = new Vault(vaultConfig)

    // Specify the path to the secret in Vault
    val secretPath = "/kv/data/scala-poc"

    // Authenticate using role ID and secret ID
    vault.auth().loginByAppRole(roleId, secretId)

    // Read the secret from Vault
    val response = vault.logical().read(secretPath)

    // Extract the configuration from the response
    val configMap = response.getData

    println("Retrieved configuration from Vault:")
    configMap.forEach((key, value) => println(s"$key -> $value"))
  }
}

There is no error, but it does not print any config data either. However, there are some config data as I can see from Vault UI. There, the navigation goes like - namespace-path -> kv -> scala-poc

As there is no error shown, I suppose the Vault configurations are correct and have been set correctly as well. I am unsure of what will be the correct secretPath if not this one. Tried with /kv/scala-poc as well, but no luck. Also, I don't find anything to set kv as backend here. I can confirm that kv version 2 is being used this side.

Unable to identify what's missing in here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant