Refactoring changes

This commit is contained in:
Vishal Nayak
2015-06-29 22:00:08 -04:00
parent 208e068138
commit 756be6976d
7 changed files with 157 additions and 81 deletions

View File

@@ -1,6 +1,9 @@
package api
import "fmt"
import (
"encoding/json"
"fmt"
)
type Ssh struct {
c *Client
@@ -10,8 +13,8 @@ func (c *Client) Ssh() *Ssh {
return &Ssh{c: c}
}
func (c *Ssh) KeyCreate(data map[string]interface{}) (*Secret, error) {
r := c.c.NewRequest("PUT", fmt.Sprintf("/v1/ssh/creds/web"))
func (c *Ssh) KeyCreate(role string, data map[string]interface{}) (*Secret, error) {
r := c.c.NewRequest("PUT", fmt.Sprintf("/v1/ssh/creds/"+role))
if err := r.SetJSONBody(data); err != nil {
return nil, err
}
@@ -24,3 +27,27 @@ func (c *Ssh) KeyCreate(data map[string]interface{}) (*Secret, error) {
return ParseSecret(resp.Body)
}
func (c *Ssh) Lookup(data map[string]interface{}) (*SshRoles, error) {
r := c.c.NewRequest("PUT", "/v1/ssh/lookup")
if err := r.SetJSONBody(data); err != nil {
return nil, err
}
resp, err := c.c.RawRequest(r)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var roles SshRoles
dec := json.NewDecoder(resp.Body)
if err := dec.Decode(&roles); err != nil {
return nil, err
}
return &roles, nil
}
type SshRoles struct {
Data map[string]interface{} `json:"data"`
}