Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying a simple operation using node-vault but it is not working. Here is my attempt:

  1. Configuration

     var options = {
       apiVersion: 'v2', // default
       endpoint: 'http://127.0.0.1:8200', // default
     };
    
     // get new instance of the client
     var vault = require("node-vault")(options);
     vault.token = "<<MY TOKEN>>";
    
  2. Usage

     vault.write('secret/data/new', {"data": {"foo": "bar"}}).then(
           function (value: any) {
             console.log(value);
           })
           .catch((err: any) => {
             console.log(err);
           });
    
  3. Response

     { statusCode: 404, body: { errors: [] } }
    

But, if I run vault kv put secret/data/new foo=bar it does work and value is there.

What is going on?

Thank you all and I wish a happy new year!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
567 views
Welcome To Ask or Share your Answers For Others

1 Answer

Ok, here is what I did.

  1. Reinstall Vault, something happened to storage because I did a lot of attempts and commands in it.
  2. Enable secrets engine in specific path vault secrets enable -path=testPath kv
  3. Write to this path

Configure:

    export const VAULT_OPTIONS = {
      apiVersion: 'v1',
      endpoint: 'http://127.0.0.1:8200',
      token: '<<YOUR TOKEN>>'
    };
    vault = require("node-vault")(VAULT_OPTIONS);

Write:

    this.vault.write('test/data/mykey', {"data": {"tests": {"test1": "test1-value", "test2": "test2-value"}}}).then(
          (result: any) => {
            console.log(res.data);
          }, (error: any) => {
              console.log(error);
          });

Please note that path must contain data and data must be surounded by data ({ data: {key:value}) as well.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...