Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
547 views
in Technique[技术] by (71.8m points)

HashiCorp Vault + node-vault + write = 404

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!


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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...