11use cipherstash_proxy:: config:: TandemConfig ;
22use cipherstash_proxy:: connect:: { self , AsyncStream } ;
3- use cipherstash_proxy:: encrypt:: Encrypt ;
43use cipherstash_proxy:: error:: Error ;
54use cipherstash_proxy:: prometheus:: CLIENTS_ACTIVE_CONNECTIONS ;
5+ use cipherstash_proxy:: proxy:: Proxy ;
66use cipherstash_proxy:: { cli, log, postgresql as pg, prometheus, tls, Args } ;
77use clap:: Parser ;
88use metrics:: gauge;
@@ -53,16 +53,16 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
5353 runtime. block_on ( async move {
5454 let shutdown_timeout = & config. server . shutdown_timeout ( ) ;
5555
56- let mut encrypt = init ( config) . await ;
56+ let mut proxy = init ( config) . await ;
5757
58- let mut listener = connect:: bind_with_retry ( & encrypt . config . server ) . await ;
58+ let mut listener = connect:: bind_with_retry ( & proxy . config . server ) . await ;
5959 let tracker = TaskTracker :: new ( ) ;
6060
6161 let mut client_id = 0 ;
6262
63- if encrypt . config . prometheus_enabled ( ) {
64- let host = encrypt . config . server . host . to_owned ( ) ;
65- match prometheus:: start ( host, encrypt . config . prometheus . port ) {
63+ if proxy . config . prometheus_enabled ( ) {
64+ let host = proxy . config . server . host . to_owned ( ) ;
65+ match prometheus:: start ( host, proxy . config . prometheus . port ) {
6666 Ok ( _) => { }
6767 Err ( err) => {
6868 error ! (
@@ -82,7 +82,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
8282 } ,
8383 _ = sighup( ) => {
8484 info!( msg = "Received SIGHUP. Reloading configuration" ) ;
85- ( listener, encrypt ) = reload_config( listener, & args, encrypt ) . await ;
85+ ( listener, proxy ) = reload_config( listener, & args, proxy ) . await ;
8686 info!( msg = "Reloaded configuration" ) ;
8787 } ,
8888 _ = sigterm( ) => {
@@ -91,16 +91,16 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
9191 } ,
9292 Ok ( client_stream) = AsyncStream :: accept( & listener) => {
9393
94- let encrypt = encrypt . clone( ) ;
94+ let proxy = proxy . clone( ) ;
9595
9696 client_id += 1 ;
9797
9898 tracker. spawn( async move {
99- let encrypt = encrypt . clone( ) ;
99+ let proxy = proxy . clone( ) ;
100100
101101 gauge!( CLIENTS_ACTIVE_CONNECTIONS ) . increment( 1 ) ;
102102
103- match pg:: handler( client_stream, encrypt , client_id) . await {
103+ match pg:: handler( client_stream, proxy , client_id) . await {
104104 Ok ( _) => ( ) ,
105105 Err ( err) => {
106106
@@ -145,9 +145,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
145145
146146///
147147/// Validate various configuration options and
148- /// Init the Encrypt service
148+ /// Init the Proxy service
149149///
150- async fn init ( mut config : TandemConfig ) -> Encrypt {
150+ async fn init ( mut config : TandemConfig ) -> Proxy {
151151 if config. encrypt . default_keyset_id . is_none ( ) {
152152 warn ! ( msg = "Default Keyset Id has not been configured" ) ;
153153 warn ! ( msg = "A Keyset Identifier must be set using the `SET CIPHERSTASH.KEYSET_ID` or `SET CIPHERSTASH.KEYSET_NAME` commands" ) ;
@@ -216,25 +216,25 @@ async fn init(mut config: TandemConfig) -> Encrypt {
216216 }
217217 }
218218
219- match Encrypt :: init ( config) . await {
220- Ok ( encrypt ) => {
221- info ! ( msg = "Connected to CipherStash Encrypt " ) ;
219+ match Proxy :: init ( config) . await {
220+ Ok ( proxy ) => {
221+ info ! ( msg = "Connected to CipherStash Proxy " ) ;
222222 info ! (
223223 msg = "Connected to Database" ,
224- database = encrypt . config. database. name,
225- host = encrypt . config. database. host,
226- port = encrypt . config. database. port,
227- username = encrypt . config. database. username,
228- eql_version = encrypt . eql_version,
224+ database = proxy . config. database. name,
225+ host = proxy . config. database. host,
226+ port = proxy . config. database. port,
227+ username = proxy . config. database. username,
228+ eql_version = proxy . eql_version,
229229 ) ;
230- if encrypt . eql_version . as_deref ( ) != EQL_VERSION_AT_BUILD_TIME {
230+ if proxy . eql_version . as_deref ( ) != EQL_VERSION_AT_BUILD_TIME {
231231 warn ! (
232232 msg = "installed version of EQL is different to the version that Proxy was built with" ,
233233 eql_build_version = EQL_VERSION_AT_BUILD_TIME ,
234- eql_installed_version = encrypt . eql_version,
234+ eql_installed_version = proxy . eql_version,
235235 ) ;
236236 }
237- encrypt
237+ proxy
238238 }
239239 Err ( err) => {
240240 error ! (
@@ -261,29 +261,25 @@ async fn sighup() -> std::io::Result<()> {
261261 Ok ( ( ) )
262262}
263263
264- async fn reload_config (
265- listener : TcpListener ,
266- args : & Args ,
267- encrypt : Encrypt ,
268- ) -> ( TcpListener , Encrypt ) {
264+ async fn reload_config ( listener : TcpListener , args : & Args , proxy : Proxy ) -> ( TcpListener , Proxy ) {
269265 let new_config = match TandemConfig :: load ( args) {
270266 Ok ( config) => config,
271267 Err ( err) => {
272268 warn ! (
273269 msg = "Configuration could not be reloaded: {}" ,
274270 error = err. to_string( )
275271 ) ;
276- return ( listener, encrypt ) ;
272+ return ( listener, proxy ) ;
277273 }
278274 } ;
279275
280- let new_encrypt = init ( new_config) . await ;
276+ let new_proxy = init ( new_config) . await ;
281277
282278 // Explicit drop needed here to free the network resources before binding if using the same address & port
283279 std:: mem:: drop ( listener) ;
284280
285281 (
286- connect:: bind_with_retry ( & new_encrypt . config . server ) . await ,
287- new_encrypt ,
282+ connect:: bind_with_retry ( & new_proxy . config . server ) . await ,
283+ new_proxy ,
288284 )
289285}
0 commit comments