golang vault api

987 views
Skip to first unread message

mg

unread,
May 31, 2016, 6:19:26 PM5/31/16
to Vault
Hi 

I am able to generate a pki cert using command line like so

vault write iptv_qa_pki/issue/test-dot-local common_name=localhost alt_names="vault.test.local,*.vault.test.local" ip_sans="127.0.0.1,192.168.1.77" > /tmp/localhost.certs


When i try to do the same with golang api, i get nil output


package main


import (

  vaultapi "github.com/hashicorp/vault/api"

  "log"

  )


func main() {


client, err := vaultapi.NewClient(vaultapi.DefaultConfig())


if  err == nil {

   log.Println(err)

   return

}


token := "28ef4e40-2597-4571-aadf-41300df98338"


client.SetToken(token)

c := client.Logical()


sec, err := c.Write("iptv_qa_pki/issue/test-dot-local",

    map[string]interface{}{

     "common_name": "localhost",

     "alt_names": "*.test.local",

        "ip_sans": "127.0.0.1",

    })


if  err == nil {

   log.Println(err)

   return

}


log.Println(sec)


}


When I do - go run program.go . My output is


2016/05/31 15:18:22 <nil>


What am I doing wrong here?


I realize this is a vault forum and not golang one, so I apologize for taking the liberty to ask golang vault related issue.

But any help/pointer would be appreciated.


vishal nayak

unread,
May 31, 2016, 6:33:42 PM5/31/16
to vault...@googlegroups.com
Hi Meher,

No problem :)

You should use "err != nil" and that should do it!

Regards,
Vishal

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/vault/issues
IRC: #vault-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Vault" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vault-tool+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vault-tool/454b8af9-f856-49e5-8ab4-53c841b08761%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
vn

Matt Button

unread,
May 31, 2016, 6:40:54 PM5/31/16
to vault...@googlegroups.com

Hi mg,

The `if err == nil` lines should be `if err != nil`

Hope that helps

Matt

mg

unread,
May 31, 2016, 7:54:48 PM5/31/16
to Vault
Hi Vishal and Matt

Thank You , that helped. I am able to get the certificate, private-key and the issuing-ca.
Reply all
Reply to author
Forward
0 new messages