Пример #1
0
    def __init__(
        self,
        bucket: str,
        access_key: Optional[str],
        secret_key: Optional[str],
        endpoint_url: Optional[str],
        prefix: Optional[str],
        *args: Any,
        **kwargs: Any,
    ) -> None:
        super().__init__(*args, **kwargs)
        import boto3

        self.bucket = bucket
        self.client = boto3.client(
            "s3",
            endpoint_url=endpoint_url,
            aws_access_key_id=access_key,
            aws_secret_access_key=secret_key,
        )
        self.resource = boto3.resource(
            "s3",
            endpoint_url=endpoint_url,
            aws_access_key_id=access_key,
            aws_secret_access_key=secret_key,
        )

        self.prefix = normalize_prefix(prefix)
Пример #2
0
    def __init__(self, bucket: str, prefix: Optional[str], *args: Any,
                 **kwargs: Any) -> None:
        super().__init__(*args, **kwargs)
        import google.cloud.storage

        self.client = google.cloud.storage.Client()
        self.bucket = self.client.bucket(bucket)
        self.prefix = normalize_prefix(prefix)
Пример #3
0
    def __init__(
        self,
        bucket: str,
        prefix: Optional[str] = None,
        temp_dir: Optional[str] = None,
    ) -> None:
        super().__init__(temp_dir if temp_dir is not None else tempfile.gettempdir())
        import google.cloud.storage

        self.client = google.cloud.storage.Client()
        self.bucket = self.client.bucket(bucket)
        self.prefix = normalize_prefix(prefix)
Пример #4
0
def test_storage_prefix_normalization(
    require_secrets: bool,
    tmp_path: Path,
    prefix: Union[None, str],
    expected_storage_prefix: str,
    should_fail: bool,
) -> None:
    """Test various inputs for storage prefix are normalized properly."""

    try:
        observed_prefix = normalize_prefix(prefix)
        assert not should_fail and observed_prefix == expected_storage_prefix
    except ValueError as exc:
        assert should_fail and "prefix must not match" in str(exc)