diff --git a/src/datacat_integration/connection.py b/src/datacat_integration/connection.py index c7f4d2cbb493049cc2c473af0caca47dcc742341..bf2297989116ca6bdbb58f0007254de1ecdf2057 100644 --- a/src/datacat_integration/connection.py +++ b/src/datacat_integration/connection.py @@ -18,7 +18,7 @@ class DataCatalogEntry: self.metadata = metadata def json(self): - """returns a json-compatible representation of the object.""" + """returns a json-compatible representation of the entry.""" return json.dumps( { "name" : self.name, @@ -28,7 +28,7 @@ class DataCatalogEntry: ) def from_json(data: json): - """returns a DataCatalogEntry object from the given json string""" + """returns a DataCatalogEntry entry from the given json string""" dict_data = json.loads(data) return DataCatalogEntry(dict_data['name'], dict_data['url'], dict_data['metadata']) @@ -76,22 +76,22 @@ class DataCatConnection: return self.refresh_token() - def get_object(self, datacat_type: str, oid: uuid.UUID): # GET /<type>/<oid> - """Returns a json of the given object from the server.""" + def get_entry(self, datacat_type: str, oid: uuid.UUID): # GET /<type>/<oid> + """Returns a json of the given entry from the server.""" headers = { 'accept' : 'application/json' } url = urljoin(self.url, "{}/{}".format(datacat_type, oid)) return json.dumps(requests.get(url, headers=headers).json()) - def create_object(self, datacat_type: str, object: DataCatalogEntry): # POST /<type> - """Creates a new object in the datacatalog. Returns the oid of successful.""" + def create_entry(self, datacat_type: str, entry: DataCatalogEntry): # POST /<type> + """Creates a new entry in the datacatalog. Returns the oid of successful.""" headers = { 'accept' : 'application/json', 'Content-Type' : 'application/json', 'Authorization' : 'Bearer {}'.format(self._auth_token) } - response = requests.post(urljoin(self.url, datacat_type), headers=headers, data=object.json()) + response = requests.post(urljoin(self.url, datacat_type), headers=headers, data=entry.json()) if response.ok: return response.json()[0] else: diff --git a/src/datacat_integration/hooks.py b/src/datacat_integration/hooks.py index 542da6ef279721015a7362f92a9a6d81acf087fc..4559234059593ba7ea7717fb902c1c7a432563eb 100644 --- a/src/datacat_integration/hooks.py +++ b/src/datacat_integration/hooks.py @@ -13,7 +13,7 @@ from datacat_integration.auth import BearerAuth def get_connection_from_entry(data: Dict[str, Any], datacat_type: str, oid: str) -> Connection: - """returns an aiflow connection from the data provided in the datacat entry.""" + """returns an airflow connection from the data provided in the datacat entry.""" conn_type = data['metadata']['conn_type'] host = data['metadata']['host'] port = data['metadata']['port'] @@ -51,19 +51,18 @@ class DataCatalogHook(HttpHook): conn.auth = BearerAuth(self.connection.get_token()) return conn - def get_object(self, datacat_type: str, oid: str): - return self.connection.get_object(datacat_type, oid) + def get_entry(self, datacat_type: str, oid: str): + return self.connection.get_entry(datacat_type, oid) - def create_object(self, datacat_type: str, object: DataCatalogEntry): - return self.connection.create_object(datacat_type, object) + def create_entry(self, datacat_type: str, entry: DataCatalogEntry): + return self.connection.create_entry(datacat_type, entry) def list_type(self, datacat_type: str): return self.connection.list_type(datacat_type) - def create_get_object_connection(self, datacat_type: str, oid: str): - object = self.get_object(datacat_type=datacat_type, oid=oid) - # TODO decide some factors, such as connection type - conn = get_connection_from_entry(object, datacat_type, oid) + def create_get_entry_connection(self, datacat_type: str, oid: str): + entry = self.get_entry(datacat_type, oid) + conn = get_connection_from_entry(entry, datacat_type, oid) session = settings.Session() diff --git a/src/datacat_integration/operators.py b/src/datacat_integration/operators.py index 718ee3b01831eba1898d2e289f896e85e04dfee8..660052b4a608f95352b089a4c7281894a35c2b09 100644 --- a/src/datacat_integration/operators.py +++ b/src/datacat_integration/operators.py @@ -15,7 +15,7 @@ class GetDatacatalogEntryOperator(BaseOperator): def execute(self, context): cat_conn = DataCatalogHook('datacatalog') - return cat_conn.get_object(self.datacat_type, self.oid) + return cat_conn.get_entry(self.datacat_type, self.oid) class GetDatacatalogEntryConnectionOperator(BaseOperator): """This task returns the data for an entry in the datacatalog.""" @@ -31,4 +31,4 @@ class GetDatacatalogEntryConnectionOperator(BaseOperator): def execute(self, context): hook = DataCatalogHook("datacatalog") - hook.create_get_object_connection(self.datacat_type, self.oid) \ No newline at end of file + hook.create_get_entry_connection(self.datacat_type, self.oid) \ No newline at end of file diff --git a/src/datacat_integration/secrets.py b/src/datacat_integration/secrets.py index 33d18a3c63ef4b2f076fb85a7025ae618a0ad311..2165b7e486b2c9c05053e7d55129615369e4a7da 100644 --- a/src/datacat_integration/secrets.py +++ b/src/datacat_integration/secrets.py @@ -77,20 +77,19 @@ class DatacatSecretsBackend(BaseSecretsBackend): def __init__(self, **kwargs): log.debug("Init of Datacat Secrets Backend") - super().__init__(**kwargs) self.url = kwargs["url"] self.user = kwargs["user"] self.password = kwargs["password"] def get_connection(self, conn_id: str): - """returns a Connection object created from the <conenction_type>/<conn_id> object in the datacatalog""" + """returns a Connection created from the <conenction_type>/<conn_id> entry in the datacatalog""" # only for testing: check that a specific oid has been requested log.debug(f"Get connection: {conn_id}") if conn_id != "860355e9-975f-4253-9421-1815e20c879b": return None secrets_conn = DataCatConnectionWithSecrets(self.url, self.user, self.password) - data = secrets_conn.get_object(connection_backend_type, conn_id) + data = secrets_conn.get_entry(connection_backend_type, conn_id) secrets = secrets_conn.get_all_secret_key_value(connection_backend_type, conn_id) conn = get_connection_from_entry(data, secrets, connection_backend_type, conn_id) return conn \ No newline at end of file diff --git a/tests/test_connection.py b/tests/test_connection.py index 51c4fe3c9092b4c1b2b1aa7f4552dd3efaae8221..4b23a15d086303f6491e44fa57bc83c106c6edaa 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -45,10 +45,10 @@ class ConnectionTest(TestCase): self.assertEqual(token, token2) - # may fail in future when the testing instance is moved or redeployed - test may need to be updated in that case, since the tested object may no longer exist + # may fail in future when the testing instance is moved or redeployed - test may need to be updated in that case, since the tested entry may no longer exist def test_get_entry(self): connection = DataCatConnection(self.url, self.user, self.password) - entry_json = connection.get_object("storage_target", "7aa3877e-2860-4c65-8d48-3e080ceedca2") + entry_json = connection.get_entry("storage_target", "7aa3877e-2860-4c65-8d48-3e080ceedca2") entry = DataCatalogEntry.from_json(entry_json) self.assertEqual(entry.name, "Yet Another Test Object") self.assertEqual(entry.url, "1234") @@ -58,13 +58,13 @@ class ConnectionTest(TestCase): def test_create_entry(self): connection = DataCatConnection(self.url, self.user, self.password) entry = DataCatalogEntry("foo", "bar", {"1" : "2", "source" : "automated tests", "random" : str(random.getrandbits(32))}) - oid = connection.create_object("storage_target", entry) - entry_from_server = DataCatalogEntry.from_json(connection.get_object("storage_target", oid)) + oid = connection.create_entry("storage_target", entry) + entry_from_server = DataCatalogEntry.from_json(connection.get_entry("storage_target", oid)) self.assertDictEqual(entry.metadata, entry_from_server.metadata) self.assertEqual(entry.name, entry_from_server.name) self.assertEqual(entry.url, entry_from_server.url) - # may fail in future when the testing instance is moved or redeployed - test may need to be updated in that case, since the tested objects may no longer exist + # may fail in future when the testing instance is moved or redeployed - test may need to be updated in that case, since the tested entries may no longer exist def test_list_entries(self): connection = DataCatConnection(self.url, self.user, self.password) entries = connection.list_type("storage_target") @@ -79,4 +79,4 @@ class ConnectionTest(TestCase): self.assertRaises(ConnectionError, connection.refresh_token) connection._auth_token = "foobar" self.assertRaises(ConnectionError, connection.get_token) - self.assertRaises(ConnectionError, connection.create_object, "storage_target", DataCatalogEntry("foo", "bar", {})) \ No newline at end of file + self.assertRaises(ConnectionError, connection.create_entry, "storage_target", DataCatalogEntry("foo", "bar", {})) \ No newline at end of file