mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-30 10:12:35 +00:00 
			
		
		
		
	Refactoring changes
This commit is contained in:
		
							
								
								
									
										33
									
								
								api/ssh.go
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								api/ssh.go
									
									
									
									
									
								
							| @@ -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"` | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Vishal Nayak
					Vishal Nayak