mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-29 17:52:32 +00:00 
			
		
		
		
	agent: Use an in-process listener with cache (#12762)
Uses a bufconn listener between consul-template and vault-agent when
caching is enabled and either templates or a listener is defined. This
means no listeners need to be defined in vault-agent for just
templating. Always routes consul-template through the vault-agent
cache (instead of only when persistent cache is enabled).
Uses a local transportDialer interface in config.Cache{}. 
Co-authored-by: Tom Proctor <tomhjp@users.noreply.github.com>
Co-authored-by: Ben Ash <32777270+benashz@users.noreply.github.com>
			
			
This commit is contained in:
		
							
								
								
									
										38
									
								
								internalshared/listenerutil/bufconn.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								internalshared/listenerutil/bufconn.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,38 @@ | ||||
| package listenerutil | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"net" | ||||
|  | ||||
| 	"google.golang.org/grpc/test/bufconn" | ||||
| ) | ||||
|  | ||||
| const BufConnType = "bufconn" | ||||
|  | ||||
| // BufConnWrapper implements consul-template's TransportDialer using a | ||||
| // bufconn listener, to provide a way to Dial the in-memory listener | ||||
| type BufConnWrapper struct { | ||||
| 	listener *bufconn.Listener | ||||
| } | ||||
|  | ||||
| // NewBufConnWrapper returns a new BufConnWrapper using an | ||||
| // existing bufconn.Listener | ||||
| func NewBufConnWrapper(bcl *bufconn.Listener) *BufConnWrapper { | ||||
| 	return &BufConnWrapper{ | ||||
| 		listener: bcl, | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // Dial connects to the listening end of the bufconn (satisfies | ||||
| // consul-template's TransportDialer interface). This is essentially the client | ||||
| // side of the bufconn connection. | ||||
| func (bcl *BufConnWrapper) Dial(_, _ string) (net.Conn, error) { | ||||
| 	return bcl.listener.Dial() | ||||
| } | ||||
|  | ||||
| // DialContext connects to the listening end of the bufconn (satisfies | ||||
| // consul-template's TransportDialer interface). This is essentially the client | ||||
| // side of the bufconn connection. | ||||
| func (bcl *BufConnWrapper) DialContext(ctx context.Context, _, _ string) (net.Conn, error) { | ||||
| 	return bcl.listener.DialContext(ctx) | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Theron Voran
					Theron Voran