| OLD | NEW |
| 1 # Copyright 2016 The LUCI Authors. All rights reserved. | 1 # Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import base64 | 5 import base64 |
| 6 import logging | 6 import logging |
| 7 import threading | 7 import threading |
| 8 import time | 8 import time |
| 9 import traceback | 9 import traceback |
| 10 import urllib | 10 import urllib |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 # time). On GCE machines it is usually 5 min. | 34 # time). On GCE machines it is usually 5 min. |
| 35 AUTH_HEADERS_EXPIRATION_SEC = 4*60+30 | 35 AUTH_HEADERS_EXPIRATION_SEC = 4*60+30 |
| 36 | 36 |
| 37 | 37 |
| 38 # How long to wait for a response from the server. Must not be greater than | 38 # How long to wait for a response from the server. Must not be greater than |
| 39 # AUTH_HEADERS_EXPIRATION_SEC, since otherwise there's a chance auth headers | 39 # AUTH_HEADERS_EXPIRATION_SEC, since otherwise there's a chance auth headers |
| 40 # will expire while we wait for connection. | 40 # will expire while we wait for connection. |
| 41 NET_CONNECTION_TIMEOUT_SEC = 3*60 | 41 NET_CONNECTION_TIMEOUT_SEC = 3*60 |
| 42 | 42 |
| 43 | 43 |
| 44 def createRemoteClient(server, auth, useGrpc): | 44 def createRemoteClient(server, auth, grpc_proxy): |
| 45 if useGrpc: | 45 if grpc_proxy: |
| 46 import remote_client_grpc | 46 import remote_client_grpc |
| 47 return remote_client_grpc.RemoteClientGrpc(server) | 47 return remote_client_grpc.RemoteClientGrpc(grpc_proxy) |
| 48 return RemoteClientNative(server, auth) | 48 return RemoteClientNative(server, auth) |
| 49 | 49 |
| 50 | 50 |
| 51 class RemoteClientNative(object): | 51 class RemoteClientNative(object): |
| 52 """RemoteClientNative knows how to make authenticated calls to the backend. | 52 """RemoteClientNative knows how to make authenticated calls to the backend. |
| 53 | 53 |
| 54 It also holds in-memory cache of authentication headers and periodically | 54 It also holds in-memory cache of authentication headers and periodically |
| 55 refreshes them (by calling supplied callback, that usually is implemented in | 55 refreshes them (by calling supplied callback, that usually is implemented in |
| 56 terms of bot_config.get_authentication_headers() function). | 56 terms of bot_config.get_authentication_headers() function). |
| 57 | 57 |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 'account_id': account_id, | 313 'account_id': account_id, |
| 314 'id': bot_id, | 314 'id': bot_id, |
| 315 'scopes': scopes, | 315 'scopes': scopes, |
| 316 'task_id': task_id, | 316 'task_id': task_id, |
| 317 }) | 317 }) |
| 318 if not resp: | 318 if not resp: |
| 319 raise InternalError('Error when minting the token') | 319 raise InternalError('Error when minting the token') |
| 320 if resp.get('error'): | 320 if resp.get('error'): |
| 321 raise MintOAuthTokenError(resp['error']) | 321 raise MintOAuthTokenError(resp['error']) |
| 322 return resp | 322 return resp |
| OLD | NEW |