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
9e6d43b5
Commit
9e6d43b5
authored
3 years ago
by
Christian Boettcher
Browse files
Options
Downloads
Patches
Plain Diff
delay some imports, use dict.get() to prevent keyErrors
parent
d50486bf
No related branches found
No related tags found
No related merge requests found
Pipeline
#86420
passed
3 years ago
Stage: test
Stage: build
Stage: publish
Changes
2
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/datacat_integration/connection.py
+7
-7
7 additions, 7 deletions
src/datacat_integration/connection.py
src/datacat_integration/secrets.py
+9
-10
9 additions, 10 deletions
src/datacat_integration/secrets.py
with
16 additions
and
17 deletions
src/datacat_integration/connection.py
+
7
−
7
View file @
9e6d43b5
...
@@ -4,17 +4,17 @@ import json
...
@@ -4,17 +4,17 @@ import json
from
urllib.parse
import
urljoin
from
urllib.parse
import
urljoin
from
airflow.models.connection
import
Connection
import
requests
import
requests
def
get_connection_from_entry
(
data
:
Dict
[
str
,
Any
],
datacat_type
:
str
,
oid
:
str
)
->
Connection
:
def
get_connection_from_entry
(
data
:
Dict
[
str
,
Any
],
datacat_type
:
str
,
oid
:
str
):
"""
returns an airflow 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
'
]
# delay import to prevent circular dependencies during config startup
host
=
data
[
'
metadata
'
][
'
host
'
]
from
airflow.models.connection
import
Connection
port
=
data
[
'
metadata
'
][
'
port
'
]
conn_type
=
data
[
'
metadata
'
].
get
(
'
conn_type
'
)
schema
=
data
[
'
metadata
'
][
'
schema
'
]
host
=
data
[
'
metadata
'
].
get
(
'
host
'
)
port
=
data
[
'
metadata
'
].
get
(
'
port
'
)
schema
=
data
[
'
metadata
'
].
get
(
'
schema
'
)
conn_id
=
f
"
{
datacat_type
}
/
{
oid
}
-connection
"
conn_id
=
f
"
{
datacat_type
}
/
{
oid
}
-connection
"
# set all remaining metadata as extra
# set all remaining metadata as extra
extra
=
{}
extra
=
{}
...
...
This diff is collapsed.
Click to expand it.
src/datacat_integration/secrets.py
+
9
−
10
View file @
9e6d43b5
from
typing
import
Any
,
Dict
,
Set
from
typing
import
Any
,
Dict
,
Set
from
urllib.parse
import
urljoin
from
urllib.parse
import
urljoin
from
airflow.secrets
import
BaseSecretsBackend
from
airflow.secrets
import
BaseSecretsBackend
from
airflow.models.connection
import
Connection
import
requests
import
requests
import
logging
import
logging
...
@@ -11,12 +10,14 @@ connection_backend_type = "airflow_connections"
...
@@ -11,12 +10,14 @@ connection_backend_type = "airflow_connections"
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
class
Empty
:
pass
def
get_connection_with_secrets_from_entry
(
data
:
Dict
[
str
,
Any
],
secrets
:
Dict
[
str
,
str
]
,
datacat_type
:
str
,
oid
:
str
)
->
Connection
:
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
)
conn
.
password
=
secrets
[
'
password
'
]
conn
.
password
=
secrets
.
get
(
'
password
'
)
conn
.
login
=
secrets
[
'
login
'
]
conn
.
login
=
secrets
.
get
(
'
login
'
)
# add all remaining secrets to extra
# add all remaining secrets to extra
extra
=
conn
.
extra
extra
=
conn
.
extra
for
key
in
secrets
.
keys
():
for
key
in
secrets
.
keys
():
...
@@ -76,16 +77,14 @@ class DatacatSecretsBackend(BaseSecretsBackend):
...
@@ -76,16 +77,14 @@ class DatacatSecretsBackend(BaseSecretsBackend):
def
__init__
(
self
,
**
kwargs
):
def
__init__
(
self
,
**
kwargs
):
log
.
debug
(
"
Init of Datacat Secrets Backend
"
)
log
.
debug
(
"
Init of Datacat Secrets Backend
"
)
self
.
url
=
kwargs
[
"
url
"
]
self
.
url
=
kwargs
.
get
(
"
url
"
,
"
http://localhost
"
)
self
.
user
=
kwargs
[
"
user
"
]
self
.
user
=
kwargs
.
get
(
"
user
"
,
""
)
self
.
password
=
kwargs
[
"
password
"
]
self
.
password
=
kwargs
.
get
(
"
password
"
,
""
)
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
"""
# only for testing: check that a specific oid has been requested
log
.
debug
(
f
"
Get connection:
{
conn_id
}
"
)
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
)
secrets_conn
=
DataCatConnectionWithSecrets
(
self
.
url
,
self
.
user
,
self
.
password
)
data
=
secrets_conn
.
get_entry
(
connection_backend_type
,
conn_id
)
data
=
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
register
or
sign in
to comment