Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(ingest): add error on missing config, add a test
  • Loading branch information
aseembansal-gogo committed Sep 12, 2021
commit 89488a23e3549de5cf77223c302b74909d114b82
15 changes: 11 additions & 4 deletions metadata-ingestion/src/datahub/cli/cli_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import logging
import os.path
import sys
import typing
Expand All @@ -10,6 +11,8 @@
import yaml
from pydantic import BaseModel, ValidationError

log = logging.getLogger(__name__)

DEFAULT_GMS_HOST = "http://localhost:8080"
CONDENSED_DATAHUB_CONFIG_PATH = "~/.datahubenv"
DATAHUB_CONFIG_PATH = os.path.expanduser(CONDENSED_DATAHUB_CONFIG_PATH)
Expand Down Expand Up @@ -99,14 +102,18 @@ def get_session_and_host():
session = requests.Session()

gms_host_env, gms_token_env = get_details_from_env()
if not should_skip_config():
if should_skip_config():
gms_host = gms_host_env
gms_token = gms_token_env
else:
ensure_datahub_config()
gms_host_conf, gms_token_conf = get_details_from_config()
gms_host = first_non_null([gms_host_env, gms_host_conf])
gms_token = first_non_null([gms_token_env, gms_token_conf])
else:
gms_host = gms_host_env
gms_token = gms_token_env

if gms_host is None or gms_host == "":
log.error("GMS Host is not set. Use datahub init command or set DATAHUB_GMS_HOST env var")
return None, None

session.headers.update(
{
Expand Down
9 changes: 9 additions & 0 deletions metadata-ingestion/tests/unit/test_cli_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from datahub.cli import cli_utils


def test_first_non_null():
assert cli_utils.first_non_null([]) is None
assert cli_utils.first_non_null([None]) is None
assert cli_utils.first_non_null([None, "1"]) == "1"
assert cli_utils.first_non_null([None, "1", "2"]) == "1"
assert cli_utils.first_non_null(["3", "1", "2"]) == "3"