Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(json-schema): do not send invalid URLs #9417

Merged
merged 5 commits into from
Dec 12, 2023
Merged
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from os.path import basename, dirname
from pathlib import Path
from typing import Any, Iterable, List, Optional, Union
from urllib.parse import urlparse

import jsonref
from pydantic import AnyHttpUrl, DirectoryPath, FilePath, validator
Expand Down Expand Up @@ -53,6 +54,16 @@
logger = logging.getLogger(__name__)


def is_url_valid(url: Optional[str]) -> bool:
if url is None:
return False
try:
result = urlparse(url)
return all([result.scheme, result.netloc])
except Exception:
return False


class URIReplacePattern(ConfigModel):
match: str = Field(
description="Pattern to match on uri-s as part of reference resolution. See replace field",
Expand Down Expand Up @@ -281,12 +292,14 @@ def _load_one_file(
entityUrn=dataset_urn, aspect=models.StatusClass(removed=False)
).as_workunit()

external_url = JsonSchemaTranslator._get_id_from_any_schema(schema_dict)
if not is_url_valid(external_url):
external_url = None

yield MetadataChangeProposalWrapper(
entityUrn=dataset_urn,
aspect=models.DatasetPropertiesClass(
externalUrl=JsonSchemaTranslator._get_id_from_any_schema(
schema_dict
),
externalUrl=external_url,
name=dataset_simple_name,
description=JsonSchemaTranslator._get_description_from_any_schema(
schema_dict
Expand Down
Loading