Exemplo n.º 1
0
    def as_dict(self):
        rtn_dict = {
            "Name": self.name,
            "AccountId": self.account_id,
            "CreateDate": "%.3f" % self.created_time.timestamp(),
            "DatasetName": self.dataset_name,
            "EncryptionMode": self.encryption_mode,
            "Tags": self.tags or dict(),
            "LogSubscription": self.log_subscription,
            "MaxCapacity": self.max_capacity,
            "MaxRetries": self.max_retries,
            "ResourceArn": self.resource_arn,
            "RoleArn": self.role_arn,
            "Type": self.job_type,
        }

        # Add in subclass attributes
        for k in self.local_attrs:
            rtn_dict[camelcase_to_pascal(
                underscores_to_camelcase(k))] = getattr(self, k)

        # Remove items that have a value of None
        rtn_dict = {k: v for k, v in rtn_dict.items() if v is not None}

        return rtn_dict
Exemplo n.º 2
0
 def info_json(self):
     ret = {
         underscores_to_camelcase(k.capitalize()): v
         for k, v in self.__dict__.items()
         if not k.startswith("_")
     }
     return ret
Exemplo n.º 3
0
 def info_json(self):
     ret = {
         underscores_to_camelcase(k.capitalize()): v
         for k, v in self.__dict__.items() if not k.startswith("_")
     }
     ret["SizeInBytes"] = self.size_in_bytes
     ret["NumberOfMountTargets"] = self.number_of_mount_targets
     return ret
Exemplo n.º 4
0
    def create_from_cloudformation_json(
        cls, resource_name, cloudformation_json, region_name
    ):
        properties = cloudformation_json["Properties"]

        elbv2_backend = elbv2_backends[region_name]
        load_balancer_arn = properties.get("LoadBalancerArn")
        protocol = properties.get("Protocol")
        port = properties.get("Port")
        ssl_policy = properties.get("SslPolicy")
        certificates = properties.get("Certificates")
        # transform default actions to confirm with the rest of the code and XML templates
        if "DefaultActions" in properties:
            default_actions = []
            for i, action in enumerate(properties["DefaultActions"]):
                action_type = action["Type"]
                if action_type == "forward":
                    default_actions.append(
                        {
                            "type": action_type,
                            "target_group_arn": action["TargetGroupArn"],
                        }
                    )
                elif action_type in [
                    "redirect",
                    "authenticate-cognito",
                    "fixed-response",
                ]:
                    redirect_action = {"type": action_type}
                    key = (
                        underscores_to_camelcase(
                            action_type.capitalize().replace("-", "_")
                        )
                        + "Config"
                    )
                    for redirect_config_key, redirect_config_value in action[
                        key
                    ].items():
                        # need to match the output of _get_list_prefix
                        redirect_action[
                            camelcase_to_underscores(key)
                            + "._"
                            + camelcase_to_underscores(redirect_config_key)
                        ] = redirect_config_value
                    default_actions.append(redirect_action)
                else:
                    raise InvalidActionTypeError(action_type, i + 1)
        else:
            default_actions = None

        listener = elbv2_backend.create_listener(
            load_balancer_arn, protocol, port, ssl_policy, certificates, default_actions
        )
        return listener
Exemplo n.º 5
0
 def describe_subnets(
     self,
     context: RequestContext,
     request: DescribeSubnetsRequest,
 ) -> DescribeSubnetsResult:
     result = call_moto(context)
     backend = ec2_backends[context.region]
     # add additional/missing attributes in subnet responses
     for subnet in result.get("Subnets", []):
         subnet_obj = backend.subnets[subnet["AvailabilityZone"]][subnet["SubnetId"]]
         for attr in ADDITIONAL_SUBNET_ATTRS:
             if hasattr(subnet_obj, attr):
                 attr_name = first_char_to_upper(underscores_to_camelcase(attr))
                 if attr_name not in subnet:
                     subnet[attr_name] = getattr(subnet_obj, attr)
     return result
Exemplo n.º 6
0
    def info_json(self):
        ret = {
            underscores_to_camelcase(k.capitalize()): v
            for k, v in self.__dict__.items() if not k.startswith("_")
        }
        tags = self._context.list_tags_for_resource(self.file_system_id)
        name = ""
        for tag in tags:
            if tag["Key"] == "Name":
                name = tag["Value"]
                break

        ret.update(
            Tags=tags,
            SizeInBytes=self.size_in_bytes,
            NumberOfMountTargets=self.number_of_mount_targets,
            Name=name,
        )
        return ret
Exemplo n.º 7
0
    def create_from_cloudformation_json(cls, resource_name,
                                        cloudformation_json, region_name):
        properties = cloudformation_json["Properties"]

        elbv2_backend = elbv2_backends[region_name]
        listener_arn = properties.get("ListenerArn")
        priority = properties.get("Priority")
        conditions = properties.get("Conditions")

        default_actions = []
        for i, action in enumerate(properties["Actions"]):
            action_type = action["Type"]
            if action_type == "forward":
                default_actions.append({
                    "type":
                    action_type,
                    "target_group_arn":
                    action["TargetGroupArn"],
                })
            elif action_type in [
                    "redirect",
                    "authenticate-cognito",
                    "fixed-response",
            ]:
                redirect_action = {"type": action_type}
                key = (underscores_to_camelcase(
                    action_type.capitalize().replace("-", "_")) + "Config")
                for redirect_config_key, redirect_config_value in action[
                        key].items():
                    # need to match the output of _get_list_prefix
                    redirect_action[
                        camelcase_to_underscores(key) + "._" +
                        camelcase_to_underscores(
                            redirect_config_key)] = redirect_config_value
                default_actions.append(redirect_action)
            else:
                raise InvalidActionTypeError(action_type, i + 1)

        listener_rule = elbv2_backend.create_rule(listener_arn, conditions,
                                                  priority, default_actions)
        return listener_rule
Exemplo n.º 8
0
 def __init__(self, event_id, event_type, event_timestamp=None, **kwargs):
     if event_type not in SUPPORTED_HISTORY_EVENT_TYPES:
         raise NotImplementedError(
             "HistoryEvent does not implement attributes for type '{0}'".format(event_type)
         )
     self.event_id = event_id
     self.event_type = event_type
     if event_timestamp:
         self.event_timestamp = event_timestamp
     else:
         self.event_timestamp = unix_time()
     # pre-populate a dict: {"camelCaseKey": value}
     self.event_attributes = {}
     for key, value in kwargs.items():
         if value:
             camel_key = underscores_to_camelcase(key)
             if key == "task_list":
                 value = {"name": value}
             elif key == "workflow_type":
                 value = {"name": value.name, "version": value.version}
             elif key == "activity_type":
                 value = value.to_short_dict()
             self.event_attributes[camel_key] = value
Exemplo n.º 9
0
 def __init__(self, event_id, event_type, event_timestamp=None, **kwargs):
     if event_type not in SUPPORTED_HISTORY_EVENT_TYPES:
         raise NotImplementedError(
             "HistoryEvent does not implement attributes for type '{0}'".
             format(event_type))
     self.event_id = event_id
     self.event_type = event_type
     if event_timestamp:
         self.event_timestamp = event_timestamp
     else:
         self.event_timestamp = unix_time()
     # pre-populate a dict: {"camelCaseKey": value}
     self.event_attributes = {}
     for key, value in kwargs.items():
         if value:
             camel_key = underscores_to_camelcase(key)
             if key == "task_list":
                 value = {"name": value}
             elif key == "workflow_type":
                 value = {"name": value.name, "version": value.version}
             elif key == "activity_type":
                 value = value.to_short_dict()
             self.event_attributes[camel_key] = value
Exemplo n.º 10
0
    def receive_message(self):
        queue_name = self._get_queue_name()
        message_attributes = self._get_multi_param("message_attributes")
        if not message_attributes:
            message_attributes = extract_input_message_attributes(self.querystring)

        attribute_names = self._get_multi_param("AttributeName")

        queue = self.sqs_backend.get_queue(queue_name)

        try:
            message_count = int(self.querystring.get("MaxNumberOfMessages")[0])
        except TypeError:
            message_count = DEFAULT_RECEIVED_MESSAGES

        if message_count < 1 or message_count > 10:
            return self._error(
                "InvalidParameterValue",
                "An error occurred (InvalidParameterValue) when calling "
                "the ReceiveMessage operation: Value %s for parameter "
                "MaxNumberOfMessages is invalid. Reason: must be between "
                "1 and 10, if provided." % message_count,
            )

        try:
            wait_time = int(self.querystring.get("WaitTimeSeconds")[0])
        except TypeError:
            wait_time = int(queue.receive_message_wait_time_seconds)

        if wait_time < 0 or wait_time > 20:
            return self._error(
                "InvalidParameterValue",
                "An error occurred (InvalidParameterValue) when calling "
                "the ReceiveMessage operation: Value %s for parameter "
                "WaitTimeSeconds is invalid. Reason: must be &lt;= 0 and "
                "&gt;= 20 if provided." % wait_time,
            )

        try:
            visibility_timeout = self._get_validated_visibility_timeout()
        except TypeError:
            visibility_timeout = queue.visibility_timeout
        except ValueError:
            return ERROR_MAX_VISIBILITY_TIMEOUT_RESPONSE, dict(status=400)

        messages = self.sqs_backend.receive_messages(
            queue_name, message_count, wait_time, visibility_timeout, message_attributes
        )

        attributes = {
            "approximate_first_receive_timestamp": False,
            "approximate_receive_count": False,
            "message_deduplication_id": False,
            "message_group_id": False,
            "sender_id": False,
            "sent_timestamp": False,
            "sequence_number": False,
        }

        for attribute in attributes:
            pascalcase_name = camelcase_to_pascal(underscores_to_camelcase(attribute))
            if any(x in ["All", pascalcase_name] for x in attribute_names):
                attributes[attribute] = True

        template = self.response_template(RECEIVE_MESSAGE_RESPONSE)
        return template.render(messages=messages, attributes=attributes)
Exemplo n.º 11
0
def test_underscores_to_camelcase():
    cases = {
        "the_new_attribute": "theNewAttribute",
    }
    for arg, expected in cases.items():
        underscores_to_camelcase(arg).should.equal(expected)
Exemplo n.º 12
0
def test_underscores_to_camelcase(input, expected):
    underscores_to_camelcase(input).should.equal(expected)