Exemplo n.º 1
0
    def __init__(
        self,
        hostname,
        services=None,
        region_name=None,
        use_ssl=False,
        localstack_version="latest",
        **kwargs,
    ):

        self.kwargs = kwargs
        self.use_ssl = use_ssl
        self.region_name = region_name
        self._hostname = hostname
        self.localstack_version = localstack_version

        if self.localstack_version != "latest" and utils.get_version_tuple(
                localstack_version) < utils.get_version_tuple("0.11"):
            self.service_ports = constants.LEGACY_SERVICE_PORTS
        else:
            self.service_ports = constants.SERVICE_PORTS

        plugin.manager.hook.contribute_to_session(session=self)
        # If no region was provided, use what botocore defaulted to.
        if not region_name:
            self.region_name = (
                self.botocore.session().get_config_variable("region")
                or constants.DEFAULT_AWS_REGION)

        if services is None:
            self.services = copy(self.service_ports)
        elif isinstance(services, (list, tuple, set)):
            self.services = {}
            for service_name in services:
                try:
                    port = self.service_ports[service_name]
                except KeyError:
                    raise exceptions.ServiceError("unknown service " +
                                                  service_name)
                self.services[service_name] = port
        elif isinstance(services, dict):
            self.services = {}
            for service_name, port in services.items():
                if service_name not in self.service_ports:
                    raise exceptions.ServiceError("unknown service " +
                                                  service_name)
                if port is None:
                    port = self.service_ports[service_name]
                self.services[service_name] = port
        else:
            raise TypeError("unsupported services type: %r" % (services, ))
Exemplo n.º 2
0
    def __init__(self,
                 hostname,
                 services=None,
                 region_name=None,
                 use_ssl=False,
                 localstack_version="latest",
                 **kwargs):

        self.kwargs = kwargs
        self.use_ssl = use_ssl
        self.region_name = region_name
        self._hostname = hostname
        self.localstack_version = localstack_version

        if self.localstack_version != "latest" and utils.get_version_tuple(
                localstack_version) < utils.get_version_tuple("0.11"):
            raise UnsupportedLocalstackVersion()

        plugin.manager.hook.contribute_to_session(session=self)
        # If no region was provided, use what botocore defaulted to.
        if not region_name:
            self.region_name = (
                self.botocore.session().get_config_variable("region")
                or constants.DEFAULT_AWS_REGION)

        if services is None:
            self.services = SERVICES.keys()
        elif isinstance(services, (list, tuple, set)):
            for service_name in services:
                if service_name not in SERVICES:
                    raise exceptions.ServiceError("unknown service " +
                                                  service_name)

            self.services = list(services)
        else:
            raise TypeError("unsupported services type: %r" % (services, ))
Exemplo n.º 3
0
    "iam": 4593,
    "kinesis": 4568,
    "lambda": 4574,
    "logs": 4586,
    "redshift": 4577,
    "route53": 4580,
    "s3": 4572,
    "secretsmanager": 4584,
    "ses": 4579,
    "sns": 4575,
    "sqs": 4576,
    "ssm": 4583,
    "stepfunctions": 4585,
    "sts": 4592,
}

SERVICE_PORTS = {k: 4566 for k in LEGACY_SERVICE_PORTS}

# AWS uses multiple names for some services. Map alias to service name.
SERVICE_ALIASES = {
    "email": "ses",
    "monitoring": "cloudwatch",
    "states": "stepfunctions",
    "streams.dynamodb": "dynamodbstreams",
}

DEFAULT_CONTAINER_START_TIMEOUT = 60
DEFAULT_CONTAINER_STOP_TIMEOUT = 10

BOTOCORE_VERSION = utils.get_version_tuple(botocore.__version__)
Exemplo n.º 4
0
def test_get_version_tuple():
    assert utils.get_version_tuple("1.2.3") == (1, 2, 3)
    with pytest.raises(ValueError):
        utils.get_version_tuple("latest")