• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

localstack / localstack / 21697093787

04 Feb 2026 09:56PM UTC coverage: 86.962% (-0.004%) from 86.966%
21697093787

push

github

web-flow
improve system information sent in session and container_info (#13680)

10 of 17 new or added lines in 2 files covered. (58.82%)

222 existing lines in 17 files now uncovered.

70560 of 81139 relevant lines covered (86.96%)

0.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.88
/localstack-core/localstack/services/s3control/validation.py
1
from localstack.aws.api.s3 import InvalidTag
1✔
2
from localstack.aws.api.s3control import Tag, TagList
1✔
3
from localstack.aws.forwarder import NotImplementedAvoidFallbackError
1✔
4
from localstack.services.s3.exceptions import MalformedXML
1✔
5
from localstack.services.s3.models import s3_stores
1✔
6
from localstack.services.s3.utils import TAG_REGEX
1✔
7
from localstack.services.s3control.exceptions import NoSuchResource
1✔
8

9

10
def validate_arn_for_tagging(
1✔
11
    resource_arn: str, partition: str, account_id: str, region: str
12
) -> None:
13
    """
14
    Validates the resource ARN for the resource being tagged.
15

16
    :param resource_arn: The ARN of the resource being tagged.
17
    :param partition: The partition the request is originating from.
18
    :param account_id: The account ID of the target resource.
19
    :param region: The region the request is originating from.
20
    :return: None
21
    """
22

23
    s3_prefix = f"arn:{partition}:s3:::"
1✔
24
    if not resource_arn.startswith(s3_prefix):
1✔
25
        # Moto does not support Tagging operations for S3 Control, so we should not forward those operations back
26
        # to it
27
        raise NotImplementedAvoidFallbackError(
28
            "LocalStack only support Bucket tagging operations for S3Control"
29
        )
30

31
    store = s3_stores[account_id][region]
1✔
32
    bucket_name = resource_arn.removeprefix(s3_prefix)
1✔
33
    if bucket_name not in store.global_bucket_map:
1✔
34
        raise NoSuchResource("The specified resource doesn't exist.")
1✔
35

36

37
def validate_tags(tags: TagList):
1✔
38
    """
39
    Validate the tags provided. This is the same function as S3, but with different error messages
40
    :param tags: a TagList object
41
    :raises MalformedXML if the object does not conform to the schema
42
    :raises InvalidTag if the tag key or value are outside the set of validations defined by S3 and S3Control
43
    :return: None
44
    """
45
    keys = set()
1✔
46
    for tag in tags:
1✔
47
        tag: Tag
48
        if set(tag) != {"Key", "Value"}:
1✔
UNCOV
49
            raise MalformedXML()
×
50

51
        key = tag["Key"]
1✔
52
        value = tag["Value"]
1✔
53

54
        if key is None or value is None:
1✔
55
            raise MalformedXML()
1✔
56

57
        if key in keys:
1✔
58
            raise InvalidTag(
1✔
59
                "There are duplicate tag keys in your request. Remove the duplicate tag keys and try again.",
60
                TagKey=key,
61
            )
62

63
        if key.startswith("aws:"):
1✔
64
            raise InvalidTag(
1✔
65
                'User-defined tag keys can\'t start with "aws:". This prefix is reserved for system tags. Remove "aws:" from your tag keys and try again.',
66
            )
67

68
        if not TAG_REGEX.match(key):
1✔
69
            raise InvalidTag(
1✔
70
                "This request contains a tag key or value that isn't valid. Valid characters include the following: [a-zA-Z+-=._:/]. Tag keys can contain up to 128 characters. Tag values can contain up to 256 characters.",
71
                TagKey=key,
72
            )
73
        elif not TAG_REGEX.match(value):
1✔
74
            raise InvalidTag(
1✔
75
                "This request contains a tag key or value that isn't valid. Valid characters include the following: [a-zA-Z+-=._:/]. Tag keys can contain up to 128 characters. Tag values can contain up to 256 characters.",
76
                TagKey=key,
77
                TagValue=value,
78
            )
79

80
        keys.add(key)
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc