Skip to content

Commit

Permalink
chore: add a validation function for GCS path in gcs_utils.py
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 542054866
  • Loading branch information
vertex-sdk-bot authored and copybara-github committed Jun 20, 2023
1 parent 1b91e9f commit cd67734
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
15 changes: 15 additions & 0 deletions google/cloud/aiplatform/utils/gcs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,18 @@ def _upload_pandas_df_to_gcs(
storage.Blob.from_string(
uri=upload_gcs_path, client=storage_client
).upload_from_filename(filename=local_dataset_path)


def validate_gcs_path(gcs_path: str) -> None:
"""Validates a GCS path.
Args:
gcs_path (str):
Required. A GCS path to validate.
Raises:
ValueError if gcs_path is invalid.
"""
if not gcs_path.startswith("gs://"):
raise ValueError(
f"Invalid GCS path {gcs_path}. Please provide a valid GCS path starting with 'gs://'"
)
11 changes: 11 additions & 0 deletions tests/unit/aiplatform/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,17 @@ def test_create_gcs_bucket_for_pipeline_artifacts_if_it_does_not_exist(
output == "gs://test-project-vertex-pipelines-us-central1/output_artifacts/"
)

def test_validate_gcs_path(self):
test_valid_path = "gs://test_valid_path"
gcs_utils.validate_gcs_path(test_valid_path)

test_invalid_path = "test_invalid_path"
err_msg = re.escape(
f"Invalid GCS path {test_invalid_path}. Please provide a valid GCS path starting with 'gs://'"
)
with pytest.raises(ValueError, match=err_msg):
gcs_utils.validate_gcs_path(test_invalid_path)


class TestPipelineUtils:
SAMPLE_JOB_SPEC = {
Expand Down

0 comments on commit cd67734

Please sign in to comment.