@@ -21,6 +21,7 @@ type Client interface {
2121}
2222
2323type ClientManager struct {
24+ name string
2425 cliCfg * config.ProxyClient
2526 cfg * config.UpStream
2627 privKey * ecdsa.PrivateKey
@@ -52,14 +53,15 @@ func buildPrivateKey(inputBytes []byte) (*ecdsa.PrivateKey, error) {
5253 return nil , fmt .Errorf ("failed to generate valid private key from input bytes" )
5354}
5455
55- func NewClientManager (cliCfg * config.ProxyClient , cfg * config.UpStream ) (* ClientManager , error ) {
56+ func NewClientManager (name string , cliCfg * config.ProxyClient , cfg * config.UpStream ) (* ClientManager , error ) {
5657
5758 privKey , err := buildPrivateKey ([]byte (cliCfg .Secret ))
5859 if err != nil {
5960 return nil , err
6061 }
6162
6263 return & ClientManager {
64+ name : name ,
6365 privKey : privKey ,
6466 cfg : cfg ,
6567 cliCfg : cliCfg ,
@@ -75,13 +77,13 @@ func (cliMgr *ClientManager) doLogin(ctx context.Context, loginCli *upClient) ti
7577 }
7678
7779 for {
78- log .Info ("attempting login to upstream coordinator" , "baseURL " , cliMgr .cfg . BaseUrl )
80+ log .Info ("attempting login to upstream coordinator" , "name " , cliMgr .name )
7981 loginResult , err := loginCli .Login (ctx )
8082 if err == nil && loginResult != nil {
81- log .Info ("login to upstream coordinator successful" , "baseURL " , cliMgr .cfg . BaseUrl , "time" , loginResult .Time )
83+ log .Info ("login to upstream coordinator successful" , "name " , cliMgr .name , "time" , loginResult .Time )
8284 return loginResult .Time
8385 }
84- log .Info ("login to upstream coordinator failed, retrying" , "baseURL " , cliMgr .cfg . BaseUrl , "error" , err , "waitDuration" , waitDuration )
86+ log .Info ("login to upstream coordinator failed, retrying" , "name " , cliMgr .name , "error" , err , "waitDuration" , waitDuration )
8587
8688 timer := time .NewTimer (waitDuration )
8789 select {
@@ -136,14 +138,14 @@ func (cliMgr *ClientManager) Client(ctx context.Context) *upClient {
136138 if clearTime .Before (now .Add (10 * time .Second )) {
137139 clearTime = now .Add (10 * time .Second )
138140 log .Error ("token expiration time is too close, delaying clear time" ,
139- "baseURL " , cliMgr .cfg . BaseUrl ,
141+ "name " , cliMgr .name ,
140142 "expiredT" , expiredT ,
141143 "adjustedClearTime" , clearTime )
142144 }
143145
144146 waitDuration := time .Until (clearTime )
145147 log .Info ("token expiration monitor started" ,
146- "baseURL " , cliMgr .cfg . BaseUrl ,
148+ "name " , cliMgr .name ,
147149 "expiredT" , expiredT ,
148150 "clearTime" , clearTime ,
149151 "waitDuration" , waitDuration )
@@ -152,10 +154,10 @@ func (cliMgr *ClientManager) Client(ctx context.Context) *upClient {
152154 select {
153155 case <- ctx .Done ():
154156 timer .Stop ()
155- log .Info ("token expiration monitor cancelled" , "baseURL " , cliMgr .cfg . BaseUrl )
157+ log .Info ("token expiration monitor cancelled" , "name " , cliMgr .name )
156158 case <- timer .C :
157159 log .Info ("clearing cached client before token expiration" ,
158- "baseURL " , cliMgr .cfg . BaseUrl ,
160+ "name " , cliMgr .name ,
159161 "expiredT" , expiredT )
160162 cliMgr .clearCachedCli (loginCli )
161163 }
@@ -182,14 +184,14 @@ func (cliMgr *ClientManager) clearCachedCli(cli *upClient) {
182184 if cliMgr .cachedCli .cli == cli {
183185 cliMgr .cachedCli .cli = nil
184186 cliMgr .cachedCli .completionCtx = nil
185- log .Info ("cached client cleared due to forbidden response" , "baseURL " , cliMgr .cfg . BaseUrl )
187+ log .Info ("cached client cleared due to forbidden response" , "name " , cliMgr .name )
186188 }
187189 cliMgr .cachedCli .Unlock ()
188190}
189191
190192func (cliMgr * ClientManager ) OnResp (cli * upClient , resp * http.Response ) {
191193 if resp .StatusCode == http .StatusForbidden {
192- log .Info ("cached client cleared due to forbidden response" , "baseURL " , cliMgr .cfg . BaseUrl )
194+ log .Info ("cached client cleared due to forbidden response" , "name " , cliMgr .name )
193195 cliMgr .clearCachedCli (cli )
194196 }
195197}
0 commit comments