Merge pull request #13 from gambol99/raw_requests
- adding the ability to perform raw queries to vault
This commit is contained in:
commit
ec472dca8e
|
@ -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**
|
#### **Version v0.0.6**
|
||||||
|
|
||||||
##### FEATURES:
|
##### FEATURES:
|
||||||
|
|
2
main.go
2
main.go
|
@ -26,7 +26,7 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Prog = "vault-sidekick"
|
Prog = "vault-sidekick"
|
||||||
Version = "v0.0.6"
|
Version = "v0.0.7"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
30
vault.go
30
vault.go
|
@ -319,11 +319,39 @@ func (r VaultService) get(rn *watchedResource) (err error) {
|
||||||
for k, v := range rn.resource.options {
|
for k, v := range rn.resource.options {
|
||||||
params[k] = interface{}(v)
|
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)
|
glog.V(5).Infof("attempting to retrieve the resource: %s from vault", rn.resource)
|
||||||
// step: perform a request to vault
|
// step: perform a request to vault
|
||||||
switch rn.resource.resource {
|
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":
|
case "pki":
|
||||||
secret, err = r.client.Logical().Write(fmt.Sprintf(rn.resource.path), params)
|
secret, err = r.client.Logical().Write(fmt.Sprintf(rn.resource.path), params)
|
||||||
case "transit":
|
case "transit":
|
||||||
|
|
|
@ -44,6 +44,7 @@ var (
|
||||||
|
|
||||||
// a map of valid resource to retrieve from vault
|
// a map of valid resource to retrieve from vault
|
||||||
validResources = map[string]bool{
|
validResources = map[string]bool{
|
||||||
|
"raw": true,
|
||||||
"pki": true,
|
"pki": true,
|
||||||
"aws": true,
|
"aws": true,
|
||||||
"secret": true,
|
"secret": true,
|
||||||
|
|
Reference in a new issue