-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy path__init__.py
49 lines (38 loc) · 1.64 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Copyright Contributors to the Amundsen project.
# SPDX-License-Identifier: Apache-2.0
from threading import Lock
from flask import current_app
from werkzeug.utils import import_string
from metadata_service import config
from metadata_service.proxy.base_proxy import BaseProxy
_proxy_client = None
_proxy_client_lock = Lock()
def get_proxy_client() -> BaseProxy:
"""
Provides singleton proxy client based on the config
:return: Proxy instance of any subclass of BaseProxy
"""
global _proxy_client
if _proxy_client:
return _proxy_client
with _proxy_client_lock:
if _proxy_client:
return _proxy_client
else:
# Gather all the configuration to create a Proxy Client
host = current_app.config[config.PROXY_HOST]
port = current_app.config[config.PROXY_PORT]
user = current_app.config[config.PROXY_USER]
password = current_app.config[config.PROXY_PASSWORD]
encrypted = current_app.config[config.PROXY_ENCRYPTED]
validate_ssl = current_app.config[config.PROXY_VALIDATE_SSL]
client_kwargs = current_app.config[config.PROXY_CLIENT_KWARGS]
client = import_string(current_app.config[config.PROXY_CLIENT])
_proxy_client = client(host=host,
port=port,
user=user,
password=password,
encrypted=encrypted,
validate_ssl=validate_ssl,
client_kwargs=client_kwargs)
return _proxy_client