File: stepfunctions_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 (46 lines) | stat: -rw-r--r-- 1,563 bytes parent folder | download
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
35
36
37
38
39
40
41
42
43
44
45
46
import base64
import logging

from moto.stepfunctions.parser.api import ValidationException
from moto.stepfunctions.parser.utils import to_bytes, to_str

LOG = logging.getLogger(__name__)


def get_next_page_token_from_arn(resource_arn: str) -> str:
    return to_str(base64.b64encode(to_bytes(resource_arn)))


_DEFAULT_SFN_MAX_RESULTS: int = 100


def normalise_max_results(max_results: int = 100) -> int:
    if not max_results:
        return _DEFAULT_SFN_MAX_RESULTS
    return max_results


def assert_pagination_parameters_valid(
    max_results: int,
    next_token: str,
    next_token_length_limit: int = 1024,
    max_results_upper_limit: int = 1000,
) -> tuple[int, str]:
    validation_errors = []

    if isinstance(max_results, int) and max_results > max_results_upper_limit:
        validation_errors.append(
            f"Value '{max_results}' at 'maxResults' failed to satisfy constraint: "
            f"Member must have value less than or equal to {max_results_upper_limit}"
        )

    if isinstance(next_token, str) and len(next_token) > next_token_length_limit:
        validation_errors.append(
            f"Value '{next_token}' at 'nextToken' failed to satisfy constraint: "
            f"Member must have length less than or equal to {next_token_length_limit}"
        )

    if validation_errors:
        errors_message = "; ".join(validation_errors)
        message = f"{len(validation_errors)} validation {'errors' if len(validation_errors) > 1 else 'error'} detected: {errors_message}"
        raise ValidationException(message)