diff --git a/CHANGELOG.md b/CHANGELOG.md index b516a79..e0b4ddc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: diff --git a/main.go b/main.go index 6c40ec8..72e18f7 100644 --- a/main.go +++ b/main.go @@ -26,7 +26,7 @@ import ( const ( Prog = "vault-sidekick" - Version = "v0.0.6" + Version = "v0.0.7" ) func main() { diff --git a/vault.go b/vault.go index 8bca704..a0bc301 100644 --- a/vault.go +++ b/vault.go @@ -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": diff --git a/vault_resource.go b/vault_resource.go index 0045072..a768112 100644 --- a/vault_resource.go +++ b/vault_resource.go @@ -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,