From 4188380fb7b806640103f557afec344455787a34 Mon Sep 17 00:00:00 2001 From: Michael Hwang Date: Fri, 15 Sep 2017 13:41:58 -0400 Subject: Make server url into a user inputted config param Change-Id: I90e94445fe0f3c003307355cade493e97d0a202d Issue-Id: DCAEGEN2-110 Signed-off-by: Michael Hwang --- dcae-cli/dcae_cli/catalog/mock/schema.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'dcae-cli/dcae_cli/catalog/mock') diff --git a/dcae-cli/dcae_cli/catalog/mock/schema.py b/dcae-cli/dcae_cli/catalog/mock/schema.py index a85d11f..a27346b 100644 --- a/dcae-cli/dcae_cli/catalog/mock/schema.py +++ b/dcae-cli/dcae_cli/catalog/mock/schema.py @@ -29,7 +29,7 @@ import six from jsonschema import validate, ValidationError import requests -from dcae_cli.util import reraise_with_msg +from dcae_cli.util import reraise_with_msg, fetch_file_from_web from dcae_cli.util import config as cli_config from dcae_cli.util.exc import DcaeException from dcae_cli.util.logger import get_logger @@ -61,25 +61,19 @@ log = get_logger('Schema') # c) Both # -# TODO: Source this from app's configuration [ONAP URL TBD] -_nexus_uri = "http://make-me-valid" class FetchSchemaError(RuntimeError): pass -def _fetch_schema_from_web(server_uri, schema_path): +def _fetch_schema(schema_path): try: - schema_url = "{0}/{1}".format(server_uri, schema_path) - r = requests.get(schema_url) - r.raise_for_status() - return json.loads(r.text) + server_url = cli_config.get_server_url() + return fetch_file_from_web(server_url, schema_path) except requests.HTTPError as e: raise FetchSchemaError("HTTP error from fetching schema", e) except Exception as e: raise FetchSchemaError("Unexpected error from fetching schema", e) -_fetch_schema_from_nexus = partial(_fetch_schema_from_web, _nexus_uri) - def _safe_dict(obj): '''Returns a dict from a dict or json string''' @@ -113,7 +107,7 @@ def _validate(fetch_schema_func, schema_path, spec): except FetchSchemaError as e: reraise_with_msg(e, as_dcae=True) -_validate_using_nexus = partial(_validate, _fetch_schema_from_nexus) +_validate_using_nexus = partial(_validate, _fetch_schema) _path_component_spec = cli_config.get_path_component_spec() @@ -165,7 +159,7 @@ def apply_defaults_docker_config(config): """ # Apply health check defaults healthcheck_type = config["healthcheck"]["type"] - component_spec = _fetch_schema_from_nexus(_path_component_spec) + component_spec = _fetch_schema(_path_component_spec) if healthcheck_type in ["http", "https"]: apply_defaults_func = partial(apply_defaults, -- cgit 1.2.3-korg