Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Open Subsurface Data Universe Software
Platform
System
SDKs
Python SDK
Commits
fa50d8e8
Commit
fa50d8e8
authored
Jan 17, 2022
by
harshit aggarwal
Browse files
Create config from environment variables in Azure
parent
24271157
Changes
1
Hide whitespace changes
Inline
Side-by-side
osdu_api/configuration/config_manager.py
View file @
fa50d8e8
...
...
@@ -18,8 +18,9 @@ import os
from
osdu_api.configuration.base_config_manager
import
BaseConfigManager
from
osdu_api.utils.env
import
getenv_by_names
"""
"""
Default Config Manager to work with .ini files.
The .ini file's path can be:
1. passed directely to DefaultConfigManager,
...
...
@@ -31,7 +32,7 @@ If both of this options are not provided, the file 'osdu_api.ini' will be taken
class
DefaultConfigManager
(
BaseConfigManager
):
"""
This configuration manager is used for getting different configurations for OSDU clients.
This configuration manager is used for getting different configurations for OSDU clients.
"""
def
__init__
(
self
,
config_file_path
:
str
=
None
):
...
...
@@ -41,7 +42,7 @@ class DefaultConfigManager(BaseConfigManager):
:param config_file_path: Path to config .ini file; if it is not provided, then 'OSDU_API_CONFIG_INI' env var will be used, defaults to None
:type config_file_path: str, optional
"""
self
.
_parser
=
self
.
_read_config
(
config_file_path
)
self
.
_parser
=
self
.
_read_config
(
config_file_path
)
def
_read_config
(
self
,
config_file_path
:
str
=
None
)
->
configparser
.
ConfigParser
:
"""
...
...
@@ -67,16 +68,37 @@ class DefaultConfigManager(BaseConfigManager):
:return: ConfigParser with parsed configs.
:rtype: configparser.ConfigParser
"""
config_file_path
=
config_file_path
or
os
.
environ
.
get
(
"OSDU_API_CONFIG_INI"
)
or
"osdu_api.ini"
parser
=
configparser
.
ConfigParser
(
os
.
environ
)
config_read_results
=
parser
.
read
(
config_file_path
)
if
not
config_read_results
:
raise
configparser
.
Error
(
f
"Could not find the config file in '
{
config_file_path
}
'."
)
return
parser
env_vars_enabled
=
getenv_by_names
([
"AIRFLOW_VAR_ENV_VARS_ENABLED"
])
if
env_vars_enabled
==
'true'
:
parser
=
configparser
.
ConfigParser
()
parser
[
'environment'
]
=
{
'schema_url'
:
getenv_by_names
([
"AIRFLOW_VAR_CORE__SERVICE__SCHEMA__URL"
]),
'search_url'
:
getenv_by_names
([
"AIRFLOW_VAR_CORE__SERVICE__SEARCH__URL"
]),
'entitlements_url'
:
getenv_by_names
([
"AIRFLOW_VAR_CORE__SERVICE__ENTITLEMENTS__URL"
]),
'ingestion_workflow_url'
:
getenv_by_names
([
"AIRFLOW_VAR_CORE__SERVICE__WORKFLOW__HOST"
]),
'storage_url'
:
getenv_by_names
([
"AIRFLOW_VAR_CORE__SERVICE__STORAGE__URL"
]),
'partition_url'
:
getenv_by_names
([
"AIRFLOW_VAR_CORE__SERVICE__PARTITION__URL"
]),
'dataset_url'
:
getenv_by_names
([
"AIRFLOW_VAR_CORE__SERVICE__DATASET__HOST"
]),
'legal_url'
:
getenv_by_names
([
"AIRFLOW_VAR_CORE__SERVICE__LEGAL__HOST"
]),
'data_workflow_url'
:
getenv_by_names
([
"AIRFLOW_VAR_CORE__SERVICE__DATASET__HOST"
]),
'file_dms_url'
:
getenv_by_names
([
"AIRFLOW_VAR_CORE__SERVICE__FILE__HOST"
])
}
parser
[
'provider'
]
=
{
'name'
:
getenv_by_names
([
"CLOUD_PROVIDER"
])
}
return
parser
else
:
config_file_path
=
config_file_path
or
os
.
environ
.
get
(
"OSDU_API_CONFIG_INI"
)
or
"osdu_api.ini"
parser
=
configparser
.
ConfigParser
(
os
.
environ
)
config_read_results
=
parser
.
read
(
config_file_path
)
if
not
config_read_results
:
raise
configparser
.
Error
(
f
"Could not find the config file in '
{
config_file_path
}
'."
)
return
parser
def
get
(
self
,
section
:
str
,
option
:
str
,
default
:
str
=
None
)
->
str
:
"""
"""
Get config value.
:param section: Section of ini file.
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment