File: utils.py

package info (click to toggle)
python-moto 5.1.18-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 116,520 kB
  • sloc: python: 636,725; javascript: 181; makefile: 39; sh: 3
file content (34 lines) | stat: -rw-r--r-- 1,195 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import random
import re
import string

from .exceptions import ValidationException


def random_id(size: int = 10) -> str:
    chars = list(range(10)) + list(string.ascii_lowercase)
    return "".join(str(random.choice(chars)) for x in range(size))


def validate_name(name: str) -> None:
    """
    The name that uniquely identifies the DB instance when interacting with the Amazon Timestream for InfluxDB API and CLI commands.
    This name will also be a prefix included in the endpoint.
    DB instance names must be unique per customer and per region.
    Length Constraints: Minimum length of 3. Maximum length of 40.
    Pattern: ^[a-zA-Z][a-zA-Z0-9]*(-[a-zA-Z0-9]+)*$

    """

    if len(name) < 3:
        raise ValidationException(
            f"Expected name to have a minimum length of 3, got {len(name)}"
        )
    elif len(name) > 40:
        raise ValidationException(
            f"Expected name to have a maximum length of 40, got {len(name)}"
        )
    elif not re.match(r"^[a-zA-Z][a-zA-Z0-9]*(-[a-zA-Z0-9]+)*$", name):
        raise ValidationException(
            f"Expected name to match the pattern ^[a-zA-Z][a-zA-Z0-9]*(-[a-zA-Z0-9]+)*$, got {name}"
        )