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 os |
7 import threading | 8 import threading |
8 import time | 9 import time |
9 import traceback | 10 import traceback |
10 import urllib | 11 import urllib |
11 | 12 |
12 from utils import net | 13 from utils import net |
13 | 14 |
14 from remote_client_errors import BotCodeError | 15 from remote_client_errors import BotCodeError |
15 from remote_client_errors import InitializationError | 16 from remote_client_errors import InitializationError |
16 from remote_client_errors import InternalError | 17 from remote_client_errors import InternalError |
(...skipping 18 matching lines...) Expand all Loading... |
35 AUTH_HEADERS_EXPIRATION_SEC = 4*60+30 | 36 AUTH_HEADERS_EXPIRATION_SEC = 4*60+30 |
36 | 37 |
37 | 38 |
38 # How long to wait for a response from the server. Must not be greater than | 39 # 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 | 40 # AUTH_HEADERS_EXPIRATION_SEC, since otherwise there's a chance auth headers |
40 # will expire while we wait for connection. | 41 # will expire while we wait for connection. |
41 NET_CONNECTION_TIMEOUT_SEC = 3*60 | 42 NET_CONNECTION_TIMEOUT_SEC = 3*60 |
42 | 43 |
43 | 44 |
44 def createRemoteClient(server, auth, grpc_proxy): | 45 def createRemoteClient(server, auth, grpc_proxy): |
| 46 grpc_proxy = os.environ.get('SWARMING_GRPC_PROXY', grpc_proxy) |
45 if grpc_proxy: | 47 if grpc_proxy: |
46 import remote_client_grpc | 48 import remote_client_grpc |
47 return remote_client_grpc.RemoteClientGrpc(grpc_proxy) | 49 return remote_client_grpc.RemoteClientGrpc(grpc_proxy) |
48 return RemoteClientNative(server, auth) | 50 return RemoteClientNative(server, auth) |
49 | 51 |
50 | 52 |
51 class RemoteClientNative(object): | 53 class RemoteClientNative(object): |
52 """RemoteClientNative knows how to make authenticated calls to the backend. | 54 """RemoteClientNative knows how to make authenticated calls to the backend. |
53 | 55 |
54 It also holds in-memory cache of authentication headers and periodically | 56 It also holds in-memory cache of authentication headers and periodically |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 'account_id': account_id, | 315 'account_id': account_id, |
314 'id': bot_id, | 316 'id': bot_id, |
315 'scopes': scopes, | 317 'scopes': scopes, |
316 'task_id': task_id, | 318 'task_id': task_id, |
317 }) | 319 }) |
318 if not resp: | 320 if not resp: |
319 raise InternalError('Error when minting the token') | 321 raise InternalError('Error when minting the token') |
320 if resp.get('error'): | 322 if resp.get('error'): |
321 raise MintOAuthTokenError(resp['error']) | 323 raise MintOAuthTokenError(resp['error']) |
322 return resp | 324 return resp |
OLD | NEW |