mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-30 18:17:55 +00:00 
			
		
		
		
	 4b67fd139f
			
		
	
	4b67fd139f
	
	
	
		
			
			backends for the moment. This is pretty simple; it just adds the actual capability to make a list call into both the CLI and the HTTP handler. The real meat was already in those backends.
		
			
				
	
	
		
			80 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			80 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package api
 | |
| 
 | |
| // Logical is used to perform logical backend operations on Vault.
 | |
| type Logical struct {
 | |
| 	c *Client
 | |
| }
 | |
| 
 | |
| // Logical is used to return the client for logical-backend API calls.
 | |
| func (c *Client) Logical() *Logical {
 | |
| 	return &Logical{c: c}
 | |
| }
 | |
| 
 | |
| func (c *Logical) Read(path string) (*Secret, error) {
 | |
| 	r := c.c.NewRequest("GET", "/v1/"+path)
 | |
| 	resp, err := c.c.RawRequest(r)
 | |
| 	if resp != nil {
 | |
| 		defer resp.Body.Close()
 | |
| 	}
 | |
| 	if resp != nil && resp.StatusCode == 404 {
 | |
| 		return nil, nil
 | |
| 	}
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 
 | |
| 	return ParseSecret(resp.Body)
 | |
| }
 | |
| 
 | |
| func (c *Logical) List(path string) (*Secret, error) {
 | |
| 	r := c.c.NewRequest("LIST", "/v1/"+path)
 | |
| 	resp, err := c.c.RawRequest(r)
 | |
| 	if resp != nil && resp.StatusCode == 404 {
 | |
| 		return nil, nil
 | |
| 	}
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	defer resp.Body.Close()
 | |
| 
 | |
| 	return ParseSecret(resp.Body)
 | |
| }
 | |
| 
 | |
| func (c *Logical) Write(path string, data map[string]interface{}) (*Secret, error) {
 | |
| 	r := c.c.NewRequest("PUT", "/v1/"+path)
 | |
| 	if err := r.SetJSONBody(data); err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 
 | |
| 	resp, err := c.c.RawRequest(r)
 | |
| 	if resp != nil {
 | |
| 		defer resp.Body.Close()
 | |
| 	}
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 
 | |
| 	if resp.StatusCode == 200 {
 | |
| 		return ParseSecret(resp.Body)
 | |
| 	}
 | |
| 
 | |
| 	return nil, nil
 | |
| }
 | |
| 
 | |
| func (c *Logical) Delete(path string) (*Secret, error) {
 | |
| 	r := c.c.NewRequest("DELETE", "/v1/"+path)
 | |
| 	resp, err := c.c.RawRequest(r)
 | |
| 	if resp != nil {
 | |
| 		defer resp.Body.Close()
 | |
| 	}
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 
 | |
| 	if resp.StatusCode == 200 {
 | |
| 		return ParseSecret(resp.Body)
 | |
| 	}
 | |
| 
 | |
| 	return nil, nil
 | |
| }
 |