Skip to content

Commit

Permalink
pr fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMichaelHu committed Sep 24, 2022
1 parent 506adc8 commit f673696
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 23 deletions.
4 changes: 2 additions & 2 deletions google/cloud/aiplatform/constants/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
_PIPELINE_ERROR_STATES = set([gca_pipeline_state.PipelineState.PIPELINE_STATE_FAILED])

# Pattern for valid names used as a Vertex resource name.
_VALID_NAME_PATTERN = re.compile("^[a-z][-a-z0-9]{0,127}$")
_VALID_NAME_PATTERN = re.compile("^[a-z][-a-z0-9]{0,127}$", re.IGNORECASE)

# Pattern for an Artifact Registry URL.
_VALID_AR_URL = re.compile(r"^https:\/\/([\w-]+)-kfp\.pkg\.dev\/.*")
_VALID_AR_URL = re.compile(r"^https:\/\/([\w-]+)-kfp\.pkg\.dev\/.*", re.IGNORECASE)

# Pattern for any JSON or YAML file over HTTPS.
_VALID_HTTPS_URL = re.compile(r"^https:\/\/([\.\/\w-]+)\/.*(json|yaml|yml)$")
Expand Down
29 changes: 9 additions & 20 deletions google/cloud/aiplatform/utils/yaml_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,14 @@ def load_yaml(
"""
if path.startswith("gs://"):
return _load_yaml_from_gs_uri(path, project, credentials)
elif _VALID_AR_URL.match(path):
return _load_yaml_from_ar_uri(path, credentials)
elif _VALID_HTTPS_URL.match(path):
return _load_yaml_from_https_uri(path)
elif path.startswith("http://") or path.startswith("https://"):
if _VALID_AR_URL.match(path) or _VALID_HTTPS_URL.match(path):
return _load_yaml_from_https_uri(path, credentials)
else:
raise ValueError(
"Invalid HTTPS URI. If not using Artifact Registry, please "
"ensure the URI ends with .json, .yaml, or .yml."
)
else:
return _load_yaml_from_local_file(path)

Expand Down Expand Up @@ -111,7 +115,7 @@ def _load_yaml_from_local_file(file_path: str) -> Dict[str, Any]:
return yaml.safe_load(f)


def _load_yaml_from_ar_uri(
def _load_yaml_from_https_uri(
uri: str,
credentials: Optional[auth_credentials.Credentials] = None,
) -> Dict[str, Any]:
Expand All @@ -137,18 +141,3 @@ def _load_yaml_from_ar_uri(
response = request.urlopen(req)

return yaml.safe_load(response.read().decode("utf-8"))


def _load_yaml_from_https_uri(uri: str) -> Dict[str, Any]:
"""Loads data from a YAML document referenced by an HTTPS URI.
Args:
uri (str):
Required. HTTPS URI for YAML document.
Returns:
A Dict object representing the YAML document.
"""
yaml = _maybe_import_yaml()
response = request.urlopen(uri)
return yaml.safe_load(response.read().decode("utf-8"))
6 changes: 5 additions & 1 deletion tests/unit/aiplatform/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,5 +806,9 @@ def test_load_yaml_from_https_uri(self, mock_request_urlopen):
],
)
def test_load_yaml_from_invalid_uri(self, uri: str):
with pytest.raises(FileNotFoundError):
message = (
"Invalid HTTPS URI. If not using Artifact Registry, please "
"ensure the URI ends with .json, .yaml, or .yml."
)
with pytest.raises(ValueError, match=message):
yaml_utils.load_yaml(uri)

0 comments on commit f673696

Please sign in to comment.