Esempio n. 1
0
def test_parse_simple_raid():
    config = _parse_blockstore_params([
        "raid0:0:MOCKED",
        "raid0:1:POSTGRESQL",
        "raid0:2:s3:s3.example.com:region1:bucketA:key123:S3cr3t",
        "raid0:3:swift:swift.example.com:tenant2:containerB:user123:S3cr3t",
    ])
    assert config == RAID0BlockStoreConfig(blockstores=[
        MockedBlockStoreConfig(),
        PostgreSQLBlockStoreConfig(),
        S3BlockStoreConfig(
            s3_endpoint_url="s3.example.com",
            s3_region="region1",
            s3_bucket="bucketA",
            s3_key="key123",
            s3_secret="S3cr3t",
        ),
        SWIFTBlockStoreConfig(
            swift_authurl="swift.example.com",
            swift_tenant="tenant2",
            swift_container="containerB",
            swift_user="******",
            swift_password="******",
        ),
    ])
Esempio n. 2
0
def test_parse_s3_with_default_endpoint():
    config = _parse_blockstore_params(["s3::region1:bucketA:key123:S3cr3t"])
    assert config == S3BlockStoreConfig(
        s3_endpoint_url=None,
        s3_region="region1",
        s3_bucket="bucketA",
        s3_key="key123",
        s3_secret="S3cr3t",
    )
Esempio n. 3
0
def test_parse_s3():
    config = _parse_blockstore_params(["s3:s3.example.com:region1:bucketA:key123:S3cr3t"])
    assert config == S3BlockStoreConfig(
        s3_endpoint_url="https://s3.example.com",
        s3_region="region1",
        s3_bucket="bucketA",
        s3_key="key123",
        s3_secret="S3cr3t",
    )
Esempio n. 4
0
def test_parse_s3_with_custom_url_scheme():
    config = _parse_blockstore_params(
        ["s3:http\\://s3.example.com:region1:bucketA:key123:\\:S3cr3t\\\\"]
    )
    assert config == S3BlockStoreConfig(
        s3_endpoint_url="http://s3.example.com",
        s3_region="region1",
        s3_bucket="bucketA",
        s3_key="key123",
        s3_secret=":S3cr3t\\",  # Also test escaping in password
    )
Esempio n. 5
0
def _parse_blockstore_param(value):
    if value.upper() == "MOCKED":
        return MockedBlockStoreConfig()
    elif value.upper() == "POSTGRESQL":
        return PostgreSQLBlockStoreConfig()
    else:
        parts = _split_with_escaping(value)
        if parts[0].upper() == "S3":
            try:
                endpoint_url, region, bucket, key, secret = parts[1:]
            except ValueError:
                raise click.BadParameter(
                    "Invalid S3 config, must be `s3:[<endpoint_url>]:<region>:<bucket>:<key>:<secret>`"
                )
            # Provide https by default to avoid anoying escaping for most cases
            if (endpoint_url and not endpoint_url.startswith("http://")
                    and not endpoint_url.startswith("https://")):
                endpoint_url = f"https://{endpoint_url}"
            return S3BlockStoreConfig(
                s3_endpoint_url=endpoint_url or None,
                s3_region=region,
                s3_bucket=bucket,
                s3_key=key,
                s3_secret=secret,
            )

        elif parts[0].upper() == "SWIFT":
            try:
                auth_url, tenant, container, user, password = parts[1:]
            except ValueError:
                raise click.BadParameter(
                    "Invalid SWIFT config, must be `swift:<auth_url>:<tenant>:<container>:<user>:<password>`"
                )
            # Provide https by default to avoid anoying escaping for most cases
            if (auth_url and not auth_url.startswith("http://")
                    and not auth_url.startswith("https://")):
                auth_url = f"https://{auth_url}"
            return SWIFTBlockStoreConfig(
                swift_authurl=auth_url,
                swift_tenant=tenant,
                swift_container=container,
                swift_user=user,
                swift_password=password,
            )
        else:
            raise click.BadParameter(f"Invalid blockstore type `{parts[0]}`")
Esempio n. 6
0
def _parse_blockstore_param(value):
    if value.upper() == "MOCKED":
        return MockedBlockStoreConfig()
    elif value.upper() == "POSTGRESQL":
        return PostgreSQLBlockStoreConfig()
    else:
        parts = value.split(":")
        if parts[0].upper() == "S3":
            try:
                endpoint_url, region, bucket, key, secret = parts[1:]
            except ValueError:
                raise click.BadParameter(
                    "Invalid S3 config, must be `s3:<endpoint_url>:<region>:<bucket>:<key>:<secret>`"
                )
            return S3BlockStoreConfig(
                s3_endpoint_url=endpoint_url or None,
                s3_region=region,
                s3_bucket=bucket,
                s3_key=key,
                s3_secret=secret,
            )

        elif parts[0].upper() == "SWIFT":
            try:
                authurl, tenant, container, user, password = parts[1:]
            except ValueError:
                raise click.BadParameter(
                    "Invalid SWIFT config, must be `swift:<authurl>:<tenant>:<container>:<user>:<password>`"
                )
            return SWIFTBlockStoreConfig(
                swift_authurl=authurl,
                swift_tenant=tenant,
                swift_container=container,
                swift_user=user,
                swift_password=password,
            )
        else:
            raise click.BadParameter(f"Invalid blockstore type `{parts[0]}`")