Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Airflow Datacat Integration
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
eFlows4HPC WP2
Airflow Datacat Integration
Commits
60826e03
Commit
60826e03
authored
Apr 20, 2022
by
Christian Boettcher
Browse files
Options
Downloads
Patches
Plain Diff
check if conn_is is uuid to prevent failed request
parent
d949a217
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Pipeline
#98070
passed
Apr 20, 2022
Stage: test
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/datacat_integration/secrets.py
+14
-2
14 additions, 2 deletions
src/datacat_integration/secrets.py
with
14 additions
and
2 deletions
src/datacat_integration/secrets.py
+
14
−
2
View file @
60826e03
...
@@ -4,13 +4,22 @@ from airflow.secrets import BaseSecretsBackend
...
@@ -4,13 +4,22 @@ from airflow.secrets import BaseSecretsBackend
import
requests
import
requests
import
logging
import
logging
import
json
import
json
import
uuid
from
datacat_integration.connection
import
DataCatConnection
,
DataCatalogEntry
,
get_connection_from_entry
from
datacat_integration.connection
import
DataCatConnection
,
get_connection_from_entry
connection_backend_type
=
"
airflow_connections
"
connection_backend_type
=
"
airflow_connections
"
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
def
validate_uuid
(
uuid_to_test
:
str
,
version
=
4
):
"""
Check if uuid_to_test id a valid UUID. Returns True if it is and false if it is not.
"""
try
:
uuid_obj
=
uuid
.
UUID
(
uuid_to_test
,
version
=
version
)
except
ValueError
:
return
False
return
str
(
uuid_obj
)
==
uuid_to_test
def
get_connection_with_secrets_from_entry
(
data
:
Dict
[
str
,
Any
],
secrets
:
Dict
[
str
,
str
]
,
datacat_type
:
str
,
oid
:
str
):
def
get_connection_with_secrets_from_entry
(
data
:
Dict
[
str
,
Any
],
secrets
:
Dict
[
str
,
str
]
,
datacat_type
:
str
,
oid
:
str
):
"""
returns an aiflow connection from the data provided in the datacat entry and the secrets.
"""
"""
returns an aiflow connection from the data provided in the datacat entry and the secrets.
"""
conn
=
get_connection_from_entry
(
data
,
datacat_type
,
oid
)
conn
=
get_connection_from_entry
(
data
,
datacat_type
,
oid
)
...
@@ -85,7 +94,10 @@ class DatacatSecretsBackend(BaseSecretsBackend):
...
@@ -85,7 +94,10 @@ class DatacatSecretsBackend(BaseSecretsBackend):
def
get_connection
(
self
,
conn_id
:
str
):
def
get_connection
(
self
,
conn_id
:
str
):
"""
returns a Connection created from the <conenction_type>/<conn_id> entry in the datacatalog
"""
"""
returns a Connection created from the <conenction_type>/<conn_id> entry in the datacatalog
"""
log
.
debug
(
f
"
Get connection:
{
conn_id
}
"
)
log
.
debug
(
f
"
Get connection from datacat secrets backend:
{
conn_id
}
"
)
if
not
validate_uuid
(
conn_id
):
return
None
# can not be a connection in the datacat, immediatly return None to allow airflow to look elsewhere
secrets_conn
=
DataCatConnectionWithSecrets
(
self
.
url
,
self
.
user
,
self
.
password
)
secrets_conn
=
DataCatConnectionWithSecrets
(
self
.
url
,
self
.
user
,
self
.
password
)
data
:
Dict
[
str
,
str
]
=
json
.
loads
(
secrets_conn
.
get_entry
(
connection_backend_type
,
conn_id
))
data
:
Dict
[
str
,
str
]
=
json
.
loads
(
secrets_conn
.
get_entry
(
connection_backend_type
,
conn_id
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment