Merge pull request #13 from gambol99/raw_requests

- adding the ability to perform raw queries to vault
This commit is contained in:
Rohith 2016-03-16 16:21:14 +00:00
commit ec472dca8e
4 changed files with 38 additions and 2 deletions

View file

@ -1,3 +1,10 @@
#### **Version v0.0.7**
##### FEATURES
* Adding the ability to the perform raw queries to vault, the formatting stays the same - a single
data key 'content' is returned, example: -cn=raw:platform/pki/ca/pem:fmt=txt,file=ca
#### **Version v0.0.6**
##### FEATURES:

View file

@ -26,7 +26,7 @@ import (
const (
Prog = "vault-sidekick"
Version = "v0.0.6"
Version = "v0.0.7"
)
func main() {

View file

@ -319,11 +319,39 @@ func (r VaultService) get(rn *watchedResource) (err error) {
for k, v := range rn.resource.options {
params[k] = interface{}(v)
}
glog.V(10).Infof("get path: %s, params: %v", rn.resource.path, params)
glog.V(10).Infof("get, resource: %s, path: %s, params: %v", rn.resource.resource, rn.resource.path, params)
glog.V(5).Infof("attempting to retrieve the resource: %s from vault", rn.resource)
// step: perform a request to vault
switch rn.resource.resource {
case "raw":
request := r.client.NewRequest("GET", "/v1/" + rn.resource.path)
for k, v := range rn.resource.options {
request.Params.Add(k, v)
}
resp, err := r.client.RawRequest(request)
if err != nil {
fmt.Printf("FAILED HERE")
return err
}
// step: read the response
content, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
// step: construct a secret from the response
secret = &api.Secret{
LeaseID: "raw",
Renewable: false,
Data: map[string]interface{}{
"content" : fmt.Sprintf("%s", content),
},
}
if rn.resource.update > 0 {
secret.LeaseDuration = int(rn.resource.update.Seconds())
} else {
secret.LeaseDuration = int((time.Duration(24) * time.Hour).Seconds())
}
case "pki":
secret, err = r.client.Logical().Write(fmt.Sprintf(rn.resource.path), params)
case "transit":

View file

@ -44,6 +44,7 @@ var (
// a map of valid resource to retrieve from vault
validResources = map[string]bool{
"raw": true,
"pki": true,
"aws": true,
"secret": true,