mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-30 18:17:55 +00:00 
			
		
		
		
	api: add auth information to results
This commit is contained in:
		| @@ -7,10 +7,21 @@ import ( | |||||||
|  |  | ||||||
| // Secret is the structure returned for every secret within Vault. | // Secret is the structure returned for every secret within Vault. | ||||||
| type Secret struct { | type Secret struct { | ||||||
| 	VaultId       string `json:"vault_id"` | 	VaultId       string                 `json:"vault_id"` | ||||||
| 	Renewable     bool | 	Renewable     bool                   `json":renewable"` | ||||||
| 	LeaseDuration int                    `json:"lease_duration"` | 	LeaseDuration int                    `json:"lease_duration"` | ||||||
| 	Data          map[string]interface{} `json:"data"` | 	Data          map[string]interface{} `json:"data"` | ||||||
|  | 	Auth          *SecretAuth            `json:"auth,omitempty"` | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // Auth is the structure containing auth information if we have it. | ||||||
|  | type SecretAuth struct { | ||||||
|  | 	ClientToken string            `json:"client_Token"` | ||||||
|  | 	Policies    []string          `json:"policies"` | ||||||
|  | 	Metadata    map[string]string `json:"metadata"` | ||||||
|  |  | ||||||
|  | 	LeaseDuration int  `json:"lease_duration"` | ||||||
|  | 	Renewable     bool `json:"renewable"` | ||||||
| } | } | ||||||
|  |  | ||||||
| // ParseSecret is used to parse a secret value from JSON from an io.Reader. | // ParseSecret is used to parse a secret value from JSON from an io.Reader. | ||||||
|   | |||||||
| @@ -84,6 +84,7 @@ func handleLogical(core *vault.Core) http.Handler { | |||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			// If we have authentication information, then set the cookie | 			// If we have authentication information, then set the cookie | ||||||
|  | 			// and setup the result structure. | ||||||
| 			if resp.Auth != nil { | 			if resp.Auth != nil { | ||||||
| 				expireDuration := 365 * 24 * time.Hour | 				expireDuration := 365 * 24 * time.Hour | ||||||
| 				if logicalResp.LeaseDuration != 0 { | 				if logicalResp.LeaseDuration != 0 { | ||||||
| @@ -97,6 +98,14 @@ func handleLogical(core *vault.Core) http.Handler { | |||||||
| 					Path:    "/", | 					Path:    "/", | ||||||
| 					Expires: time.Now().UTC().Add(expireDuration), | 					Expires: time.Now().UTC().Add(expireDuration), | ||||||
| 				}) | 				}) | ||||||
|  |  | ||||||
|  | 				logicalResp.Auth = &Auth{ | ||||||
|  | 					ClientToken:   resp.Auth.ClientToken, | ||||||
|  | 					Policies:      resp.Auth.Policies, | ||||||
|  | 					Metadata:      resp.Auth.Metadata, | ||||||
|  | 					LeaseDuration: int(resp.Auth.Lease.Seconds()), | ||||||
|  | 					Renewable:     resp.Auth.Renewable, | ||||||
|  | 				} | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			httpResp = logicalResp | 			httpResp = logicalResp | ||||||
| @@ -112,4 +121,13 @@ type LogicalResponse struct { | |||||||
| 	Renewable     bool                   `json:"renewable"` | 	Renewable     bool                   `json:"renewable"` | ||||||
| 	LeaseDuration int                    `json:"lease_duration"` | 	LeaseDuration int                    `json:"lease_duration"` | ||||||
| 	Data          map[string]interface{} `json:"data"` | 	Data          map[string]interface{} `json:"data"` | ||||||
|  | 	Auth          *Auth                  `json:"auth"` | ||||||
|  | } | ||||||
|  |  | ||||||
|  | type Auth struct { | ||||||
|  | 	ClientToken   string            `json:"client_Token"` | ||||||
|  | 	Policies      []string          `json:"policies"` | ||||||
|  | 	Metadata      map[string]string `json:"metadata"` | ||||||
|  | 	LeaseDuration int               `json:"lease_duration"` | ||||||
|  | 	Renewable     bool              `json:"renewable"` | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Mitchell Hashimoto
					Mitchell Hashimoto