collibra-connector 1.0.6__tar.gz → 1.0.9__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.
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: collibra-connector
3
- Version: 1.0.6
4
- Summary: A standard Python connector for the Collibra Data Governance Center API.
3
+ Version: 1.0.9
4
+ Summary: An UNOFICIAL standard Python connector for the Collibra Data Governance Center API.
5
5
  Author-email: Raül Dalgamonni <rauldalgamonnialonso@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/rauldaal/collibra-python-connector
7
7
  Project-URL: Bug Tracker, https://github.com/rauldaal/collibra-python-connector
@@ -0,0 +1,39 @@
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
+ Collibra Connector Library
30
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
31
+
32
+ Uses the Collibra API to connect and interact with Collibra's data governance platform.
33
+ This library provides a simple interface to handle connection and URLs
34
+
35
+ """
36
+
37
+ from .connector import CollibraConnector
38
+
39
+ __version__ = "0.1.0"
@@ -0,0 +1,102 @@
1
+ import uuid
2
+ from .Base import BaseAPI
3
+
4
+
5
+ class Asset(BaseAPI):
6
+ def __init__(self, connector):
7
+ super().__init__(connector)
8
+ self.__base_api = connector.api + "/assets"
9
+
10
+ def _get(self, url: str = None, params: dict = None, headers: dict = None):
11
+ """
12
+ Makes a GET request to the asset API.
13
+ :param url: The URL to send the GET request to.
14
+ :param params: Optional parameters to include in the GET request.
15
+ :param headers: Optional headers to include in the GET request.
16
+ :return: The response from the GET request.
17
+ """
18
+ return super()._get(self.__base_api if not url else url, params, headers)
19
+
20
+ def _post(self, url: str, data: dict):
21
+ """
22
+ Makes a POST request to the asset API.
23
+ :param url: The URL to send the POST request to.
24
+ :param data: The data to send in the POST request.
25
+ :return: The response from the POST request.
26
+ """
27
+ return super()._post(url, data)
28
+
29
+ def _handle_response(self, response):
30
+ return super()._handle_response(response)
31
+
32
+ def _uuid_validation(self, id):
33
+ return super()._uuid_validation(id)
34
+
35
+ def get_asset(self, asset_id):
36
+ """
37
+ Retrieves an asset by its ID.
38
+ :param asset_id: The ID of the asset to retrieve.
39
+ :return: Asset details.
40
+ """
41
+ response = self._get(url=f"{self.__base_api}/{asset_id}")
42
+ return self._handle_response(response)
43
+
44
+ def add_asset(
45
+ self,
46
+ name: str,
47
+ domain_id: str,
48
+ display_name: str = None,
49
+ type_id: str = None,
50
+ id: str = None,
51
+ status_id: str = None,
52
+ excluded_from_auto_hyperlink: bool = False,
53
+ type_public_id: str = None,
54
+ ):
55
+ """
56
+ Adds a new asset.
57
+ :param name: The name of the asset.
58
+ :param domain_id: The ID of the domain to which the asset belongs.
59
+ :param display_name: Optional display name for the asset.
60
+ :param type_id: Optional type ID for the asset.
61
+ :param id: Optional ID for the asset.
62
+ :param status_id: Optional status ID for the asset.
63
+ :param excluded_from_auto_hyperlink: Whether the asset is excluded from auto hyperlinking.
64
+ :param type_public_id: Optional public ID for the asset type.
65
+ :return: Details of the created asset.
66
+ """
67
+ # Parameter type validation
68
+ if not name or not domain_id:
69
+ raise ValueError("Name and domain_id are required parameters.")
70
+ if not isinstance(excluded_from_auto_hyperlink, bool):
71
+ raise ValueError("excluded_from_auto_hyperlink must be a boolean value.")
72
+ if type_id and not isinstance(type_id, str):
73
+ raise ValueError("type_id must be a string if provided.")
74
+ if id and not isinstance(id, str):
75
+ raise ValueError("id must be a string if provided.")
76
+ if status_id and not isinstance(status_id, str):
77
+ raise ValueError("status_id must be a string if provided.")
78
+ if type_public_id and not isinstance(type_public_id, str):
79
+ raise ValueError("type_public_id must be a string if provided.")
80
+
81
+ # Check Ids are UUIDS
82
+ if id and self._uuid_validation(id) is False:
83
+ raise ValueError("id must be a valid UUID.")
84
+ if domain_id and self._uuid_validation(domain_id) is False:
85
+ raise ValueError("domain_id must be a valid UUID.")
86
+ if type_id and self._uuid_validation(type_id) is False:
87
+ raise ValueError("type_id must be a valid UUID.")
88
+ if status_id and self._uuid_validation(status_id) is False:
89
+ raise ValueError("status_id must be a valid UUID.")
90
+
91
+ data = {
92
+ "name": name,
93
+ "domainId": domain_id,
94
+ "displayName": display_name,
95
+ "typeId": type_id,
96
+ "id": id,
97
+ "statusId": status_id,
98
+ "excludedFromAutoHyperlink": excluded_from_auto_hyperlink,
99
+ "typePublicId": type_public_id
100
+ }
101
+ response = self._post(url=self.__base_api, data=data)
102
+ return self._handle_response(response)
@@ -0,0 +1,83 @@
1
+ import re
2
+ import requests
3
+ from .Exceptions import (
4
+ UnauthorizedError,
5
+ ForbiddenError,
6
+ NotFoundError,
7
+ ServerError
8
+ )
9
+
10
+
11
+ class BaseAPI:
12
+ def __init__(self, connector):
13
+ self.__connector = connector
14
+ self.__base_api = connector.api
15
+ self.__header = {
16
+ "Content-Type": "application/json",
17
+ "Accept": "application/json"
18
+ }
19
+ self.__params = None
20
+
21
+ def _get(self, url: str = None, params: dict = None, headers: dict = None):
22
+ """
23
+ Makes a GET request to the specified URL.
24
+ :param url: The URL to send the GET request to.
25
+ :param params: Optional parameters to include in the GET request.
26
+ :param headers: Optional headers to include in the GET request.
27
+ :return: The response from the GET request.
28
+ """
29
+ url = self.__base_api if not url else url
30
+ headers = self.__header if not headers else headers
31
+ params = self.__params if not params else params
32
+ return requests.get(
33
+ url,
34
+ auth=self.__connector.auth,
35
+ params=params,
36
+ headers=headers
37
+ )
38
+
39
+ def _post(self, url: str, data: dict, headers: dict = None):
40
+ """
41
+ Makes a POST request to the specified URL with the given data.
42
+ :param url: The URL to send the POST request to.
43
+ :param data: The data to send in the POST request.
44
+ :return: The response from the POST request.
45
+ """
46
+ url = self.__base_api if not url else url
47
+ headers = self.__header if not headers else headers
48
+ if not isinstance(data, dict):
49
+ raise ValueError("Data must be a dictionary")
50
+ if not data:
51
+ raise ValueError("Data cannot be empty")
52
+ return requests.post(
53
+ url,
54
+ auth=self.__connector.auth,
55
+ json=data,
56
+ headers=headers
57
+ )
58
+
59
+ def _handle_response(self, response):
60
+ """
61
+ Handles the response from the API.
62
+ :param response: The response object from the API request.
63
+ :return: The JSON content of the response if successful, otherwise raises an error.
64
+ """
65
+ if response.status_code == 200 or response.status_code == 201:
66
+ return response.json()
67
+ elif response.status_code == 401:
68
+ raise UnauthorizedError("Unauthorized access - invalid credentials" + response.text)
69
+ elif response.status_code == 403:
70
+ raise ForbiddenError("Forbidden access - insufficient permissions" + response.text)
71
+ elif response.status_code == 404:
72
+ raise NotFoundError("The specified resource was not found" + response.text)
73
+ elif response.status_code >= 500:
74
+ raise ServerError("Internal server error - something went wrong on the server" + response.text)
75
+
76
+ def _uuid_validation(self, id: str):
77
+ """
78
+ Validates if the provided ID is a valid UUID.
79
+ :param id: The ID to validate.
80
+ :return: True if the ID is a valid UUID, otherwise raises ValueError.
81
+ """
82
+ pattern = re.compile(r"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$")
83
+ return bool(pattern.match(id))
@@ -0,0 +1,24 @@
1
+
2
+ class CollibraAPIError(Exception):
3
+ """Base exception for Collibra API errors"""
4
+ pass
5
+
6
+
7
+ class UnauthorizedError(CollibraAPIError):
8
+ """Raised when authentication fails"""
9
+ pass
10
+
11
+
12
+ class ForbiddenError(CollibraAPIError):
13
+ """Raised when access is forbidden"""
14
+ pass
15
+
16
+
17
+ class NotFoundError(CollibraAPIError):
18
+ """Raised when resource is not found"""
19
+ pass
20
+
21
+
22
+ class ServerError(CollibraAPIError):
23
+ """Raised when server returns 5xx errors"""
24
+ pass
@@ -0,0 +1,2 @@
1
+ from .Asset import Asset
2
+ from .Base import BaseAPI
@@ -4,6 +4,7 @@ from requests.auth import HTTPBasicAuth
4
4
 
5
5
  from .api import Asset
6
6
 
7
+
7
8
  class CollibraConnector():
8
9
  """
9
10
  This class is used to connect to the Collibra API.
@@ -35,7 +36,7 @@ class CollibraConnector():
35
36
  """Test the connection to Collibra API"""
36
37
  try:
37
38
  response = requests.get(
38
- f"{self.__api}/info",
39
+ f"{self.__api}/auth/sessions/current",
39
40
  auth=self.__auth,
40
41
  timeout=self.__timeout
41
42
  )
@@ -54,4 +55,4 @@ class CollibraConnector():
54
55
 
55
56
  @property
56
57
  def base_url(self):
57
- return self.__base_url
58
+ return self.__base_url
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: collibra-connector
3
- Version: 1.0.6
4
- Summary: A standard Python connector for the Collibra Data Governance Center API.
3
+ Version: 1.0.9
4
+ Summary: An UNOFICIAL standard Python connector for the Collibra Data Governance Center API.
5
5
  Author-email: Raül Dalgamonni <rauldalgamonnialonso@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/rauldaal/collibra-python-connector
7
7
  Project-URL: Bug Tracker, https://github.com/rauldaal/collibra-python-connector
@@ -7,4 +7,8 @@ collibra_connector.egg-info/PKG-INFO
7
7
  collibra_connector.egg-info/SOURCES.txt
8
8
  collibra_connector.egg-info/dependency_links.txt
9
9
  collibra_connector.egg-info/requires.txt
10
- collibra_connector.egg-info/top_level.txt
10
+ collibra_connector.egg-info/top_level.txt
11
+ collibra_connector/api/Asset.py
12
+ collibra_connector/api/Base.py
13
+ collibra_connector/api/Exceptions.py
14
+ collibra_connector/api/__init__.py
@@ -1,10 +1,10 @@
1
1
  [project]
2
2
  name = "collibra-connector"
3
- version = "1.0.6"
3
+ version = "1.0.9"
4
4
  authors = [
5
5
  { name="Raül Dalgamonni", email="rauldalgamonnialonso@gmail.com"},
6
6
  ]
7
- description = "A standard Python connector for the Collibra Data Governance Center API."
7
+ description = "An UNOFICIAL standard Python connector for the Collibra Data Governance Center API."
8
8
  readme = "README.md"
9
9
  requires-python = ">=3.8"
10
10
  classifiers = [
@@ -28,4 +28,4 @@ build-backend = "setuptools.build_meta"
28
28
 
29
29
  [tool.setuptools.packages.find]
30
30
  where = ["."]
31
- include = ["collibra_connector"]
31
+ include = ["collibra_connector", "collibra_connector.api"]
@@ -1,39 +0,0 @@
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
- Collibra Connector Library
30
- ~~~~~~~~~~~~~~~~~~~~~~~~~~
31
-
32
- Uses the Collibra API to connect and interact with Collibra's data governance platform.
33
- This library provides a simple interface to handle connection and URLs
34
-
35
- """
36
-
37
- from .connector import CollibraConnector
38
-
39
- __version__ = "0.1.0"