get-conn-by-id 0.0.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- get_conn_by_id-0.0.4/LICENSE +21 -0
- get_conn_by_id-0.0.4/PKG-INFO +33 -0
- get_conn_by_id-0.0.4/get_conn_by_id/__init__.py +38 -0
- get_conn_by_id-0.0.4/get_conn_by_id/__version__.py +8 -0
- get_conn_by_id-0.0.4/get_conn_by_id/get_conn_by_id_airflow/__init__.py +47 -0
- get_conn_by_id-0.0.4/get_conn_by_id/get_conn_by_id_json/__init__.py +25 -0
- get_conn_by_id-0.0.4/get_conn_by_id/get_conn_by_id_json/get_credential_url/__init__.py +17 -0
- get_conn_by_id-0.0.4/get_conn_by_id/get_conn_by_id_json/get_credential_url/databricks/__init__.py +10 -0
- get_conn_by_id-0.0.4/get_conn_by_id/get_conn_by_id_json/get_credential_url/local/__init__.py +13 -0
- get_conn_by_id-0.0.4/get_conn_by_id/get_conn_by_id_synapse/__init__.py +15 -0
- get_conn_by_id-0.0.4/get_conn_by_id/get_conn_by_id_synapse/connect_lake_and_fetch_json/__init__.py +19 -0
- get_conn_by_id-0.0.4/get_conn_by_id/get_conn_by_id_synapse/datalake/__init__.py +7 -0
- get_conn_by_id-0.0.4/get_conn_by_id.egg-info/PKG-INFO +33 -0
- get_conn_by_id-0.0.4/get_conn_by_id.egg-info/SOURCES.txt +16 -0
- get_conn_by_id-0.0.4/get_conn_by_id.egg-info/dependency_links.txt +1 -0
- get_conn_by_id-0.0.4/get_conn_by_id.egg-info/top_level.txt +1 -0
- get_conn_by_id-0.0.4/pyproject.toml +41 -0
- get_conn_by_id-0.0.4/setup.cfg +4 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 Cody Xiaozhan Yang
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,33 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: get_conn_by_id
|
3
|
+
Version: 0.0.4
|
4
|
+
Summary: A library used to get the connections from different environments.
|
5
|
+
Author-email: Cody Xiaozhan Yang <x.yang@cloudfmgroup.com>
|
6
|
+
License: MIT License
|
7
|
+
|
8
|
+
Copyright (c) 2025 Cody Xiaozhan Yang
|
9
|
+
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
12
|
+
in the Software without restriction, including without limitation the rights
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
15
|
+
furnished to do so, subject to the following conditions:
|
16
|
+
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
18
|
+
copies or substantial portions of the Software.
|
19
|
+
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
26
|
+
SOFTWARE.
|
27
|
+
Keywords: connections
|
28
|
+
Classifier: Programming Language :: Python :: 3
|
29
|
+
Classifier: License :: OSI Approved :: MIT License
|
30
|
+
Classifier: Operating System :: OS Independent
|
31
|
+
Requires-Python: >=3.8
|
32
|
+
License-File: LICENSE
|
33
|
+
Dynamic: license-file
|
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
from .get_conn_by_id_json import get_conn_by_id_json
|
3
|
+
|
4
|
+
def get_conn_by_id(conn_id,
|
5
|
+
account_key=None,
|
6
|
+
credential_url=None):
|
7
|
+
|
8
|
+
# # fetching creds from local filesystem or datalake
|
9
|
+
# cred_conn = get_conn_by_id_json(conn_id,
|
10
|
+
# credential_url=credential_url)
|
11
|
+
|
12
|
+
# if cred_conn != None:
|
13
|
+
# return cred_conn
|
14
|
+
# else:
|
15
|
+
# # fetching creds from the airflow environment
|
16
|
+
# from .get_conn_by_id_airflow import get_conn_by_id_airflow
|
17
|
+
|
18
|
+
# cred_conn = get_conn_by_id_airflow(conn_id)
|
19
|
+
|
20
|
+
# for testing
|
21
|
+
cred_conn = None
|
22
|
+
|
23
|
+
if cred_conn != None:
|
24
|
+
return cred_conn
|
25
|
+
else:
|
26
|
+
# fetching creds from the synapse environment
|
27
|
+
from .get_conn_by_id_synapse import get_conn_by_id_synapse
|
28
|
+
|
29
|
+
if account_key is None:
|
30
|
+
raise Exception('Please provide a valid account_key for getting credentials in the synapse environment')
|
31
|
+
|
32
|
+
cred_conn = get_conn_by_id_synapse(conn_id, account_key)
|
33
|
+
return cred_conn
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
|
@@ -0,0 +1,8 @@
|
|
1
|
+
|
2
|
+
__version__ = '0.0.3' # can set multiple paths for local and databricks
|
3
|
+
|
4
|
+
# __version__ = '0.0.2' # being able to get conn from local, airflow, and databricks
|
5
|
+
|
6
|
+
# __version__ = '0.0.1' # require two functions for getting the conn
|
7
|
+
|
8
|
+
# __version__ = '0.0.0' # the basic way for getting conn only from airflow
|
@@ -0,0 +1,47 @@
|
|
1
|
+
|
2
|
+
import inspect
|
3
|
+
from airflow.hooks.base_hook import BaseHook
|
4
|
+
import json
|
5
|
+
|
6
|
+
def get_conn_by_id_airflow(conn_id):
|
7
|
+
|
8
|
+
cred_conn = BaseHook.get_connection(conn_id)
|
9
|
+
|
10
|
+
cred_dict = {}
|
11
|
+
for attribute in dir(cred_conn):
|
12
|
+
print(cred_conn, 'attr: ', attribute)
|
13
|
+
|
14
|
+
if not attribute.startswith('__'):
|
15
|
+
if not inspect.ismethod(attribute):
|
16
|
+
cred_dict[attribute] = getattr(cred_conn, attribute)
|
17
|
+
if attribute == 'schema':
|
18
|
+
cred_dict['database'] = getattr(cred_conn, attribute)
|
19
|
+
elif attribute == 'login':
|
20
|
+
cred_dict['username'] = getattr(cred_conn, attribute)
|
21
|
+
cred_dict['client_id'] = getattr(cred_conn, attribute)
|
22
|
+
|
23
|
+
cred_dict['password'] = cred_conn.get_password()
|
24
|
+
cred_dict['token'] = cred_conn.get_password()
|
25
|
+
cred_dict['api_key'] = cred_conn.get_password()
|
26
|
+
cred_dict['secret'] = cred_conn.get_password()
|
27
|
+
|
28
|
+
cred_extra = cred_conn.get_extra()
|
29
|
+
|
30
|
+
if len(cred_extra) > 2:
|
31
|
+
cred_extra_json = json.loads(cred_extra)
|
32
|
+
|
33
|
+
cred_dict = {**cred_dict, **cred_extra_json}
|
34
|
+
|
35
|
+
print('cred_dict: ', cred_dict)
|
36
|
+
|
37
|
+
return cred_dict
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
# server = email_conn.host
|
44
|
+
# port = email_conn.port
|
45
|
+
# send_from = json.loads(email_conn.get_extra())["send_from"]
|
46
|
+
# username = email_conn.login
|
47
|
+
# password = email_conn.get_password()
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import json
|
2
|
+
from .get_credential_url import get_credential_url
|
3
|
+
|
4
|
+
def get_conn_by_id_json(conn_id,
|
5
|
+
credential_url=None):
|
6
|
+
|
7
|
+
if credential_url == None:
|
8
|
+
credential_url = get_credential_url()
|
9
|
+
|
10
|
+
if credential_url == None: # if there is no credential_url from localhost or databricks
|
11
|
+
return None
|
12
|
+
|
13
|
+
with open(credential_url) as f:
|
14
|
+
credentials = json.load(f)
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
for connection in credentials['connections']:
|
19
|
+
if connection['connection_id'] == conn_id:
|
20
|
+
return connection['secrets']
|
21
|
+
|
22
|
+
print('[INFO]: cannot found the connection_id!')
|
23
|
+
return None # if there is no such credential id yet
|
24
|
+
|
25
|
+
# raise('cannot found the connection_id!')
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import os
|
2
|
+
|
3
|
+
from . import databricks
|
4
|
+
from . import local
|
5
|
+
|
6
|
+
def get_credential_url():
|
7
|
+
|
8
|
+
for local_credential_url in local.credential_urls:
|
9
|
+
if os.path.exists(local_credential_url):
|
10
|
+
return local_credential_url
|
11
|
+
|
12
|
+
for databricks_credential_url in databricks.credential_urls:
|
13
|
+
if os.path.exists(databricks_credential_url):
|
14
|
+
return databricks_credential_url
|
15
|
+
|
16
|
+
print("[INFO]: Cannot find credentials from local server or databricks!")
|
17
|
+
return None
|
get_conn_by_id-0.0.4/get_conn_by_id/get_conn_by_id_json/get_credential_url/databricks/__init__.py
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
# import os
|
4
|
+
|
5
|
+
# from pathlib import Path
|
6
|
+
# cache_directory = os.path.join(os.path.dirname(__file__), '_cache_/')
|
7
|
+
|
8
|
+
credential_urls = ['/dbfs/FileStore/shared_uploads/x.yang@cloudfmgroup.com/credentials/credentials.json']
|
9
|
+
|
10
|
+
# print('credential_url: ', credential_url)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
import os
|
4
|
+
|
5
|
+
# from pathlib import Path
|
6
|
+
# cache_directory = os.path.join(os.path.dirname(__file__), '_cache_/')
|
7
|
+
|
8
|
+
# credential_url = os.path.join(os.path.dirname(__file__), 'credentials.json')
|
9
|
+
|
10
|
+
credential_urls = ['/Volumes/EXT SSD/Cloudfm Backup/Documents at Cloudfm/Accounts/credentials/credentials.json',
|
11
|
+
'/Volumes/macOS 1/Users/Shared/Cloudfm Backup/OneDrive - Cloudfm Integrated Services Ltd - Backup/KTP Project/Cloudfm/Accounts/credentials/credentials.json']
|
12
|
+
|
13
|
+
# '/dbfs/FileStore/shared_uploads/x.yang@cloudfmgroup.com/credentials_/credentials.json'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
from . import datalake
|
2
|
+
from .connect_lake_and_fetch_json import connect_lake_and_fetch_json
|
3
|
+
|
4
|
+
def get_conn_by_id_synapse(conn_id, account_key):
|
5
|
+
|
6
|
+
credentials = connect_lake_and_fetch_json(datalake, account_key)
|
7
|
+
|
8
|
+
for connection in credentials['connections']:
|
9
|
+
if connection['connection_id'] == conn_id:
|
10
|
+
return connection['secrets']
|
11
|
+
|
12
|
+
print('[INFO]: cannot found the connection_id!')
|
13
|
+
return None # if there is no such credential id yet
|
14
|
+
|
15
|
+
# raise('cannot found the connection_id!')
|
get_conn_by_id-0.0.4/get_conn_by_id/get_conn_by_id_synapse/connect_lake_and_fetch_json/__init__.py
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
from azure.storage.filedatalake import DataLakeServiceClient
|
3
|
+
import io
|
4
|
+
import json
|
5
|
+
|
6
|
+
|
7
|
+
def connect_lake_and_fetch_json(datalake, account_key):
|
8
|
+
|
9
|
+
# connect to the datalake and fetch the json file
|
10
|
+
azure_service_client = DataLakeServiceClient(account_url="{}://{}.dfs.core.windows.net".format(
|
11
|
+
"https", datalake.account_name), credential=account_key)
|
12
|
+
|
13
|
+
azure_file_system_client = azure_service_client.get_file_system_client(file_system=datalake.container_name)
|
14
|
+
|
15
|
+
file_client = azure_file_system_client.get_file_client(datalake.file_path)
|
16
|
+
data = file_client.download_file().readall()
|
17
|
+
json_dict = json.load(io.BytesIO(data))
|
18
|
+
|
19
|
+
return json_dict
|
@@ -0,0 +1,33 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: get_conn_by_id
|
3
|
+
Version: 0.0.4
|
4
|
+
Summary: A library used to get the connections from different environments.
|
5
|
+
Author-email: Cody Xiaozhan Yang <x.yang@cloudfmgroup.com>
|
6
|
+
License: MIT License
|
7
|
+
|
8
|
+
Copyright (c) 2025 Cody Xiaozhan Yang
|
9
|
+
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
12
|
+
in the Software without restriction, including without limitation the rights
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
15
|
+
furnished to do so, subject to the following conditions:
|
16
|
+
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
18
|
+
copies or substantial portions of the Software.
|
19
|
+
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
26
|
+
SOFTWARE.
|
27
|
+
Keywords: connections
|
28
|
+
Classifier: Programming Language :: Python :: 3
|
29
|
+
Classifier: License :: OSI Approved :: MIT License
|
30
|
+
Classifier: Operating System :: OS Independent
|
31
|
+
Requires-Python: >=3.8
|
32
|
+
License-File: LICENSE
|
33
|
+
Dynamic: license-file
|
@@ -0,0 +1,16 @@
|
|
1
|
+
LICENSE
|
2
|
+
pyproject.toml
|
3
|
+
get_conn_by_id/__init__.py
|
4
|
+
get_conn_by_id/__version__.py
|
5
|
+
get_conn_by_id.egg-info/PKG-INFO
|
6
|
+
get_conn_by_id.egg-info/SOURCES.txt
|
7
|
+
get_conn_by_id.egg-info/dependency_links.txt
|
8
|
+
get_conn_by_id.egg-info/top_level.txt
|
9
|
+
get_conn_by_id/get_conn_by_id_airflow/__init__.py
|
10
|
+
get_conn_by_id/get_conn_by_id_json/__init__.py
|
11
|
+
get_conn_by_id/get_conn_by_id_json/get_credential_url/__init__.py
|
12
|
+
get_conn_by_id/get_conn_by_id_json/get_credential_url/databricks/__init__.py
|
13
|
+
get_conn_by_id/get_conn_by_id_json/get_credential_url/local/__init__.py
|
14
|
+
get_conn_by_id/get_conn_by_id_synapse/__init__.py
|
15
|
+
get_conn_by_id/get_conn_by_id_synapse/connect_lake_and_fetch_json/__init__.py
|
16
|
+
get_conn_by_id/get_conn_by_id_synapse/datalake/__init__.py
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
get_conn_by_id
|
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
[build-system]
|
3
|
+
requires = ["setuptools>=61.0", "wheel", "setuptools-git-versioning>=2.0,<3"]
|
4
|
+
build-backend = "setuptools.build_meta"
|
5
|
+
|
6
|
+
[project]
|
7
|
+
name = "get_conn_by_id"
|
8
|
+
dynamic = ["version"]
|
9
|
+
authors = [
|
10
|
+
{ name="Cody Xiaozhan Yang", email="x.yang@cloudfmgroup.com" },
|
11
|
+
]
|
12
|
+
description = "A library used to get the connections from different environments."
|
13
|
+
keywords = ["connections"]
|
14
|
+
# readme = "README.md"
|
15
|
+
requires-python = ">=3.8"
|
16
|
+
classifiers = [
|
17
|
+
"Programming Language :: Python :: 3",
|
18
|
+
"License :: OSI Approved :: MIT License",
|
19
|
+
"Operating System :: OS Independent",
|
20
|
+
]
|
21
|
+
license = {file = "LICENSE"}
|
22
|
+
|
23
|
+
[tool.setuptools-git-versioning]
|
24
|
+
enabled = true
|
25
|
+
version_file = "VERSION"
|
26
|
+
# count_commits_from_version_file = true
|
27
|
+
# dev_template = "{tag}.{ccount}" # <--- note {branch} here
|
28
|
+
# dirty_template = "{tag}.{ccount}"
|
29
|
+
# version_callback = "fetch_sharepoint_info.version:get_version"
|
30
|
+
|
31
|
+
# [tool.setuptools.dynamic]
|
32
|
+
# version = {attr = "__version__"}
|
33
|
+
|
34
|
+
# [project.urls]
|
35
|
+
# Homepage = "https://github.com/pypa/sampleproject"
|
36
|
+
# Issues = "https://github.com/pypa/sampleproject/issues"
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
# [tool.setuptools_scm]
|
41
|
+
# version_file = "cache_return/_version.py"
|