Skip to content
Snippets Groups Projects
Commit f0e4fad9 authored by Jedrzej Rybicki's avatar Jedrzej Rybicki
Browse files

registration with hook. testing

parent d0f64577
No related branches found
No related tags found
No related merge requests found
Pipeline #96994 passed
...@@ -3,6 +3,8 @@ from airflow.models.connection import Connection ...@@ -3,6 +3,8 @@ from airflow.models.connection import Connection
from airflow.operators.bash import BashOperator from airflow.operators.bash import BashOperator
from airflow.providers.http.hooks.http import HttpHook from airflow.providers.http.hooks.http import HttpHook
from airflow.utils.dates import days_ago from airflow.utils.dates import days_ago
from datacat_integration.hooks import DataCatalogHook
from datacat_integration.connection import DataCatalogEntry
default_args = { default_args = {
...@@ -33,33 +35,32 @@ def datacat_registration_example(): ...@@ -33,33 +35,32 @@ def datacat_registration_example():
print("Skipping registration as 'register' parameter is not set") print("Skipping registration as 'register' parameter is not set")
return 0 return 0
connection = Connection.get_connection_from_secrets( hook = DataCatalogHook()
'datacat_connection') print("Connected to datacat via hook", hook.list_type('dataset'))
server = connection.get_uri()
print(f"Registring\n\t{object_url}\n with\n\t {server}")
# auth_type empty to overwrite http basic auth entry = DataCatalogEntry(name=f"DLS results {kwargs['run_id']}",
hook = HttpHook(http_conn_id='datacat_connection', auth_type=lambda x, y: None) url=object_url,
res = hook.run(endpoint='token', metadata= {
data={'username': connection.login, 'password': connection.password} "author": "DLS on behalf of eFlows",
"access": "hook-based"}
) )
try:
if res.status_code != 200: r = hook.create_entry(datacat_type='dataset', entry=entry)
print("Unable to authenticate. Breaking. Check `datacat_conneciton` for creds") print("Hook registration returned: ", r)
return r
except e:
print('Registration failed', e)
return -1 return -1
token = res.json()['access_token'] #r = hook.run(endpoint='dataset', headers=auth_header,
auth_header = {'Authorization': f"Bearer {token}"} # json=get_record(name=f"DLS results {kwargs['run_id']}", url=object_url)
# )
r = hook.run(endpoint='dataset', headers=auth_header, #if r.status_code==200:
json=get_record(name=f"DLS results {kwargs['run_id']}", url=object_url) # d_id = r.json()[0]
) # print(f"Registered sucesfully: {hook.base_url}/dataset/{d_id}")
if r.status_code==200: # return d_id
d_id = r.json()[0] #print(f"Registraton failed: {r.text}")
print(f"Registered sucesfully: {hook.base_url}/dataset/{d_id}") #return -1
return d_id
print(f"Registraton failed: {r.text}")
return -1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment