Feature: Ability to seed Moto, and make random ID's deterministic (#5492)
This commit is contained in:
parent
c462688846
commit
aa7d68a688
@ -68,3 +68,46 @@ The requests are stored in a file called `moto_recording`, in the directory that
|
||||
|
||||
The recorder is disabled by default. If you want to enable it, use the following environment variable:
|
||||
`MOTO_ENABLE_RECORDING=True`
|
||||
|
||||
|
||||
Deterministic Identifiers
|
||||
##############################
|
||||
|
||||
Moto creates random identifiers for most resources, just like AWS. The Recorder will recreate the same resources every time, but with different identifiers.
|
||||
|
||||
It is possible to seed Moto and ensure that the 'random' identifiers are always the same for subsequent requests.
|
||||
|
||||
Example invocation:
|
||||
|
||||
.. sourcecode:: python
|
||||
|
||||
# Ensure the provided parameter `a` is an integer
|
||||
requests.post("http://motoapi.amazonaws.com/moto-api/seed?a=42")
|
||||
|
||||
# To try this out, generate a EC2 instance
|
||||
client = boto3.client("ec2", region_name="us-east-1")
|
||||
resp = client.run_instances(ImageId="ami-12c6146b", MinCount=1, MaxCount=1)
|
||||
|
||||
# The resulting InstanceId will always be the same
|
||||
instance_id = resp["Instances"][0]["InstanceId"]
|
||||
assert instance_id == "i-d1026706d7e805da8"
|
||||
|
||||
To seed Moto in ServerMode:
|
||||
|
||||
.. sourcecode:: python
|
||||
|
||||
requests.post(f"http://localhost:5000/moto-api/seed?a=42")
|
||||
|
||||
|
||||
Because the seeding API is only exposed as a request, it will be recorded just like any other request. :raw-html:`<br />`
|
||||
Seed Moto at the beginning of a recording to ensure the resulting state will always be the same:
|
||||
|
||||
.. sourcecode:: python
|
||||
|
||||
requests.post("http://localhost:5000/moto-api/recorder/start-recording")
|
||||
requests.post("http://localhost:5000/moto-api/seed?a=42")
|
||||
|
||||
client = boto3.client("ec2", region_name="us-east-1")
|
||||
resp = client.run_instances(ImageId="ami-12c6146b", MinCount=1, MaxCount=1)
|
||||
|
||||
requests.post("http://localhost:5000/moto-api/recorder/stop-recording")
|
||||
|
@ -1,9 +1,9 @@
|
||||
import uuid
|
||||
from moto.moto_api._internal import mock_random
|
||||
|
||||
|
||||
def make_arn_for_certificate(account_id, region_name):
|
||||
# Example
|
||||
# arn:aws:acm:eu-west-2:764371465172:certificate/c4b738b8-56fe-4b3a-b841-1c047654780b
|
||||
return "arn:aws:acm:{0}:{1}:certificate/{2}".format(
|
||||
region_name, account_id, uuid.uuid4()
|
||||
region_name, account_id, mock_random.uuid4()
|
||||
)
|
||||
|
@ -2,10 +2,10 @@
|
||||
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import BackendDict, unix_time
|
||||
from moto.moto_api._internal import mock_random
|
||||
from moto.utilities.paginator import paginate
|
||||
from moto.utilities.tagging_service import TaggingService
|
||||
from typing import Dict
|
||||
from uuid import uuid4
|
||||
from .exceptions import RuleGroupNamespaceNotFound, WorkspaceNotFound
|
||||
from .utils import PAGINATION_MODEL
|
||||
|
||||
@ -38,7 +38,7 @@ class RuleGroupNamespace(BaseModel):
|
||||
class Workspace(BaseModel):
|
||||
def __init__(self, account_id, region, alias, tag_fn):
|
||||
self.alias = alias
|
||||
self.workspace_id = f"ws-{uuid4()}"
|
||||
self.workspace_id = f"ws-{mock_random.uuid4()}"
|
||||
self.arn = f"arn:aws:aps:{region}:{account_id}:workspace/{self.workspace_id}"
|
||||
self.endpoint = f"https://aps-workspaces.{region}.amazonaws.com/workspaces/{self.workspace_id}/"
|
||||
self.status = {"statusCode": "ACTIVE"}
|
||||
|
@ -1,6 +1,5 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
import random
|
||||
import string
|
||||
import re
|
||||
from collections import defaultdict
|
||||
@ -66,6 +65,7 @@ from .exceptions import (
|
||||
)
|
||||
from ..core.models import responses_mock
|
||||
from moto.apigateway.exceptions import MethodNotFoundException
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
|
||||
STAGE_URL = "https://{api_id}.execute-api.{region_name}.amazonaws.com/{stage_name}"
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import random
|
||||
import string
|
||||
import json
|
||||
import yaml
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
|
||||
|
||||
def create_id():
|
||||
|
@ -1,10 +1,10 @@
|
||||
"""ApiGatewayV2Backend class with methods for supported APIs."""
|
||||
import random
|
||||
import string
|
||||
import yaml
|
||||
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import BackendDict, unix_time
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
from moto.utilities.tagging_service import TaggingService
|
||||
|
||||
from .exceptions import (
|
||||
|
@ -1,11 +1,11 @@
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import BackendDict
|
||||
from moto.ecs import ecs_backends
|
||||
from moto.moto_api._internal import mock_random
|
||||
from .exceptions import AWSValidationException
|
||||
from collections import OrderedDict
|
||||
from enum import Enum, unique
|
||||
import time
|
||||
import uuid
|
||||
|
||||
|
||||
@unique
|
||||
@ -418,7 +418,7 @@ class FakeApplicationAutoscalingPolicy(BaseModel):
|
||||
self.scalable_dimension = scalable_dimension
|
||||
self.policy_name = policy_name
|
||||
self.policy_type = policy_type
|
||||
self._guid = uuid.uuid4()
|
||||
self._guid = mock_random.uuid4()
|
||||
self.policy_arn = "arn:aws:autoscaling:{}:scalingPolicy:{}:resource/{}/{}:policyName/{}".format(
|
||||
region_name,
|
||||
self._guid,
|
||||
|
@ -2,10 +2,9 @@ import base64
|
||||
from datetime import timedelta, datetime, timezone
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import BackendDict, unix_time
|
||||
from moto.moto_api._internal import mock_random
|
||||
from moto.utilities.tagging_service import TaggingService
|
||||
|
||||
from uuid import uuid4
|
||||
|
||||
from .exceptions import GraphqlAPINotFound
|
||||
|
||||
|
||||
@ -66,7 +65,7 @@ class GraphqlAPI(BaseModel):
|
||||
):
|
||||
self.region = region
|
||||
self.name = name
|
||||
self.api_id = str(uuid4())
|
||||
self.api_id = str(mock_random.uuid4())
|
||||
self.authentication_type = authentication_type
|
||||
self.additional_authentication_providers = additional_authentication_providers
|
||||
self.lambda_authorizer_config = lambda_authorizer_config
|
||||
@ -157,7 +156,7 @@ class GraphqlAPI(BaseModel):
|
||||
|
||||
class GraphqlAPIKey(BaseModel):
|
||||
def __init__(self, description, expires):
|
||||
self.key_id = str(uuid4())[0:6]
|
||||
self.key_id = str(mock_random.uuid4())[0:6]
|
||||
self.description = description
|
||||
self.expires = expires
|
||||
if not self.expires:
|
||||
|
@ -2,8 +2,7 @@ import time
|
||||
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import BackendDict
|
||||
|
||||
from uuid import uuid4
|
||||
from moto.moto_api._internal import mock_random
|
||||
|
||||
|
||||
class TaggableResourceMixin(object):
|
||||
@ -66,7 +65,7 @@ class DataCatalog(TaggableResourceMixin, BaseModel):
|
||||
|
||||
class Execution(BaseModel):
|
||||
def __init__(self, query, context, config, workgroup):
|
||||
self.id = str(uuid4())
|
||||
self.id = str(mock_random.uuid4())
|
||||
self.query = query
|
||||
self.context = context
|
||||
self.config = config
|
||||
@ -77,7 +76,7 @@ class Execution(BaseModel):
|
||||
|
||||
class NamedQuery(BaseModel):
|
||||
def __init__(self, name, description, database, query_string, workgroup):
|
||||
self.id = str(uuid4())
|
||||
self.id = str(mock_random.uuid4())
|
||||
self.name = name
|
||||
self.description = description
|
||||
self.database = database
|
||||
|
@ -1,6 +1,4 @@
|
||||
import itertools
|
||||
import random
|
||||
from uuid import uuid4
|
||||
|
||||
from moto.packages.boto.ec2.blockdevicemapping import (
|
||||
BlockDeviceType,
|
||||
@ -15,6 +13,7 @@ from moto.ec2 import ec2_backends
|
||||
from moto.elb import elb_backends
|
||||
from moto.elbv2 import elbv2_backends
|
||||
from moto.elb.exceptions import LoadBalancerNotFoundError
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
from .exceptions import (
|
||||
AutoscalingClientError,
|
||||
ResourceContentionError,
|
||||
@ -375,7 +374,7 @@ class FakeAutoScalingGroup(CloudFormationModel):
|
||||
self.autoscaling_backend = autoscaling_backend
|
||||
self.ec2_backend = ec2_backend
|
||||
self.name = name
|
||||
self._id = str(uuid4())
|
||||
self._id = str(random.uuid4())
|
||||
self.region = self.autoscaling_backend.region_name
|
||||
self.account_id = self.autoscaling_backend.account_id
|
||||
self.service_linked_role = f"arn:aws:iam::{self.account_id}:role/aws-service-role/autoscaling.amazonaws.com/AWSServiceRoleForAutoScaling"
|
||||
|
@ -1,11 +1,8 @@
|
||||
import datetime
|
||||
|
||||
from moto.core.responses import BaseResponse
|
||||
from moto.core.utils import (
|
||||
amz_crc32,
|
||||
amzn_request_id,
|
||||
iso_8601_datetime_with_milliseconds,
|
||||
)
|
||||
from moto.core.utils import iso_8601_datetime_with_milliseconds
|
||||
from moto.utilities.aws_headers import amz_crc32, amzn_request_id
|
||||
from .models import autoscaling_backends
|
||||
|
||||
|
||||
|
@ -16,7 +16,6 @@ import os
|
||||
import json
|
||||
import re
|
||||
import zipfile
|
||||
import uuid
|
||||
import tarfile
|
||||
import calendar
|
||||
import threading
|
||||
@ -26,11 +25,12 @@ import requests.exceptions
|
||||
from moto.awslambda.policy import Policy
|
||||
from moto.core import BaseBackend, BaseModel, CloudFormationModel
|
||||
from moto.core.exceptions import RESTError
|
||||
from moto.core.utils import unix_time_millis, BackendDict
|
||||
from moto.iam.models import iam_backends
|
||||
from moto.iam.exceptions import IAMNotFoundException
|
||||
from moto.core.utils import unix_time_millis, BackendDict
|
||||
from moto.s3.models import s3_backends
|
||||
from moto.logs.models import logs_backends
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
from moto.s3.models import s3_backends
|
||||
from moto.s3.exceptions import MissingBucket, MissingKey
|
||||
from moto import settings
|
||||
from .exceptions import (
|
||||
@ -54,7 +54,6 @@ from moto.dynamodb import dynamodb_backends
|
||||
from moto.dynamodbstreams import dynamodbstreams_backends
|
||||
from moto.utilities.docker_utilities import DockerModel, parse_image_ref
|
||||
from tempfile import TemporaryDirectory
|
||||
from uuid import uuid4
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -335,7 +334,7 @@ class LambdaAlias(BaseModel):
|
||||
self.function_version = function_version
|
||||
self.description = description
|
||||
self.routing_config = routing_config
|
||||
self.revision_id = str(uuid4())
|
||||
self.revision_id = str(random.uuid4())
|
||||
|
||||
def update(self, description, function_version, routing_config):
|
||||
if description is not None:
|
||||
@ -439,7 +438,7 @@ class LambdaFunction(CloudFormationModel, DockerModel):
|
||||
) = _zipfile_content(self.code["ZipFile"])
|
||||
|
||||
# TODO: we should be putting this in a lambda bucket
|
||||
self.code["UUID"] = str(uuid.uuid4())
|
||||
self.code["UUID"] = str(random.uuid4())
|
||||
self.code["S3Key"] = "{}-{}".format(self.function_name, self.code["UUID"])
|
||||
elif "S3Bucket" in self.code:
|
||||
key = _validate_s3_bucket_and_key(self.account_id, data=self.code)
|
||||
@ -610,7 +609,7 @@ class LambdaFunction(CloudFormationModel, DockerModel):
|
||||
) = _zipfile_content(updated_spec["ZipFile"])
|
||||
|
||||
# TODO: we should be putting this in a lambda bucket
|
||||
self.code["UUID"] = str(uuid.uuid4())
|
||||
self.code["UUID"] = str(random.uuid4())
|
||||
self.code["S3Key"] = "{}-{}".format(self.function_name, self.code["UUID"])
|
||||
elif "S3Bucket" in updated_spec and "S3Key" in updated_spec:
|
||||
key = None
|
||||
@ -757,7 +756,7 @@ class LambdaFunction(CloudFormationModel, DockerModel):
|
||||
|
||||
def save_logs(self, output):
|
||||
# Send output to "logs" backend
|
||||
invoke_id = uuid.uuid4().hex
|
||||
invoke_id = random.uuid4().hex
|
||||
log_stream_name = (
|
||||
"{date.year}/{date.month:02d}/{date.day:02d}/[{version}]{invoke_id}".format(
|
||||
date=datetime.datetime.utcnow(),
|
||||
@ -935,7 +934,7 @@ class FunctionUrlConfig:
|
||||
def __init__(self, function: LambdaFunction, config):
|
||||
self.function = function
|
||||
self.config = config
|
||||
self.url = f"https://{uuid.uuid4().hex}.lambda-url.{function.region}.on.aws"
|
||||
self.url = f"https://{random.uuid4().hex}.lambda-url.{function.region}.on.aws"
|
||||
self.created = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S")
|
||||
self.last_modified = self.created
|
||||
|
||||
@ -970,7 +969,7 @@ class EventSourceMapping(CloudFormationModel):
|
||||
self.starting_position_timestamp = spec.get("StartingPositionTimestamp", None)
|
||||
|
||||
self.function_arn = spec["FunctionArn"]
|
||||
self.uuid = str(uuid.uuid4())
|
||||
self.uuid = str(random.uuid4())
|
||||
self.last_modified = time.mktime(datetime.datetime.utcnow().timetuple())
|
||||
|
||||
def _get_service_source_from_arn(self, event_source_arn):
|
||||
|
@ -1,15 +1,15 @@
|
||||
import json
|
||||
import uuid
|
||||
|
||||
from moto.awslambda.exceptions import (
|
||||
PreconditionFailedException,
|
||||
UnknownPolicyException,
|
||||
)
|
||||
from moto.moto_api._internal import mock_random
|
||||
|
||||
|
||||
class Policy:
|
||||
def __init__(self, parent):
|
||||
self.revision = str(uuid.uuid4())
|
||||
self.revision = str(mock_random.uuid4())
|
||||
self.statements = []
|
||||
self.parent = parent
|
||||
|
||||
@ -45,7 +45,7 @@ class Policy:
|
||||
policy.statements[0]["Resource"] + ":" + qualifier
|
||||
)
|
||||
self.statements.append(policy.statements[0])
|
||||
self.revision = str(uuid.uuid4())
|
||||
self.revision = str(mock_random.uuid4())
|
||||
|
||||
# removes the statement that matches 'sid' from the policy
|
||||
def del_statement(self, sid, revision=""):
|
||||
@ -73,7 +73,7 @@ class Policy:
|
||||
# set some default values if these keys are not set
|
||||
self.ensure_set(obj, "Effect", "Allow")
|
||||
self.ensure_set(obj, "Resource", self.parent.function_arn + ":$LATEST")
|
||||
self.ensure_set(obj, "StatementId", str(uuid.uuid4()))
|
||||
self.ensure_set(obj, "StatementId", str(mock_random.uuid4()))
|
||||
|
||||
# transform field names and values
|
||||
self.transform_property(obj, "StatementId", "Sid", self.nop_formatter)
|
||||
|
@ -3,7 +3,8 @@ import sys
|
||||
|
||||
from urllib.parse import unquote
|
||||
|
||||
from moto.core.utils import amz_crc32, amzn_request_id, path_url
|
||||
from moto.core.utils import path_url
|
||||
from moto.utilities.aws_headers import amz_crc32, amzn_request_id
|
||||
from moto.core.responses import BaseResponse
|
||||
from .models import lambda_backends
|
||||
|
||||
|
@ -3,7 +3,6 @@ from itertools import cycle
|
||||
from time import sleep
|
||||
import datetime
|
||||
import time
|
||||
import uuid
|
||||
import logging
|
||||
import threading
|
||||
import dateutil.parser
|
||||
@ -29,6 +28,7 @@ from moto.ec2.models.instance_types import INSTANCE_FAMILIES as EC2_INSTANCE_FAM
|
||||
from moto.iam.exceptions import IAMNotFoundException
|
||||
from moto.core.utils import unix_time_millis, BackendDict
|
||||
from moto.moto_api import state_manager
|
||||
from moto.moto_api._internal import mock_random
|
||||
from moto.moto_api._internal.managed_state_model import ManagedState
|
||||
from moto.utilities.docker_utilities import DockerModel
|
||||
from moto import settings
|
||||
@ -444,7 +444,7 @@ class Job(threading.Thread, BaseModel, DockerModel, ManagedState):
|
||||
)
|
||||
|
||||
self.job_name = name
|
||||
self.job_id = str(uuid.uuid4())
|
||||
self.job_id = str(mock_random.uuid4())
|
||||
self.job_definition = job_def
|
||||
self.container_overrides = container_overrides or {}
|
||||
self.job_queue = job_queue
|
||||
@ -1110,7 +1110,7 @@ class BatchBackend(BaseBackend):
|
||||
|
||||
# Create ECS cluster
|
||||
# Should be of format P2OnDemand_Batch_UUID
|
||||
cluster_name = "OnDemand_Batch_" + str(uuid.uuid4())
|
||||
cluster_name = "OnDemand_Batch_" + str(mock_random.uuid4())
|
||||
ecs_cluster = self.ecs_backend.create_cluster(cluster_name)
|
||||
new_comp_env.set_ecs(ecs_cluster.arn, cluster_name)
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
from .exceptions import CostCategoryNotFound
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import BackendDict
|
||||
from uuid import uuid4
|
||||
from moto.moto_api._internal import mock_random
|
||||
|
||||
|
||||
class CostCategoryDefinition(BaseModel):
|
||||
@ -15,7 +15,7 @@ class CostCategoryDefinition(BaseModel):
|
||||
self.rules = rules
|
||||
self.default_value = default_value
|
||||
self.split_charge_rules = split_charge_rules
|
||||
self.arn = f"arn:aws:ce::{account_id}:costcategory/{str(uuid4())}"
|
||||
self.arn = f"arn:aws:ce::{account_id}:costcategory/{str(mock_random.uuid4())}"
|
||||
|
||||
def update(self, rule_version, rules, default_value, split_charge_rules):
|
||||
self.rule_version = rule_version
|
||||
|
@ -4,7 +4,7 @@ import threading
|
||||
from moto import settings
|
||||
from moto.core import CloudFormationModel
|
||||
from moto.awslambda import lambda_backends
|
||||
from uuid import uuid4
|
||||
from moto.moto_api._internal import mock_random
|
||||
|
||||
|
||||
class CustomModel(CloudFormationModel):
|
||||
@ -44,7 +44,7 @@ class CustomModel(CloudFormationModel):
|
||||
backend = lambda_backends[account_id][region_name]
|
||||
fn = backend.get_function(service_token)
|
||||
|
||||
request_id = str(uuid4())
|
||||
request_id = str(mock_random.uuid4())
|
||||
|
||||
custom_resource = CustomModel(
|
||||
region_name, request_id, logical_id, resource_name
|
||||
|
@ -1,7 +1,6 @@
|
||||
from datetime import datetime, timedelta
|
||||
import json
|
||||
import yaml
|
||||
import uuid
|
||||
|
||||
from collections import OrderedDict
|
||||
from yaml.parser import ParserError # pylint:disable=c-extension-no-member
|
||||
@ -13,6 +12,7 @@ from moto.core.utils import (
|
||||
iso_8601_datetime_without_milliseconds,
|
||||
BackendDict,
|
||||
)
|
||||
from moto.moto_api._internal import mock_random
|
||||
from moto.sns.models import sns_backends
|
||||
|
||||
from .parsing import ResourceMap, OutputMap
|
||||
@ -103,7 +103,7 @@ class FakeStackSet(BaseModel):
|
||||
operation_id=None,
|
||||
):
|
||||
if not operation_id:
|
||||
operation_id = uuid.uuid4()
|
||||
operation_id = mock_random.uuid4()
|
||||
|
||||
self.template = template if template else self.template
|
||||
self.description = description if description is not None else self.description
|
||||
@ -126,7 +126,7 @@ class FakeStackSet(BaseModel):
|
||||
|
||||
def create_stack_instances(self, accounts, regions, parameters, operation_id=None):
|
||||
if not operation_id:
|
||||
operation_id = uuid.uuid4()
|
||||
operation_id = mock_random.uuid4()
|
||||
if not parameters:
|
||||
parameters = self.parameters
|
||||
|
||||
@ -141,7 +141,7 @@ class FakeStackSet(BaseModel):
|
||||
|
||||
def delete_stack_instances(self, accounts, regions, operation_id=None):
|
||||
if not operation_id:
|
||||
operation_id = uuid.uuid4()
|
||||
operation_id = mock_random.uuid4()
|
||||
|
||||
self.instances.delete(accounts, regions)
|
||||
|
||||
@ -156,7 +156,7 @@ class FakeStackSet(BaseModel):
|
||||
|
||||
def update_instances(self, accounts, regions, parameters, operation_id=None):
|
||||
if not operation_id:
|
||||
operation_id = uuid.uuid4()
|
||||
operation_id = mock_random.uuid4()
|
||||
|
||||
self.instances.update(accounts, regions, parameters)
|
||||
operation = self._create_operation(
|
||||
@ -488,7 +488,7 @@ class FakeEvent(BaseModel):
|
||||
self.resource_status_reason = resource_status_reason
|
||||
self.resource_properties = resource_properties
|
||||
self.timestamp = datetime.utcnow()
|
||||
self.event_id = uuid.uuid4()
|
||||
self.event_id = mock_random.uuid4()
|
||||
self.client_request_token = client_request_token
|
||||
|
||||
def sendToSns(self, account_id, region, sns_topic_arns):
|
||||
|
@ -5,9 +5,9 @@ from yaml.parser import ParserError # pylint:disable=c-extension-no-member
|
||||
from yaml.scanner import ScannerError # pylint:disable=c-extension-no-member
|
||||
|
||||
from moto.core.responses import BaseResponse
|
||||
from moto.core.utils import amzn_request_id
|
||||
from moto.s3.models import s3_backends
|
||||
from moto.s3.exceptions import S3ClientError
|
||||
from moto.utilities.aws_headers import amzn_request_id
|
||||
from .models import cloudformation_backends
|
||||
from .exceptions import ValidationError, MissingParameterError
|
||||
from .utils import yaml_tag_constructor
|
||||
|
@ -1,22 +1,21 @@
|
||||
import uuid
|
||||
import random
|
||||
import yaml
|
||||
import os
|
||||
import string
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
|
||||
|
||||
def generate_stack_id(stack_name, region, account):
|
||||
random_id = uuid.uuid4()
|
||||
random_id = random.uuid4()
|
||||
return f"arn:aws:cloudformation:{region}:{account}:stack/{stack_name}/{random_id}"
|
||||
|
||||
|
||||
def generate_changeset_id(changeset_name, region_name, account_id):
|
||||
random_id = uuid.uuid4()
|
||||
random_id = random.uuid4()
|
||||
return f"arn:aws:cloudformation:{region_name}:{account_id}:changeSet/{changeset_name}/{random_id}"
|
||||
|
||||
|
||||
def generate_stackset_id(stackset_name):
|
||||
random_id = uuid.uuid4()
|
||||
random_id = random.uuid4()
|
||||
return "{}:{}".format(stackset_name, random_id)
|
||||
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
import random
|
||||
import string
|
||||
|
||||
from datetime import datetime
|
||||
@ -6,8 +5,8 @@ from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import BackendDict, iso_8601_datetime_with_milliseconds
|
||||
from moto.moto_api import state_manager
|
||||
from moto.moto_api._internal.managed_state_model import ManagedState
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
from moto.utilities.tagging_service import TaggingService
|
||||
from uuid import uuid4
|
||||
|
||||
from .exceptions import (
|
||||
OriginDoesNotExist,
|
||||
@ -153,7 +152,7 @@ class DistributionConfig:
|
||||
self.enabled = config.get("Enabled") or False
|
||||
self.viewer_certificate = ViewerCertificate()
|
||||
self.geo_restriction = GeoRestrictions(config.get("Restrictions") or {})
|
||||
self.caller_reference = config.get("CallerReference", str(uuid4()))
|
||||
self.caller_reference = config.get("CallerReference", str(random.uuid4()))
|
||||
self.origins = config["Origins"]["Items"]["Origin"]
|
||||
if not isinstance(self.origins, list):
|
||||
self.origins = [self.origins]
|
||||
|
@ -6,9 +6,9 @@ from moto.core.utils import (
|
||||
iso_8601_datetime_with_nanoseconds,
|
||||
BackendDict,
|
||||
)
|
||||
from moto.moto_api._internal import mock_random
|
||||
from datetime import datetime, timedelta
|
||||
from dateutil.tz import tzutc
|
||||
from uuid import uuid4
|
||||
|
||||
from .exceptions import (
|
||||
InvalidFormat,
|
||||
@ -678,7 +678,7 @@ class CloudWatchBackend(BaseBackend):
|
||||
|
||||
def _get_paginated(self, metrics):
|
||||
if len(metrics) > 500:
|
||||
next_token = str(uuid4())
|
||||
next_token = str(mock_random.uuid4())
|
||||
self.paged_metric_data[next_token] = metrics[500:]
|
||||
return next_token, metrics[0:500]
|
||||
else:
|
||||
|
@ -3,7 +3,7 @@ import json
|
||||
from dateutil.parser import parse as dtparse
|
||||
|
||||
from moto.core.responses import BaseResponse
|
||||
from moto.core.utils import amzn_request_id
|
||||
from moto.utilities.aws_headers import amzn_request_id
|
||||
from .models import cloudwatch_backends, MetricDataQuery, MetricStat, Metric, Dimension
|
||||
from .exceptions import InvalidParameterCombination
|
||||
|
||||
|
@ -1,10 +1,9 @@
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import iso_8601_datetime_with_milliseconds, BackendDict
|
||||
from moto.moto_api._internal import mock_random
|
||||
from collections import defaultdict
|
||||
from random import randint
|
||||
from dateutil import parser
|
||||
import datetime
|
||||
import uuid
|
||||
|
||||
|
||||
class CodeBuildProjectMetadata(BaseModel):
|
||||
@ -26,7 +25,7 @@ class CodeBuildProjectMetadata(BaseModel):
|
||||
"arn"
|
||||
] = f"arn:aws:codebuild:{region_name}:{account_id}:build/{build_id}"
|
||||
|
||||
self.build_metadata["buildNumber"] = randint(1, 100)
|
||||
self.build_metadata["buildNumber"] = mock_random.randint(1, 100)
|
||||
self.build_metadata["startTime"] = current_date
|
||||
self.build_metadata["currentPhase"] = "QUEUED"
|
||||
self.build_metadata["buildStatus"] = "IN_PROGRESS"
|
||||
@ -168,7 +167,7 @@ class CodeBuildBackend(BaseBackend):
|
||||
|
||||
def start_build(self, project_name, source_version=None, artifact_override=None):
|
||||
|
||||
build_id = "{0}:{1}".format(project_name, uuid.uuid4())
|
||||
build_id = "{0}:{1}".format(project_name, mock_random.uuid4())
|
||||
|
||||
# construct a new build
|
||||
self.build_metadata[project_name] = CodeBuildProjectMetadata(
|
||||
@ -215,7 +214,7 @@ class CodeBuildBackend(BaseBackend):
|
||||
phase["phaseStatus"] = "SUCCEEDED"
|
||||
phase["startTime"] = current_date
|
||||
phase["endTime"] = current_date
|
||||
phase["durationInSeconds"] = randint(10, 100)
|
||||
phase["durationInSeconds"] = mock_random.randint(10, 100)
|
||||
phases.append(phase)
|
||||
|
||||
return phases
|
||||
@ -229,7 +228,7 @@ class CodeBuildBackend(BaseBackend):
|
||||
build["phases"] = self._set_phases(build["phases"])
|
||||
build["endTime"] = iso_8601_datetime_with_milliseconds(
|
||||
parser.parse(build["startTime"])
|
||||
+ datetime.timedelta(minutes=randint(1, 5))
|
||||
+ datetime.timedelta(minutes=mock_random.randint(1, 5))
|
||||
)
|
||||
build["currentPhase"] = "COMPLETED"
|
||||
build["buildStatus"] = "SUCCEEDED"
|
||||
@ -264,7 +263,7 @@ class CodeBuildBackend(BaseBackend):
|
||||
build["phases"] = self._set_phases(build["phases"])
|
||||
build["endTime"] = iso_8601_datetime_with_milliseconds(
|
||||
parser.parse(build["startTime"])
|
||||
+ datetime.timedelta(minutes=randint(1, 5))
|
||||
+ datetime.timedelta(minutes=mock_random.randint(1, 5))
|
||||
)
|
||||
build["currentPhase"] = "COMPLETED"
|
||||
build["buildStatus"] = "STOPPED"
|
||||
|
@ -1,8 +1,8 @@
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import iso_8601_datetime_with_milliseconds, BackendDict
|
||||
from moto.moto_api._internal import mock_random
|
||||
from datetime import datetime
|
||||
from .exceptions import RepositoryDoesNotExistException, RepositoryNameExistsException
|
||||
import uuid
|
||||
|
||||
|
||||
class CodeCommit(BaseModel):
|
||||
@ -23,7 +23,7 @@ class CodeCommit(BaseModel):
|
||||
self.repository_metadata["creationDate"] = current_date
|
||||
self.repository_metadata["lastModifiedDate"] = current_date
|
||||
self.repository_metadata["repositoryDescription"] = repository_description
|
||||
self.repository_metadata["repositoryId"] = str(uuid.uuid4())
|
||||
self.repository_metadata["repositoryId"] = str(mock_random.uuid4())
|
||||
self.repository_metadata[
|
||||
"Arn"
|
||||
] = f"arn:aws:codecommit:{region}:{account_id}:{repository_name}"
|
||||
|
@ -1,5 +1,5 @@
|
||||
from uuid import uuid4
|
||||
from moto.moto_api._internal import mock_random
|
||||
|
||||
|
||||
def get_random_identity_id(region):
|
||||
return "{0}:{1}".format(region, uuid4())
|
||||
return "{0}:{1}".format(region, mock_random.uuid4())
|
||||
|
@ -3,13 +3,12 @@ import json
|
||||
import os
|
||||
import time
|
||||
import typing
|
||||
import uuid
|
||||
import enum
|
||||
import random
|
||||
from jose import jws
|
||||
from collections import OrderedDict
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import BackendDict
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
from .exceptions import (
|
||||
GroupExistsException,
|
||||
NotAuthorizedError,
|
||||
@ -562,7 +561,7 @@ class CognitoIdpUserPool(BaseModel):
|
||||
return id_token, expires_in
|
||||
|
||||
def create_refresh_token(self, client_id, username):
|
||||
refresh_token = str(uuid.uuid4())
|
||||
refresh_token = str(random.uuid4())
|
||||
self.refresh_tokens[refresh_token] = (client_id, username)
|
||||
return refresh_token
|
||||
|
||||
@ -633,7 +632,7 @@ class CognitoIdpUserPoolDomain(BaseModel):
|
||||
if extended:
|
||||
return {
|
||||
"UserPoolId": self.user_pool_id,
|
||||
"AWSAccountId": str(uuid.uuid4()),
|
||||
"AWSAccountId": str(random.uuid4()),
|
||||
"CloudFrontDistribution": distribution,
|
||||
"Domain": self.domain,
|
||||
"S3Bucket": None,
|
||||
@ -649,7 +648,7 @@ class CognitoIdpUserPoolClient(BaseModel):
|
||||
def __init__(self, user_pool_id, generate_secret, extended_config):
|
||||
self.user_pool_id = user_pool_id
|
||||
self.id = create_id()
|
||||
self.secret = str(uuid.uuid4())
|
||||
self.secret = str(random.uuid4())
|
||||
self.generate_secret = generate_secret or False
|
||||
self.extended_config = extended_config or {}
|
||||
|
||||
@ -736,7 +735,7 @@ class CognitoIdpGroup(BaseModel):
|
||||
|
||||
class CognitoIdpUser(BaseModel):
|
||||
def __init__(self, user_pool_id, username, password, status, attributes):
|
||||
self.id = str(uuid.uuid4())
|
||||
self.id = str(random.uuid4())
|
||||
self.user_pool_id = user_pool_id
|
||||
# Username is None when users sign up with an email or phone_number,
|
||||
# and should be given the value of the internal id generate (sub)
|
||||
@ -1289,7 +1288,7 @@ class CognitoIdpBackend(BaseBackend):
|
||||
UserStatus.FORCE_CHANGE_PASSWORD,
|
||||
UserStatus.RESET_REQUIRED,
|
||||
]:
|
||||
session = str(uuid.uuid4())
|
||||
session = str(random.uuid4())
|
||||
self.sessions[session] = user_pool
|
||||
|
||||
return {
|
||||
@ -1635,15 +1634,15 @@ class CognitoIdpBackend(BaseBackend):
|
||||
if user.status is UserStatus.UNCONFIRMED:
|
||||
raise UserNotConfirmedException("User is not confirmed.")
|
||||
|
||||
session = str(uuid.uuid4())
|
||||
session = str(random.uuid4())
|
||||
self.sessions[session] = user_pool
|
||||
|
||||
return {
|
||||
"ChallengeName": "PASSWORD_VERIFIER",
|
||||
"Session": session,
|
||||
"ChallengeParameters": {
|
||||
"SALT": uuid.uuid4().hex,
|
||||
"SRP_B": uuid.uuid4().hex,
|
||||
"SALT": random.uuid4().hex,
|
||||
"SRP_B": random.uuid4().hex,
|
||||
"USERNAME": user.username,
|
||||
"USER_ID_FOR_SRP": user.id,
|
||||
"SECRET_BLOCK": session,
|
||||
@ -1664,7 +1663,7 @@ class CognitoIdpBackend(BaseBackend):
|
||||
if user.status is UserStatus.UNCONFIRMED:
|
||||
raise UserNotConfirmedException("User is not confirmed.")
|
||||
|
||||
session = str(uuid.uuid4())
|
||||
session = str(random.uuid4())
|
||||
self.sessions[session] = user_pool
|
||||
|
||||
if user.status is UserStatus.FORCE_CHANGE_PASSWORD:
|
||||
@ -1732,7 +1731,7 @@ class CognitoIdpBackend(BaseBackend):
|
||||
_, username = user_pool.access_tokens[access_token]
|
||||
self.admin_get_user(user_pool.id, username)
|
||||
|
||||
return {"SecretCode": str(uuid.uuid4())}
|
||||
return {"SecretCode": str(random.uuid4())}
|
||||
|
||||
raise NotAuthorizedError(access_token)
|
||||
|
||||
|
@ -1,10 +1,9 @@
|
||||
import random
|
||||
import string
|
||||
import hashlib
|
||||
import hmac
|
||||
import base64
|
||||
import re
|
||||
import uuid
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
|
||||
FORMATS = {
|
||||
"email": r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b",
|
||||
@ -92,7 +91,7 @@ def generate_id(strategy, *args):
|
||||
|
||||
|
||||
def _generate_id_uuid():
|
||||
return uuid.uuid4().hex
|
||||
return random.uuid4().hex
|
||||
|
||||
|
||||
def _generate_id_hash(args):
|
||||
|
@ -2,8 +2,6 @@
|
||||
import json
|
||||
import re
|
||||
import time
|
||||
import random
|
||||
import string
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
@ -53,6 +51,7 @@ from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.responses import AWSServiceSpec
|
||||
from moto.core.utils import BackendDict
|
||||
from moto.iam.config import role_config_query, policy_config_query
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
from moto.s3.config import s3_config_query
|
||||
from moto.s3control.config import s3_account_public_access_block_query
|
||||
from moto.utilities.utils import load_resource
|
||||
@ -107,11 +106,7 @@ def snake_to_camels(original, cap_start, cap_arn):
|
||||
|
||||
def random_string():
|
||||
"""Returns a random set of 8 lowercase letters for the Config Aggregator ARN"""
|
||||
chars = []
|
||||
for _ in range(0, 8):
|
||||
chars.append(random.choice(string.ascii_lowercase))
|
||||
|
||||
return "".join(chars)
|
||||
return random.get_random_string(length=8, include_digits=False, lower_case=True)
|
||||
|
||||
|
||||
def validate_tag_key(tag_key, exception_param="tags.X.member.key"):
|
||||
|
@ -1,4 +1,3 @@
|
||||
import random
|
||||
import re
|
||||
import string
|
||||
from collections import defaultdict
|
||||
@ -113,6 +112,8 @@ class BaseBackend:
|
||||
|
||||
@staticmethod
|
||||
def vpce_random_number():
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
|
||||
"""Return random number for a VPC endpoint service ID."""
|
||||
return "".join([random.choice(string.hexdigits.lower()) for i in range(17)])
|
||||
|
||||
|
@ -21,7 +21,6 @@ from .custom_responses_mock import (
|
||||
not_implemented_callback,
|
||||
reset_responses_mock,
|
||||
)
|
||||
from .utils import convert_flask_to_responses_response
|
||||
|
||||
DEFAULT_ACCOUNT_ID = "123456789012"
|
||||
|
||||
@ -272,6 +271,9 @@ class BotocoreEventMockAWS(BaseMockAWS):
|
||||
reset_responses_mock(responses_mock)
|
||||
|
||||
def enable_patching(self, reset=True): # pylint: disable=unused-argument
|
||||
# Circumvent circular imports
|
||||
from .utils import convert_flask_to_responses_response
|
||||
|
||||
botocore_stubber.enabled = True
|
||||
for method in BOTOCORE_HTTP_METHODS:
|
||||
for backend in self.backends_for_urls:
|
||||
|
@ -1,11 +1,8 @@
|
||||
from functools import lru_cache, wraps
|
||||
from functools import lru_cache
|
||||
|
||||
import binascii
|
||||
import datetime
|
||||
import inspect
|
||||
import random
|
||||
import re
|
||||
import string
|
||||
from botocore.exceptions import ClientError
|
||||
from boto3 import Session
|
||||
from moto.settings import allow_unknown_region
|
||||
@ -14,10 +11,6 @@ from urllib.parse import urlparse
|
||||
from uuid import uuid4
|
||||
|
||||
|
||||
REQUEST_ID_LONG = string.digits + string.ascii_uppercase
|
||||
HEX_CHARS = list(range(10)) + ["a", "b", "c", "d", "e", "f"]
|
||||
|
||||
|
||||
def camelcase_to_underscores(argument):
|
||||
"""Converts a camelcase param like theNewAttribute to the equivalent
|
||||
python underscore variable like the_new_attribute"""
|
||||
@ -75,20 +68,6 @@ def method_names_from_class(clazz):
|
||||
return [x[0] for x in inspect.getmembers(clazz, predicate=predicate)]
|
||||
|
||||
|
||||
def get_random_hex(length=8):
|
||||
return "".join(str(random.choice(HEX_CHARS)) for _ in range(length))
|
||||
|
||||
|
||||
def get_random_message_id():
|
||||
return "{0}-{1}-{2}-{3}-{4}".format(
|
||||
get_random_hex(8),
|
||||
get_random_hex(4),
|
||||
get_random_hex(4),
|
||||
get_random_hex(4),
|
||||
get_random_hex(12),
|
||||
)
|
||||
|
||||
|
||||
def convert_regex_to_flask_path(url_path):
|
||||
"""
|
||||
Converts a regex matching url to one that can be used with flask
|
||||
@ -206,86 +185,6 @@ def unix_time_millis(dt=None):
|
||||
return unix_time(dt) * 1000.0
|
||||
|
||||
|
||||
def gen_amz_crc32(response, headerdict=None):
|
||||
if not isinstance(response, bytes):
|
||||
response = response.encode("utf-8")
|
||||
|
||||
crc = binascii.crc32(response)
|
||||
|
||||
if headerdict is not None and isinstance(headerdict, dict):
|
||||
headerdict.update({"x-amz-crc32": str(crc)})
|
||||
|
||||
return crc
|
||||
|
||||
|
||||
def gen_amzn_requestid_long(headerdict=None):
|
||||
req_id = "".join([random.choice(REQUEST_ID_LONG) for _ in range(0, 52)])
|
||||
|
||||
if headerdict is not None and isinstance(headerdict, dict):
|
||||
headerdict.update({"x-amzn-requestid": req_id})
|
||||
|
||||
return req_id
|
||||
|
||||
|
||||
def amz_crc32(f):
|
||||
@wraps(f)
|
||||
def _wrapper(*args, **kwargs):
|
||||
response = f(*args, **kwargs)
|
||||
|
||||
headers = {}
|
||||
status = 200
|
||||
|
||||
if isinstance(response, str):
|
||||
body = response
|
||||
else:
|
||||
if len(response) == 2:
|
||||
body, new_headers = response
|
||||
status = new_headers.get("status", 200)
|
||||
else:
|
||||
status, new_headers, body = response
|
||||
headers.update(new_headers)
|
||||
# Cast status to string
|
||||
if "status" in headers:
|
||||
headers["status"] = str(headers["status"])
|
||||
|
||||
gen_amz_crc32(body, headers)
|
||||
|
||||
return status, headers, body
|
||||
|
||||
return _wrapper
|
||||
|
||||
|
||||
def amzn_request_id(f):
|
||||
@wraps(f)
|
||||
def _wrapper(*args, **kwargs):
|
||||
response = f(*args, **kwargs)
|
||||
|
||||
headers = {}
|
||||
status = 200
|
||||
|
||||
if isinstance(response, str):
|
||||
body = response
|
||||
else:
|
||||
if len(response) == 2:
|
||||
body, new_headers = response
|
||||
status = new_headers.get("status", 200)
|
||||
else:
|
||||
status, new_headers, body = response
|
||||
headers.update(new_headers)
|
||||
|
||||
request_id = gen_amzn_requestid_long(headers)
|
||||
|
||||
# Update request ID in XML
|
||||
try:
|
||||
body = re.sub(r"(?<=<RequestId>).*(?=<\/RequestId>)", request_id, body)
|
||||
except Exception: # Will just ignore if it cant work
|
||||
pass
|
||||
|
||||
return status, headers, body
|
||||
|
||||
return _wrapper
|
||||
|
||||
|
||||
def path_url(url):
|
||||
parsed_url = urlparse(url)
|
||||
path = parsed_url.path
|
||||
|
@ -2,7 +2,7 @@ import json
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from moto.core.responses import BaseResponse
|
||||
from moto.core.utils import amzn_request_id
|
||||
from moto.utilities.aws_headers import amzn_request_id
|
||||
from .models import databrew_backends
|
||||
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
import collections.abc as collections_abc
|
||||
from moto.core.utils import get_random_hex
|
||||
from moto.moto_api._internal import mock_random
|
||||
|
||||
|
||||
def get_random_pipeline_id():
|
||||
return "df-{0}".format(get_random_hex(length=19))
|
||||
return "df-{0}".format(mock_random.get_random_hex(length=19))
|
||||
|
||||
|
||||
def remove_capitalization_of_dict_keys(obj):
|
||||
|
@ -1,7 +1,8 @@
|
||||
"""DAXBackend class with methods for supported APIs."""
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import BackendDict, get_random_hex, unix_time
|
||||
from moto.core.utils import BackendDict, unix_time
|
||||
from moto.moto_api import state_manager
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
from moto.moto_api._internal.managed_state_model import ManagedState
|
||||
from moto.utilities.tagging_service import TaggingService
|
||||
from moto.utilities.paginator import paginate
|
||||
@ -89,7 +90,7 @@ class DaxCluster(BaseModel, ManagedState):
|
||||
self.arn = f"arn:aws:dax:{region}:{account_id}:cache/{self.name}"
|
||||
self.node_type = node_type
|
||||
self.replication_factor = replication_factor
|
||||
self.cluster_hex = get_random_hex(6)
|
||||
self.cluster_hex = random.get_random_hex(6)
|
||||
self.endpoint = DaxEndpoint(
|
||||
name=name, cluster_hex=self.cluster_hex, region=region
|
||||
)
|
||||
@ -99,7 +100,10 @@ class DaxCluster(BaseModel, ManagedState):
|
||||
self.iam_role_arn = iam_role_arn
|
||||
self.parameter_group = DaxParameterGroup()
|
||||
self.security_groups = [
|
||||
{"SecurityGroupIdentifier": f"sg-{get_random_hex(10)}", "Status": "active"}
|
||||
{
|
||||
"SecurityGroupIdentifier": f"sg-{random.get_random_hex(10)}",
|
||||
"Status": "active",
|
||||
}
|
||||
]
|
||||
self.sse_specification = sse_specification
|
||||
self.encryption_type = encryption_type
|
||||
|
@ -2,7 +2,7 @@
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import get_random_hex, BackendDict
|
||||
from moto.core.utils import BackendDict
|
||||
from moto.ds.exceptions import (
|
||||
ClientException,
|
||||
DirectoryLimitExceededException,
|
||||
@ -16,6 +16,7 @@ from moto.ds.utils import PAGINATION_MODEL
|
||||
from moto.ds.validations import validate_args
|
||||
from moto.ec2.exceptions import InvalidSubnetIdError
|
||||
from moto.ec2 import ec2_backends
|
||||
from moto.moto_api._internal import mock_random
|
||||
from moto.utilities.paginator import paginate
|
||||
from moto.utilities.tagging_service import TaggingService
|
||||
|
||||
@ -71,7 +72,7 @@ class Directory(BaseModel): # pylint: disable=too-many-instance-attributes
|
||||
self.edition = edition
|
||||
|
||||
# Calculated or default values for the directory attributes.
|
||||
self.directory_id = f"d-{get_random_hex(10)}"
|
||||
self.directory_id = f"d-{mock_random.get_random_hex(10)}"
|
||||
self.access_url = f"{self.directory_id}.awsapps.com"
|
||||
self.alias = self.directory_id
|
||||
self.desired_number_of_domain_controllers = 0
|
||||
|
@ -4,7 +4,6 @@ import datetime
|
||||
import decimal
|
||||
import json
|
||||
import re
|
||||
import uuid
|
||||
|
||||
from collections import OrderedDict
|
||||
from moto.core import BaseBackend, BaseModel, CloudFormationModel
|
||||
@ -40,6 +39,7 @@ from moto.dynamodb.parsing.executors import UpdateExpressionExecutor
|
||||
from moto.dynamodb.parsing.expressions import UpdateExpressionParser
|
||||
from moto.dynamodb.parsing.validators import UpdateExpressionValidator
|
||||
from moto.dynamodb.limits import HASH_KEY_MAX_LENGTH, RANGE_KEY_MAX_LENGTH
|
||||
from moto.moto_api._internal import mock_random
|
||||
|
||||
|
||||
class DynamoJsonEncoder(json.JSONEncoder):
|
||||
@ -222,7 +222,7 @@ class StreamRecord(BaseModel):
|
||||
keys[table.range_key_attr] = rec.range_key.to_json()
|
||||
|
||||
self.record = {
|
||||
"eventID": uuid.uuid4().hex,
|
||||
"eventID": mock_random.uuid4().hex,
|
||||
"eventName": event_name,
|
||||
"eventSource": "aws:dynamodb",
|
||||
"eventVersion": "1.0",
|
||||
@ -1125,7 +1125,7 @@ class Backup(object):
|
||||
def _make_identifier(self):
|
||||
timestamp = int(unix_time_millis(self.creation_date_time))
|
||||
timestamp_padded = str("0" + str(timestamp))[-16:16]
|
||||
guid = str(uuid.uuid4())
|
||||
guid = str(mock_random.uuid4())
|
||||
guid_shortened = guid[:8]
|
||||
return "{}-{}".format(timestamp_padded, guid_shortened)
|
||||
|
||||
|
@ -5,7 +5,7 @@ import itertools
|
||||
from functools import wraps
|
||||
|
||||
from moto.core.responses import BaseResponse
|
||||
from moto.core.utils import camelcase_to_underscores, amz_crc32, amzn_request_id
|
||||
from moto.core.utils import camelcase_to_underscores
|
||||
from moto.dynamodb.parsing.key_condition_expression import parse_expression
|
||||
from moto.dynamodb.parsing.reserved_keywords import ReservedKeywords
|
||||
from .exceptions import (
|
||||
@ -14,6 +14,7 @@ from .exceptions import (
|
||||
ConditionalCheckFailed,
|
||||
)
|
||||
from moto.dynamodb.models import dynamodb_backends, dynamo_json_dump
|
||||
from moto.utilities.aws_headers import amz_crc32, amzn_request_id
|
||||
|
||||
|
||||
TRANSACTION_MAX_ITEMS = 25
|
||||
|
@ -4,7 +4,7 @@ from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import BackendDict, unix_time
|
||||
from moto.ec2 import ec2_backends
|
||||
from moto.ec2.models.elastic_block_store import Snapshot
|
||||
from uuid import uuid4
|
||||
from moto.moto_api._internal import mock_random
|
||||
|
||||
|
||||
class Block(BaseModel):
|
||||
@ -13,7 +13,7 @@ class Block(BaseModel):
|
||||
self.checksum = checksum
|
||||
self.checksum_algorithm = checksum_algorithm
|
||||
self.data_length = data_length
|
||||
self.block_token = str(uuid4())
|
||||
self.block_token = str(mock_random.uuid4())
|
||||
|
||||
|
||||
class EBSSnapshot(BaseModel):
|
||||
|
@ -1,5 +1,5 @@
|
||||
from moto.core import CloudFormationModel
|
||||
from moto.core.utils import get_random_hex
|
||||
from moto.moto_api._internal import mock_random
|
||||
from .core import TaggedEC2Resource
|
||||
from ..exceptions import UnknownVpcEndpointService
|
||||
|
||||
@ -8,7 +8,7 @@ class VPCServiceConfiguration(TaggedEC2Resource, CloudFormationModel):
|
||||
def __init__(
|
||||
self, load_balancers, region, acceptance_required, private_dns_name, ec2_backend
|
||||
):
|
||||
self.id = f"vpce-svc-{get_random_hex(length=8)}"
|
||||
self.id = f"vpce-svc-{mock_random.get_random_hex(length=8)}"
|
||||
self.service_name = f"com.amazonaws.vpce.{region}.{self.id}"
|
||||
self.service_state = "Available"
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import uuid
|
||||
from moto.ec2.exceptions import FilterNotImplementedError
|
||||
from moto.moto_api._internal import mock_random
|
||||
from ._base_response import EC2BaseResponse
|
||||
|
||||
from xml.etree import ElementTree
|
||||
@ -10,7 +10,7 @@ def xml_root(name):
|
||||
root = ElementTree.Element(
|
||||
name, {"xmlns": "http://ec2.amazonaws.com/doc/2016-11-15/"}
|
||||
)
|
||||
request_id = str(uuid.uuid4()) + "example"
|
||||
request_id = str(mock_random.uuid4()) + "example"
|
||||
ElementTree.SubElement(root, "requestId").text = request_id
|
||||
|
||||
return root
|
||||
|
@ -1,5 +1,5 @@
|
||||
import random
|
||||
from moto.core.utils import camelcase_to_underscores
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
|
||||
from ._base_response import EC2BaseResponse
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
import base64
|
||||
import fnmatch
|
||||
import random
|
||||
import re
|
||||
import ipaddress
|
||||
|
||||
@ -10,6 +9,7 @@ from cryptography.hazmat.backends import default_backend
|
||||
from cryptography.hazmat.primitives.asymmetric import rsa
|
||||
|
||||
from moto.iam import iam_backends
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
from moto.utilities.utils import md5_hash
|
||||
|
||||
EC2_RESOURCE_TO_PREFIX = {
|
||||
|
@ -1,10 +1,8 @@
|
||||
import hashlib
|
||||
import json
|
||||
import re
|
||||
import uuid
|
||||
from collections import namedtuple
|
||||
from datetime import datetime, timezone
|
||||
from random import random
|
||||
from typing import Dict, List
|
||||
|
||||
from botocore.exceptions import ParamValidationError
|
||||
@ -27,6 +25,7 @@ from moto.ecr.exceptions import (
|
||||
from moto.ecr.policy_validation import EcrLifecyclePolicyValidator
|
||||
from moto.iam.exceptions import MalformedPolicyDocument
|
||||
from moto.iam.policy_validation import IAMPolicyDocumentValidator
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
from moto.utilities.tagging_service import TaggingService
|
||||
|
||||
ECR_REPOSITORY_ARN_PATTERN = "^arn:(?P<partition>[^:]+):ecr:(?P<region>[^:]+):(?P<account_id>[^:]+):repository/(?P<repo_name>.*)$"
|
||||
@ -97,7 +96,7 @@ class Repository(BaseObject, CloudFormationModel):
|
||||
if encryption_config == {"encryptionType": "KMS"}:
|
||||
encryption_config[
|
||||
"kmsKey"
|
||||
] = f"arn:aws:kms:{self.region_name}:{self.account_id}:key/{uuid.uuid4()}"
|
||||
] = f"arn:aws:kms:{self.region_name}:{self.account_id}:key/{random.uuid4()}"
|
||||
return encryption_config
|
||||
|
||||
def _get_image(self, image_tag, image_digest):
|
||||
@ -250,7 +249,7 @@ class Image(BaseObject):
|
||||
self.last_scan = None
|
||||
|
||||
def _create_digest(self):
|
||||
image_contents = "docker_image{0}".format(int(random() * 10**6))
|
||||
image_contents = "docker_image{0}".format(int(random.random() * 10**6))
|
||||
self.image_digest = (
|
||||
"sha256:%s" % hashlib.sha256(image_contents.encode("utf-8")).hexdigest()
|
||||
)
|
||||
|
@ -1,8 +1,6 @@
|
||||
import re
|
||||
import uuid
|
||||
from copy import copy
|
||||
from datetime import datetime
|
||||
from random import random, randint
|
||||
|
||||
import pytz
|
||||
|
||||
@ -16,6 +14,7 @@ from moto.core.utils import (
|
||||
BackendDict,
|
||||
)
|
||||
from moto.ec2 import ec2_backends
|
||||
from moto.moto_api._internal import mock_random
|
||||
from moto.utilities.tagging_service import TaggingService
|
||||
from .exceptions import (
|
||||
EcsClientException,
|
||||
@ -243,7 +242,7 @@ class TaskDefinition(BaseObject, CloudFormationModel):
|
||||
properties = cloudformation_json["Properties"]
|
||||
|
||||
family = properties.get(
|
||||
"Family", "task-definition-{0}".format(int(random() * 10**6))
|
||||
"Family", "task-definition-{0}".format(int(mock_random.random() * 10**6))
|
||||
)
|
||||
container_definitions = remap_nested_keys(
|
||||
properties.get("ContainerDefinitions", []), pascal_to_camelcase
|
||||
@ -266,7 +265,7 @@ class TaskDefinition(BaseObject, CloudFormationModel):
|
||||
):
|
||||
properties = cloudformation_json["Properties"]
|
||||
family = properties.get(
|
||||
"Family", "task-definition-{0}".format(int(random() * 10**6))
|
||||
"Family", "task-definition-{0}".format(int(mock_random.random() * 10**6))
|
||||
)
|
||||
container_definitions = properties["ContainerDefinitions"]
|
||||
volumes = properties.get("Volumes")
|
||||
@ -302,7 +301,7 @@ class Task(BaseObject):
|
||||
started_by="",
|
||||
tags=None,
|
||||
):
|
||||
self.id = str(uuid.uuid4())
|
||||
self.id = str(mock_random.uuid4())
|
||||
self.cluster_name = cluster.name
|
||||
self.cluster_arn = cluster.arn
|
||||
self.container_instance_arn = container_instance_arn
|
||||
@ -335,7 +334,7 @@ class Task(BaseObject):
|
||||
|
||||
class CapacityProvider(BaseObject):
|
||||
def __init__(self, account_id, region_name, name, asg_details, tags):
|
||||
self._id = str(uuid.uuid4())
|
||||
self._id = str(mock_random.uuid4())
|
||||
self.capacity_provider_arn = f"arn:aws:ecs:{region_name}:{account_id}:capacity_provider/{name}/{self._id}"
|
||||
self.name = name
|
||||
self.status = "ACTIVE"
|
||||
@ -391,7 +390,7 @@ class Service(BaseObject, CloudFormationModel):
|
||||
{
|
||||
"createdAt": datetime.now(pytz.utc),
|
||||
"desiredCount": self.desired_count,
|
||||
"id": "ecs-svc/{}".format(randint(0, 32**12)),
|
||||
"id": "ecs-svc/{}".format(mock_random.randint(0, 32**12)),
|
||||
"launchType": self.launch_type,
|
||||
"pendingCount": self.desired_count,
|
||||
"runningCount": 0,
|
||||
@ -620,7 +619,7 @@ class ContainerInstance(BaseObject):
|
||||
}
|
||||
self.registered_at = datetime.now(pytz.utc)
|
||||
self.region_name = region_name
|
||||
self.id = str(uuid.uuid4())
|
||||
self.id = str(mock_random.uuid4())
|
||||
self.cluster_name = cluster_name
|
||||
self._account_id = backend.account_id
|
||||
self._backend = backend
|
||||
@ -718,7 +717,7 @@ class TaskSet(BaseObject):
|
||||
self.createdAt = datetime.now(pytz.utc)
|
||||
self.updatedAt = datetime.now(pytz.utc)
|
||||
self.stabilityStatusAt = datetime.now(pytz.utc)
|
||||
self.id = "ecs-svc/{}".format(randint(0, 32**12))
|
||||
self.id = "ecs-svc/{}".format(mock_random.randint(0, 32**12))
|
||||
self.service_arn = ""
|
||||
self.cluster_arn = ""
|
||||
|
||||
|
@ -11,7 +11,6 @@ from copy import deepcopy
|
||||
from moto.core import BaseBackend, BaseModel, CloudFormationModel
|
||||
from moto.core.utils import (
|
||||
camelcase_to_underscores,
|
||||
get_random_hex,
|
||||
underscores_to_camelcase,
|
||||
BackendDict,
|
||||
)
|
||||
@ -30,6 +29,7 @@ from moto.efs.exceptions import (
|
||||
SecurityGroupNotFound,
|
||||
SecurityGroupLimitExceeded,
|
||||
)
|
||||
from moto.moto_api._internal import mock_random
|
||||
from moto.utilities.tagging_service import TaggingService
|
||||
from moto.utilities.utils import md5_hash
|
||||
|
||||
@ -54,7 +54,7 @@ class AccessPoint(BaseModel):
|
||||
root_directory,
|
||||
context,
|
||||
):
|
||||
self.access_point_id = get_random_hex(8)
|
||||
self.access_point_id = mock_random.get_random_hex(8)
|
||||
self.access_point_arn = f"arn:aws:elasticfilesystem:{region_name}:{account_id}:access-point/fsap-{self.access_point_id}"
|
||||
self.client_token = client_token
|
||||
self.file_system_id = file_system_id
|
||||
@ -297,7 +297,7 @@ class MountTarget(CloudFormationModel):
|
||||
|
||||
# Init non-user-assigned values.
|
||||
self.owner_id = account_id
|
||||
self.mount_target_id = "fsmt-{}".format(get_random_hex())
|
||||
self.mount_target_id = "fsmt-{}".format(mock_random.get_random_hex())
|
||||
self.life_cycle_state = "available"
|
||||
self.network_interface_id = None
|
||||
self.availability_zone_id = subnet.availability_zone_id
|
||||
@ -418,7 +418,7 @@ class EFSBackend(BaseBackend):
|
||||
|
||||
# Create a new file system ID:
|
||||
def make_id():
|
||||
return "fs-{}".format(get_random_hex())
|
||||
return "fs-{}".format(mock_random.get_random_hex())
|
||||
|
||||
fsid = make_id()
|
||||
while fsid in self.file_systems_by_id:
|
||||
|
@ -1,10 +1,9 @@
|
||||
from datetime import datetime
|
||||
from uuid import uuid4
|
||||
|
||||
from moto.core import BaseBackend
|
||||
from moto.core.utils import iso_8601_datetime_without_milliseconds, BackendDict
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
|
||||
from ..utilities.utils import random_string
|
||||
from .exceptions import (
|
||||
InvalidParameterException,
|
||||
InvalidRequestException,
|
||||
@ -17,12 +16,14 @@ from .utils import get_partition, validate_role_arn
|
||||
CLUSTER_ARN_TEMPLATE = "arn:{partition}:eks:{region}:{account_id}:cluster/{name}"
|
||||
FARGATE_PROFILE_ARN_TEMPLATE = "arn:{partition}:eks:{region}:{account_id}:fargateprofile/{cluster_name}/{fargate_profile_name}/{uuid}"
|
||||
NODEGROUP_ARN_TEMPLATE = "arn:{partition}:eks:{region}:{account_id}:nodegroup/{cluster_name}/{nodegroup_name}/{uuid}"
|
||||
ISSUER_TEMPLATE = "https://oidc.eks.{region}.amazonaws.com/id/" + random_string(10)
|
||||
ISSUER_TEMPLATE = (
|
||||
"https://oidc.eks.{region}.amazonaws.com/id/" + random.get_random_string(length=10)
|
||||
)
|
||||
ENDPOINT_TEMPLATE = (
|
||||
"https://"
|
||||
+ random_string()
|
||||
+ random.get_random_string()
|
||||
+ "."
|
||||
+ random_string(3)
|
||||
+ random.get_random_string(3)
|
||||
+ ".{region}.eks.amazonaws.com/"
|
||||
)
|
||||
|
||||
@ -120,7 +121,7 @@ class Cluster:
|
||||
region=region_name,
|
||||
name=name,
|
||||
)
|
||||
self.certificateAuthority = {"data": random_string(1400)}
|
||||
self.certificateAuthority = {"data": random.get_random_string(1400)}
|
||||
self.creation_date = iso_8601_datetime_without_milliseconds(datetime.now())
|
||||
self.identity = {"oidc": {"issuer": ISSUER_TEMPLATE.format(region=region_name)}}
|
||||
self.endpoint = ENDPOINT_TEMPLATE.format(region=region_name)
|
||||
@ -182,7 +183,7 @@ class FargateProfile:
|
||||
tags = dict()
|
||||
|
||||
self.created_at = iso_8601_datetime_without_milliseconds(datetime.now())
|
||||
self.uuid = str(uuid4())
|
||||
self.uuid = str(random.uuid4())
|
||||
self.fargate_profile_arn = FARGATE_PROFILE_ARN_TEMPLATE.format(
|
||||
partition=aws_partition,
|
||||
account_id=account_id,
|
||||
@ -244,7 +245,7 @@ class ManagedNodegroup:
|
||||
if taints is None:
|
||||
taints = dict()
|
||||
|
||||
self.uuid = str(uuid4())
|
||||
self.uuid = str(random.uuid4())
|
||||
self.arn = NODEGROUP_ARN_TEMPLATE.format(
|
||||
partition=aws_partition,
|
||||
account_id=account_id,
|
||||
@ -258,7 +259,7 @@ class ManagedNodegroup:
|
||||
self.health = DEFAULT_NODEGROUP_HEALTH
|
||||
self.resources = {
|
||||
"autoScalingGroups": [{"name": "eks-" + self.uuid}],
|
||||
"remoteAccessSecurityGroup": "sg-" + random_string(17).lower(),
|
||||
"remoteAccessSecurityGroup": "sg-" + random.get_random_string(17).lower(),
|
||||
}
|
||||
|
||||
self.ami_type = ami_type or DEFAULT_AMI_TYPE
|
||||
|
@ -1,6 +1,6 @@
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import BackendDict
|
||||
import random
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
import string
|
||||
|
||||
|
||||
|
@ -7,7 +7,7 @@ from moto.core import BaseBackend, BaseModel, CloudFormationModel
|
||||
from moto.core.utils import BackendDict
|
||||
from moto.ec2.models import ec2_backends
|
||||
from moto.ec2.exceptions import InvalidInstanceIdError
|
||||
from uuid import uuid4
|
||||
from moto.moto_api._internal import mock_random
|
||||
from .exceptions import (
|
||||
BadHealthCheckDefinition,
|
||||
DuplicateLoadBalancerName,
|
||||
@ -306,7 +306,7 @@ class ELBBackend(BaseBackend):
|
||||
raise EmptyListenersError()
|
||||
if not security_groups:
|
||||
sg = ec2_backend.create_security_group(
|
||||
name=f"default_elb_{uuid4()}",
|
||||
name=f"default_elb_{mock_random.uuid4()}",
|
||||
description="ELB created security group used when no security group is specified during ELB creation - modifications could impact traffic to future ELBs",
|
||||
vpc_id=vpc_id,
|
||||
)
|
||||
|
@ -7,10 +7,10 @@ from moto.core.exceptions import RESTError
|
||||
from moto.core import BaseBackend, BaseModel, CloudFormationModel
|
||||
from moto.core.utils import (
|
||||
iso_8601_datetime_with_milliseconds,
|
||||
get_random_hex,
|
||||
BackendDict,
|
||||
)
|
||||
from moto.ec2.models import ec2_backends
|
||||
from moto.moto_api._internal import mock_random
|
||||
from moto.utilities.tagging_service import TaggingService
|
||||
from .utils import make_arn_for_target_group
|
||||
from .utils import make_arn_for_load_balancer
|
||||
@ -757,7 +757,7 @@ class ELBv2Backend(BaseBackend):
|
||||
|
||||
self._validate_actions(actions)
|
||||
arn = listener_arn.replace(":listener/", ":listener-rule/")
|
||||
arn += "/%s" % (get_random_hex(16))
|
||||
arn += f"/{mock_random.get_random_hex(16)}"
|
||||
|
||||
# TODO: check for error 'TooManyRegistrationsForTargetId'
|
||||
# TODO: check for error 'TooManyRules'
|
||||
|
@ -1,6 +1,6 @@
|
||||
from moto.core.exceptions import RESTError
|
||||
from moto.core.utils import amzn_request_id
|
||||
from moto.core.responses import BaseResponse
|
||||
from moto.utilities.aws_headers import amzn_request_id
|
||||
from .models import elbv2_backends
|
||||
from .exceptions import TargetGroupNotFoundError
|
||||
from .exceptions import ListenerOrBalancerMissingError
|
||||
|
@ -1,12 +1,12 @@
|
||||
import copy
|
||||
import datetime
|
||||
import random
|
||||
import re
|
||||
import string
|
||||
from moto.core.utils import (
|
||||
camelcase_to_underscores,
|
||||
iso_8601_datetime_with_milliseconds,
|
||||
)
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
|
||||
|
||||
def random_id(size=13):
|
||||
|
@ -1,6 +1,6 @@
|
||||
# import json
|
||||
import string
|
||||
import random
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
|
||||
|
||||
def get_partition(region):
|
||||
|
@ -1,5 +1,4 @@
|
||||
# import json
|
||||
import random
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
import string
|
||||
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import get_random_hex, BackendDict
|
||||
from moto.core.utils import BackendDict
|
||||
from moto.moto_api._internal import mock_random
|
||||
from .exceptions import DomainNotFound
|
||||
|
||||
|
||||
@ -23,7 +24,7 @@ class Domain(BaseModel):
|
||||
advanced_security_options,
|
||||
auto_tune_options,
|
||||
):
|
||||
self.domain_id = get_random_hex(8)
|
||||
self.domain_id = mock_random.get_random_hex(8)
|
||||
self.region_name = region_name
|
||||
self.domain_name = domain_name
|
||||
self.es_version = es_version
|
||||
|
@ -26,11 +26,10 @@ from moto.events.exceptions import (
|
||||
InvalidEventPatternException,
|
||||
IllegalStatusException,
|
||||
)
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
from moto.utilities.paginator import paginate
|
||||
from moto.utilities.tagging_service import TaggingService
|
||||
|
||||
from uuid import uuid4
|
||||
|
||||
from .utils import PAGINATION_MODEL
|
||||
|
||||
# Sentinel to signal the absence of a field for `Exists` pattern matching
|
||||
@ -183,12 +182,9 @@ class Rule(CloudFormationModel):
|
||||
datetime.utcfromtimestamp(event_copy["time"])
|
||||
)
|
||||
|
||||
log_stream_name = str(uuid4())
|
||||
log_stream_name = str(random.uuid4())
|
||||
log_events = [
|
||||
{
|
||||
"timestamp": unix_time_millis(datetime.utcnow()),
|
||||
"message": json.dumps(event_copy),
|
||||
}
|
||||
{"timestamp": unix_time_millis(), "message": json.dumps(event_copy)}
|
||||
]
|
||||
|
||||
log_backend = logs_backends[self.account_id][self.region_name]
|
||||
@ -521,7 +517,7 @@ class Archive(CloudFormationModel):
|
||||
self.arn = f"arn:aws:events:{region_name}:{account_id}:archive/{name}"
|
||||
self.creation_time = unix_time(datetime.utcnow())
|
||||
self.state = "ENABLED"
|
||||
self.uuid = str(uuid4())
|
||||
self.uuid = str(random.uuid4())
|
||||
|
||||
self.events = []
|
||||
self.event_bus_name = source_arn.split("/")[-1]
|
||||
@ -691,7 +687,9 @@ class Replay(BaseModel):
|
||||
for rule in event_backend.rules.values():
|
||||
rule.send_to_targets(
|
||||
event_bus_name,
|
||||
dict(event, **{"id": str(uuid4()), "replay-name": self.name}),
|
||||
dict(
|
||||
event, **{"id": str(random.uuid4()), "replay-name": self.name}
|
||||
),
|
||||
)
|
||||
|
||||
self.state = ReplayState.COMPLETED
|
||||
@ -708,7 +706,7 @@ class Connection(BaseModel):
|
||||
authorization_type,
|
||||
auth_parameters,
|
||||
):
|
||||
self.uuid = uuid4()
|
||||
self.uuid = random.uuid4()
|
||||
self.name = name
|
||||
self.region = region_name
|
||||
self.description = description
|
||||
@ -784,7 +782,7 @@ class Destination(BaseModel):
|
||||
invocation_rate_limit_per_second,
|
||||
http_method,
|
||||
):
|
||||
self.uuid = uuid4()
|
||||
self.uuid = random.uuid4()
|
||||
self.name = name
|
||||
self.region = region_name
|
||||
self.description = description
|
||||
@ -1234,7 +1232,7 @@ class EventsBackend(BaseBackend):
|
||||
)
|
||||
continue
|
||||
|
||||
event_id = str(uuid4())
|
||||
event_id = str(random.uuid4())
|
||||
entries.append({"EventId": event_id})
|
||||
|
||||
# if 'EventBusName' is not especially set, it will be sent to the default one
|
||||
|
@ -21,7 +21,6 @@ from gzip import GzipFile
|
||||
import io
|
||||
import json
|
||||
from time import time
|
||||
from uuid import uuid4
|
||||
import warnings
|
||||
|
||||
import requests
|
||||
@ -36,6 +35,7 @@ from moto.firehose.exceptions import (
|
||||
ResourceNotFoundException,
|
||||
ValidationException,
|
||||
)
|
||||
from moto.moto_api._internal import mock_random
|
||||
from moto.s3.models import s3_backends
|
||||
from moto.utilities.tagging_service import TaggingService
|
||||
|
||||
@ -407,7 +407,7 @@ class FirehoseBackend(BaseBackend):
|
||||
url = http_destination["EndpointConfiguration"]["Url"]
|
||||
headers = {"Content-Type": "application/json"}
|
||||
record_to_send = {
|
||||
"requestId": str(uuid4()),
|
||||
"requestId": str(mock_random.uuid4()),
|
||||
"timestamp": int(time()),
|
||||
"records": [{"data": record["Data"]} for record in records],
|
||||
}
|
||||
@ -418,7 +418,7 @@ class FirehoseBackend(BaseBackend):
|
||||
raise RuntimeError(
|
||||
"Firehose PutRecord(Batch) to HTTP destination failed"
|
||||
) from exc
|
||||
return [{"RecordId": str(uuid4())} for _ in range(len(records))]
|
||||
return [{"RecordId": str(mock_random.uuid4())} for _ in range(len(records))]
|
||||
|
||||
@staticmethod
|
||||
def _format_s3_object_path(delivery_stream_name, version_id, prefix):
|
||||
@ -433,7 +433,7 @@ class FirehoseBackend(BaseBackend):
|
||||
return (
|
||||
f"{prefix}{now.strftime('%Y/%m/%d/%H')}/"
|
||||
f"{delivery_stream_name}-{version_id}-"
|
||||
f"{now.strftime('%Y-%m-%d-%H-%M-%S')}-{str(uuid4())}"
|
||||
f"{now.strftime('%Y-%m-%d-%H-%M-%S')}-{str(mock_random.uuid4())}"
|
||||
)
|
||||
|
||||
def put_s3_records(self, delivery_stream_name, version_id, s3_destination, records):
|
||||
@ -455,7 +455,7 @@ class FirehoseBackend(BaseBackend):
|
||||
raise RuntimeError(
|
||||
"Firehose PutRecord(Batch to S3 destination failed"
|
||||
) from exc
|
||||
return [{"RecordId": str(uuid4())} for _ in range(len(records))]
|
||||
return [{"RecordId": str(mock_random.uuid4())} for _ in range(len(records))]
|
||||
|
||||
def put_record_batch(self, delivery_stream_name, records):
|
||||
"""Write multiple data records into a Kinesis Data firehose stream."""
|
||||
@ -494,7 +494,7 @@ class FirehoseBackend(BaseBackend):
|
||||
# This isn't implmented as these services aren't implemented,
|
||||
# so ignore the data, but return a "proper" response.
|
||||
request_responses = [
|
||||
{"RecordId": str(uuid4())} for _ in range(len(records))
|
||||
{"RecordId": str(mock_random.uuid4())} for _ in range(len(records))
|
||||
]
|
||||
|
||||
return {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import json
|
||||
|
||||
from moto.core.responses import BaseResponse
|
||||
from moto.core.utils import amzn_request_id
|
||||
from moto.utilities.aws_headers import amzn_request_id
|
||||
from .models import forecast_backends
|
||||
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import random
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
import string
|
||||
|
||||
|
||||
|
@ -2,11 +2,11 @@ import time
|
||||
from collections import OrderedDict
|
||||
from datetime import datetime
|
||||
from typing import List
|
||||
from uuid import uuid4
|
||||
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import BackendDict
|
||||
from moto.moto_api import state_manager
|
||||
from moto.moto_api._internal import mock_random
|
||||
from moto.moto_api._internal.managed_state_model import ManagedState
|
||||
from .exceptions import (
|
||||
JsonRESTError,
|
||||
@ -1072,7 +1072,7 @@ class FakeSchemaVersion(BaseModel):
|
||||
self.schema_definition = schema_definition
|
||||
self.schema_version_status = AVAILABLE_STATUS
|
||||
self.version_number = version_number
|
||||
self.schema_version_id = str(uuid4())
|
||||
self.schema_version_id = str(mock_random.uuid4())
|
||||
self.created_time = datetime.utcnow()
|
||||
self.updated_time = datetime.utcnow()
|
||||
self.metadata = OrderedDict()
|
||||
|
@ -1,11 +1,11 @@
|
||||
import json
|
||||
import uuid
|
||||
from collections import OrderedDict
|
||||
from datetime import datetime
|
||||
import re
|
||||
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import BackendDict, iso_8601_datetime_with_milliseconds
|
||||
from moto.moto_api._internal import mock_random
|
||||
from .exceptions import (
|
||||
GreengrassClientError,
|
||||
IdNotFoundException,
|
||||
@ -21,7 +21,7 @@ class FakeCoreDefinition(BaseModel):
|
||||
def __init__(self, account_id, region_name, name):
|
||||
self.region_name = region_name
|
||||
self.name = name
|
||||
self.id = str(uuid.uuid4())
|
||||
self.id = str(mock_random.uuid4())
|
||||
self.arn = f"arn:aws:greengrass:{region_name}:{account_id}:greengrass/definition/cores/{self.id}"
|
||||
self.created_at_datetime = datetime.utcnow()
|
||||
self.latest_version = ""
|
||||
@ -48,7 +48,7 @@ class FakeCoreDefinitionVersion(BaseModel):
|
||||
self.region_name = region_name
|
||||
self.core_definition_id = core_definition_id
|
||||
self.definition = definition
|
||||
self.version = str(uuid.uuid4())
|
||||
self.version = str(mock_random.uuid4())
|
||||
self.arn = f"arn:aws:greengrass:{region_name}:{account_id}:greengrass/definition/cores/{self.core_definition_id}/versions/{self.version}"
|
||||
self.created_at_datetime = datetime.utcnow()
|
||||
|
||||
@ -71,7 +71,7 @@ class FakeCoreDefinitionVersion(BaseModel):
|
||||
class FakeDeviceDefinition(BaseModel):
|
||||
def __init__(self, account_id, region_name, name, initial_version):
|
||||
self.region_name = region_name
|
||||
self.id = str(uuid.uuid4())
|
||||
self.id = str(mock_random.uuid4())
|
||||
self.arn = f"arn:aws:greengrass:{region_name}:{account_id}:greengrass/definition/devices/{self.id}"
|
||||
self.created_at_datetime = datetime.utcnow()
|
||||
self.update_at_datetime = datetime.utcnow()
|
||||
@ -103,7 +103,7 @@ class FakeDeviceDefinitionVersion(BaseModel):
|
||||
self.region_name = region_name
|
||||
self.device_definition_id = device_definition_id
|
||||
self.devices = devices
|
||||
self.version = str(uuid.uuid4())
|
||||
self.version = str(mock_random.uuid4())
|
||||
self.arn = f"arn:aws:greengrass:{region_name}:{account_id}:greengrass/definition/devices/{self.device_definition_id}/versions/{self.version}"
|
||||
self.created_at_datetime = datetime.utcnow()
|
||||
|
||||
@ -126,7 +126,7 @@ class FakeDeviceDefinitionVersion(BaseModel):
|
||||
class FakeResourceDefinition(BaseModel):
|
||||
def __init__(self, account_id, region_name, name, initial_version):
|
||||
self.region_name = region_name
|
||||
self.id = str(uuid.uuid4())
|
||||
self.id = str(mock_random.uuid4())
|
||||
self.arn = f"arn:aws:greengrass:{region_name}:{account_id}:greengrass/definition/resources/{self.id}"
|
||||
self.created_at_datetime = datetime.utcnow()
|
||||
self.update_at_datetime = datetime.utcnow()
|
||||
@ -156,7 +156,7 @@ class FakeResourceDefinitionVersion(BaseModel):
|
||||
self.region_name = region_name
|
||||
self.resource_definition_id = resource_definition_id
|
||||
self.resources = resources
|
||||
self.version = str(uuid.uuid4())
|
||||
self.version = str(mock_random.uuid4())
|
||||
self.arn = f"arn:aws:greengrass:{region_name}:{account_id}:greengrass/definition/resources/{self.resource_definition_id}/versions/{self.version}"
|
||||
self.created_at_datetime = datetime.utcnow()
|
||||
|
||||
@ -175,7 +175,7 @@ class FakeResourceDefinitionVersion(BaseModel):
|
||||
class FakeFunctionDefinition(BaseModel):
|
||||
def __init__(self, account_id, region_name, name, initial_version):
|
||||
self.region_name = region_name
|
||||
self.id = str(uuid.uuid4())
|
||||
self.id = str(mock_random.uuid4())
|
||||
self.arn = f"arn:aws:greengrass:{self.region_name}:{account_id}:greengrass/definition/functions/{self.id}"
|
||||
self.created_at_datetime = datetime.utcnow()
|
||||
self.update_at_datetime = datetime.utcnow()
|
||||
@ -210,7 +210,7 @@ class FakeFunctionDefinitionVersion(BaseModel):
|
||||
self.function_definition_id = function_definition_id
|
||||
self.functions = functions
|
||||
self.default_config = default_config
|
||||
self.version = str(uuid.uuid4())
|
||||
self.version = str(mock_random.uuid4())
|
||||
self.arn = f"arn:aws:greengrass:{self.region_name}:{account_id}:greengrass/definition/functions/{self.function_definition_id}/versions/{self.version}"
|
||||
self.created_at_datetime = datetime.utcnow()
|
||||
|
||||
@ -229,7 +229,7 @@ class FakeFunctionDefinitionVersion(BaseModel):
|
||||
class FakeSubscriptionDefinition(BaseModel):
|
||||
def __init__(self, account_id, region_name, name, initial_version):
|
||||
self.region_name = region_name
|
||||
self.id = str(uuid.uuid4())
|
||||
self.id = str(mock_random.uuid4())
|
||||
self.arn = f"arn:aws:greengrass:{self.region_name}:{account_id}:greengrass/definition/subscriptions/{self.id}"
|
||||
self.created_at_datetime = datetime.utcnow()
|
||||
self.update_at_datetime = datetime.utcnow()
|
||||
@ -261,7 +261,7 @@ class FakeSubscriptionDefinitionVersion(BaseModel):
|
||||
self.region_name = region_name
|
||||
self.subscription_definition_id = subscription_definition_id
|
||||
self.subscriptions = subscriptions
|
||||
self.version = str(uuid.uuid4())
|
||||
self.version = str(mock_random.uuid4())
|
||||
self.arn = f"arn:aws:greengrass:{self.region_name}:{account_id}:greengrass/definition/subscriptions/{self.subscription_definition_id}/versions/{self.version}"
|
||||
self.created_at_datetime = datetime.utcnow()
|
||||
|
||||
@ -280,7 +280,7 @@ class FakeSubscriptionDefinitionVersion(BaseModel):
|
||||
class FakeGroup(BaseModel):
|
||||
def __init__(self, account_id, region_name, name):
|
||||
self.region_name = region_name
|
||||
self.group_id = str(uuid.uuid4())
|
||||
self.group_id = str(mock_random.uuid4())
|
||||
self.name = name
|
||||
self.arn = f"arn:aws:greengrass:{self.region_name}:{account_id}:greengrass/groups/{self.group_id}"
|
||||
self.created_at_datetime = datetime.utcnow()
|
||||
@ -319,7 +319,7 @@ class FakeGroupVersion(BaseModel):
|
||||
):
|
||||
self.region_name = region_name
|
||||
self.group_id = group_id
|
||||
self.version = str(uuid.uuid4())
|
||||
self.version = str(mock_random.uuid4())
|
||||
self.arn = f"arn:aws:greengrass:{self.region_name}:{account_id}:greengrass/groups/{self.group_id}/versions/{self.version}"
|
||||
self.created_at_datetime = datetime.utcnow()
|
||||
self.core_definition_version_arn = core_definition_version_arn
|
||||
@ -372,7 +372,7 @@ class FakeGroupVersion(BaseModel):
|
||||
class FakeDeployment(BaseModel):
|
||||
def __init__(self, account_id, region_name, group_id, group_arn, deployment_type):
|
||||
self.region_name = region_name
|
||||
self.id = str(uuid.uuid4())
|
||||
self.id = str(mock_random.uuid4())
|
||||
self.group_id = group_id
|
||||
self.group_arn = group_arn
|
||||
self.created_at_datetime = datetime.utcnow()
|
||||
|
@ -1,6 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import BackendDict, get_random_hex
|
||||
from moto.core.utils import BackendDict
|
||||
from moto.moto_api._internal import mock_random
|
||||
from datetime import datetime
|
||||
|
||||
from .exceptions import DetectorNotFoundException, FilterNotFoundException
|
||||
@ -129,7 +130,7 @@ class Detector(BaseModel):
|
||||
datasources,
|
||||
tags,
|
||||
):
|
||||
self.id = get_random_hex(length=32)
|
||||
self.id = mock_random.get_random_hex(length=32)
|
||||
self.created_at = created_at
|
||||
self.finding_publish_freq = finding_publish_freq
|
||||
self.service_role = f"arn:aws:iam::{account_id}:role/aws-service-role/guardduty.amazonaws.com/AWSServiceRoleForAmazonGuardDuty"
|
||||
|
@ -1,9 +1,7 @@
|
||||
import base64
|
||||
import os
|
||||
import random
|
||||
import string
|
||||
import sys
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
import json
|
||||
import re
|
||||
@ -26,6 +24,7 @@ from moto.iam.policy_validation import (
|
||||
IAMPolicyDocumentValidator,
|
||||
IAMTrustPolicyDocumentValidator,
|
||||
)
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
from moto.utilities.utils import md5_hash
|
||||
|
||||
from .aws_managed_policies import aws_managed_policies_data
|
||||
@ -3029,7 +3028,7 @@ class IAMBackend(BaseBackend):
|
||||
|
||||
def delete_service_linked_role(self, role_name):
|
||||
self.delete_role(role_name)
|
||||
deletion_task_id = str(uuid.uuid4())
|
||||
deletion_task_id = str(random.uuid4())
|
||||
return deletion_task_id
|
||||
|
||||
def get_service_linked_role_deletion_status(self):
|
||||
|
@ -1,4 +1,4 @@
|
||||
import random
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
import string
|
||||
|
||||
|
||||
|
@ -1,9 +1,6 @@
|
||||
import hashlib
|
||||
import random
|
||||
import re
|
||||
import string
|
||||
import time
|
||||
import uuid
|
||||
from collections import OrderedDict
|
||||
from cryptography import x509
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
@ -16,7 +13,7 @@ from .utils import PAGINATION_MODEL
|
||||
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import BackendDict
|
||||
from moto.utilities.utils import random_string
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
from moto.utilities.paginator import paginate
|
||||
from .exceptions import (
|
||||
CertificateStateException,
|
||||
@ -74,7 +71,7 @@ class FakeThingType(BaseModel):
|
||||
self.region_name = region_name
|
||||
self.thing_type_name = thing_type_name
|
||||
self.thing_type_properties = thing_type_properties
|
||||
self.thing_type_id = str(uuid.uuid4()) # I don't know the rule of id
|
||||
self.thing_type_id = str(random.uuid4()) # I don't know the rule of id
|
||||
t = time.time()
|
||||
self.metadata = {"deprecated": False, "creationDate": int(t * 1000) / 1000.0}
|
||||
self.arn = "arn:aws:iot:%s:1:thingtype/%s" % (self.region_name, thing_type_name)
|
||||
@ -100,7 +97,7 @@ class FakeThingGroup(BaseModel):
|
||||
):
|
||||
self.region_name = region_name
|
||||
self.thing_group_name = thing_group_name
|
||||
self.thing_group_id = str(uuid.uuid4()) # I don't know the rule of id
|
||||
self.thing_group_id = str(random.uuid4()) # I don't know the rule of id
|
||||
self.version = 1 # TODO: tmp
|
||||
self.parent_group_name = parent_group_name
|
||||
self.thing_group_properties = thing_group_properties or {}
|
||||
@ -434,7 +431,7 @@ class FakeEndpoint(BaseModel):
|
||||
"operation: Endpoint type %s not recognized." % endpoint_type
|
||||
)
|
||||
self.region_name = region_name
|
||||
identifier = random_string(14).lower()
|
||||
identifier = random.get_random_string(length=14, lower_case=True)
|
||||
if endpoint_type == "iot:Data":
|
||||
self.endpoint = "{i}.iot.{r}.amazonaws.com".format(
|
||||
i=identifier, r=self.region_name
|
||||
@ -540,7 +537,7 @@ class FakeDomainConfiguration(BaseModel):
|
||||
self.domain_configuration_arn = "arn:aws:iot:%s:1:domainconfiguration/%s/%s" % (
|
||||
region_name,
|
||||
domain_configuration_name,
|
||||
random_string(5),
|
||||
random.get_random_string(length=5),
|
||||
)
|
||||
self.domain_name = domain_name
|
||||
self.server_certificates = []
|
||||
@ -836,21 +833,14 @@ class IoTBackend(BaseBackend):
|
||||
else:
|
||||
thing.attributes.update(attributes)
|
||||
|
||||
def _random_string(self):
|
||||
n = 20
|
||||
random_str = "".join(
|
||||
[random.choice(string.ascii_letters + string.digits) for i in range(n)]
|
||||
)
|
||||
return random_str
|
||||
|
||||
def create_keys_and_certificate(self, set_as_active):
|
||||
# implement here
|
||||
# caCertificate can be blank
|
||||
key_pair = {
|
||||
"PublicKey": self._random_string(),
|
||||
"PrivateKey": self._random_string(),
|
||||
"PublicKey": random.get_random_string(),
|
||||
"PrivateKey": random.get_random_string(),
|
||||
}
|
||||
certificate_pem = self._random_string()
|
||||
certificate_pem = random.get_random_string()
|
||||
status = "ACTIVE" if set_as_active else "INACTIVE"
|
||||
certificate = FakeCertificate(
|
||||
certificate_pem, status, self.account_id, self.region_name
|
||||
@ -910,7 +900,7 @@ class IoTBackend(BaseBackend):
|
||||
return certs[0]
|
||||
|
||||
def get_registration_code(self):
|
||||
return str(uuid.uuid4())
|
||||
return str(random.uuid4())
|
||||
|
||||
def list_certificates(self):
|
||||
"""
|
||||
|
@ -1,9 +1,8 @@
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from datetime import datetime
|
||||
from .exceptions import ResourceNotFoundException, ResourceInUseException
|
||||
import random
|
||||
import string
|
||||
from moto.core.utils import get_random_hex, BackendDict
|
||||
from moto.core.utils import BackendDict
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
|
||||
|
||||
class Stream(BaseModel):
|
||||
@ -26,17 +25,12 @@ class Stream(BaseModel):
|
||||
self.data_retention_in_hours = data_retention_in_hours
|
||||
self.tags = tags
|
||||
self.status = "ACTIVE"
|
||||
self.version = self._get_random_string()
|
||||
self.version = random.get_random_string(include_digits=False, lower_case=True)
|
||||
self.creation_time = datetime.utcnow()
|
||||
stream_arn = f"arn:aws:kinesisvideo:{region_name}:{account_id}:stream/{stream_name}/1598784211076"
|
||||
self.data_endpoint_number = get_random_hex()
|
||||
self.data_endpoint_number = random.get_random_hex()
|
||||
self.arn = stream_arn
|
||||
|
||||
def _get_random_string(self, length=20):
|
||||
letters = string.ascii_lowercase
|
||||
result_str = "".join([random.choice(letters) for _ in range(length)])
|
||||
return result_str
|
||||
|
||||
def get_data_endpoint(self, api_name):
|
||||
data_endpoint_prefix = "s-" if api_name in ("PUT_MEDIA", "GET_MEDIA") else "b-"
|
||||
return "https://{}{}.kinesisvideo.{}.amazonaws.com".format(
|
||||
|
@ -9,7 +9,8 @@ from cryptography.hazmat.primitives import hashes
|
||||
from cryptography.hazmat.primitives.asymmetric import padding
|
||||
|
||||
from moto.core import BaseBackend, BaseModel, CloudFormationModel
|
||||
from moto.core.utils import get_random_hex, unix_time, BackendDict
|
||||
from moto.core.utils import unix_time, BackendDict
|
||||
from moto.moto_api._internal import mock_random
|
||||
from moto.utilities.tagging_service import TaggingService
|
||||
from moto.core.exceptions import JsonRESTError
|
||||
|
||||
@ -40,8 +41,8 @@ class Grant(BaseModel):
|
||||
self.retiring_principal = retiring_principal
|
||||
self.operations = operations
|
||||
self.constraints = constraints
|
||||
self.id = get_random_hex()
|
||||
self.token = get_random_hex()
|
||||
self.id = mock_random.get_random_hex()
|
||||
self.token = mock_random.get_random_hex()
|
||||
|
||||
def to_json(self):
|
||||
return {
|
||||
|
@ -2,7 +2,7 @@ from collections import namedtuple
|
||||
import io
|
||||
import os
|
||||
import struct
|
||||
import uuid
|
||||
from moto.moto_api._internal import mock_random
|
||||
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
from cryptography.hazmat.primitives.ciphers import algorithms, Cipher, modes
|
||||
@ -46,7 +46,7 @@ RESERVED_ALIASES = [
|
||||
|
||||
|
||||
def generate_key_id(multi_region=False):
|
||||
key = str(uuid.uuid4())
|
||||
key = str(mock_random.uuid4())
|
||||
# https://docs.aws.amazon.com/kms/latest/developerguide/multi-region-keys-overview.html
|
||||
# "Notice that multi-Region keys have a distinctive key ID that begins with mrk-. You can use the mrk- prefix to
|
||||
# identify MRKs programmatically."
|
||||
|
@ -1,11 +1,8 @@
|
||||
import uuid
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core import CloudFormationModel
|
||||
from moto.core.utils import unix_time_millis, BackendDict
|
||||
from moto.utilities.paginator import paginate
|
||||
from moto.logs.metric_filters import MetricFilters
|
||||
from moto.logs.exceptions import (
|
||||
ResourceNotFoundException,
|
||||
@ -13,7 +10,9 @@ from moto.logs.exceptions import (
|
||||
InvalidParameterException,
|
||||
LimitExceededException,
|
||||
)
|
||||
from moto.moto_api._internal import mock_random
|
||||
from moto.s3.models import s3_backends
|
||||
from moto.utilities.paginator import paginate
|
||||
from .utils import PAGINATION_MODEL, EventMessageFilter
|
||||
|
||||
MAX_RESOURCE_POLICIES_PER_REGION = 10
|
||||
@ -943,7 +942,7 @@ class LogsBackend(BaseBackend):
|
||||
if log_group_name not in self.groups:
|
||||
raise ResourceNotFoundException()
|
||||
|
||||
query_id = uuid.uuid1()
|
||||
query_id = mock_random.uuid1()
|
||||
self.queries[query_id] = LogQuery(query_id, start_time, end_time, query_string)
|
||||
return query_id
|
||||
|
||||
@ -951,7 +950,7 @@ class LogsBackend(BaseBackend):
|
||||
s3_backends[self.account_id]["global"].get_bucket(destination)
|
||||
if log_group_name not in self.groups:
|
||||
raise ResourceNotFoundException()
|
||||
task_id = uuid.uuid4()
|
||||
task_id = mock_random.uuid4()
|
||||
return task_id
|
||||
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
import json
|
||||
import random
|
||||
import re
|
||||
import string
|
||||
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
from urllib.parse import parse_qs, urlparse
|
||||
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
from collections import OrderedDict
|
||||
from uuid import uuid4
|
||||
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import BackendDict
|
||||
from moto.mediaconnect.exceptions import NotFoundException
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
|
||||
|
||||
class Flow(BaseModel):
|
||||
@ -87,7 +87,7 @@ class MediaConnectBackend(BaseBackend):
|
||||
source["ingestIp"] = ingest_ip
|
||||
|
||||
def _create_flow_add_details(self, flow):
|
||||
flow_id = uuid4().hex
|
||||
flow_id = random.uuid4().hex
|
||||
|
||||
flow.description = "A Moto test flow"
|
||||
flow.egress_ip = "127.0.0.1"
|
||||
@ -248,7 +248,7 @@ class MediaConnectBackend(BaseBackend):
|
||||
)
|
||||
flow = self._flows[flow_arn]
|
||||
for source in sources:
|
||||
source_id = uuid4().hex
|
||||
source_id = random.uuid4().hex
|
||||
name = source["name"]
|
||||
arn = f"arn:aws:mediaconnect:{self.region_name}:{self.account_id}:source:{source_id}:{name}"
|
||||
source["sourceArn"] = arn
|
||||
|
@ -1,8 +1,8 @@
|
||||
from collections import OrderedDict
|
||||
from uuid import uuid4
|
||||
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import BackendDict
|
||||
from moto.moto_api._internal import mock_random
|
||||
|
||||
|
||||
class Input(BaseModel):
|
||||
@ -134,7 +134,7 @@ class MediaLiveBackend(BaseBackend):
|
||||
"""
|
||||
The RequestID and Reserved parameters are not yet implemented
|
||||
"""
|
||||
channel_id = uuid4().hex
|
||||
channel_id = mock_random.uuid4().hex
|
||||
arn = "arn:aws:medialive:channel:{}".format(channel_id)
|
||||
channel = Channel(
|
||||
arn=arn,
|
||||
@ -228,7 +228,7 @@ class MediaLiveBackend(BaseBackend):
|
||||
"""
|
||||
The VPC and RequestId parameters are not yet implemented
|
||||
"""
|
||||
input_id = uuid4().hex
|
||||
input_id = mock_random.uuid4().hex
|
||||
arn = "arn:aws:medialive:input:{}".format(input_id)
|
||||
a_input = Input(
|
||||
arn=arn,
|
||||
|
@ -1,6 +1,12 @@
|
||||
from .models import moto_api_backend
|
||||
from .state_manager import StateManager # noqa
|
||||
from .recorder.models import Recorder # noqa
|
||||
from .moto_random import MotoRandom
|
||||
|
||||
|
||||
moto_api_backends = {"global": moto_api_backend}
|
||||
|
||||
"""
|
||||
Random-object used throughout Moto. Can be seeded to make identifiers deterministic.
|
||||
"""
|
||||
mock_random = MotoRandom()
|
||||
|
30
moto/moto_api/_internal/moto_random.py
Normal file
30
moto/moto_api/_internal/moto_random.py
Normal file
@ -0,0 +1,30 @@
|
||||
from random import Random
|
||||
import string
|
||||
import uuid
|
||||
|
||||
|
||||
HEX_CHARS = list(range(10)) + ["a", "b", "c", "d", "e", "f"]
|
||||
|
||||
|
||||
class MotoRandom(Random):
|
||||
"""
|
||||
Class used for all sources of random-ness in Moto.
|
||||
Used as a singleton, which is exposed in `moto/moto_api/_internal`.
|
||||
This Singleton can be seeded to make identifiers deterministic.
|
||||
"""
|
||||
|
||||
def uuid1(self):
|
||||
return uuid.UUID(int=self.getrandbits(128), version=1)
|
||||
|
||||
def uuid4(self):
|
||||
return uuid.UUID(int=self.getrandbits(128), version=4)
|
||||
|
||||
def get_random_hex(self, length=8):
|
||||
return "".join(str(self.choice(HEX_CHARS)) for _ in range(length))
|
||||
|
||||
def get_random_string(self, length=20, include_digits=True, lower_case=False):
|
||||
pool = string.ascii_letters
|
||||
if include_digits:
|
||||
pool += string.digits
|
||||
random_str = "".join([self.choice(pool) for i in range(length)])
|
||||
return random_str.lower() if lower_case else random_str
|
@ -44,9 +44,9 @@ class Recorder:
|
||||
body_encoded = False
|
||||
finally:
|
||||
if request_body is not None:
|
||||
if isinstance(request_body, bytes):
|
||||
request_body = request_body.decode("utf-8")
|
||||
request.environ["wsgi.input"] = io.StringIO(request_body)
|
||||
if isinstance(request_body, str):
|
||||
request_body = request_body.encode("utf-8")
|
||||
request.environ["wsgi.input"] = io.BytesIO(request_body)
|
||||
else:
|
||||
body, body_encoded = self._encode_body(body)
|
||||
entry.update({"body": body, "body_encoded": body_encoded})
|
||||
@ -87,9 +87,11 @@ class Recorder:
|
||||
|
||||
def upload_recording(self, data):
|
||||
"""
|
||||
Replace the current log. Remember to replay the recording afterwards.
|
||||
Replaces the current log. Remember to replay the recording afterwards.
|
||||
"""
|
||||
filepath = self._location
|
||||
if isinstance(data, str):
|
||||
data = data.encode("utf-8")
|
||||
with open(filepath, "bw") as file:
|
||||
file.write(data)
|
||||
|
||||
|
@ -106,3 +106,11 @@ class MotoAPIResponse(BaseResponse):
|
||||
|
||||
moto_api_backend.unset_transition(model_name)
|
||||
return 201, {}, ""
|
||||
|
||||
def seed(self, req, full_url, headers):
|
||||
self.setup_class(req, full_url, headers)
|
||||
from . import mock_random
|
||||
|
||||
a = self._get_param("a")
|
||||
mock_random.seed(int(a))
|
||||
return 200, {}, ""
|
||||
|
@ -11,6 +11,7 @@ url_paths = {
|
||||
"{0}/moto-api/data.json": response_instance.model_data,
|
||||
"{0}/moto-api/reset": response_instance.reset_response,
|
||||
"{0}/moto-api/reset-auth": response_instance.reset_auth_response,
|
||||
"{0}/moto-api/seed": response_instance.seed,
|
||||
"{0}/moto-api/state-manager/get-transition": response_instance.get_transition,
|
||||
"{0}/moto-api/state-manager/set-transition": response_instance.set_transition,
|
||||
"{0}/moto-api/state-manager/unset-transition": response_instance.unset_transition,
|
||||
|
@ -2,7 +2,8 @@ import base64
|
||||
import xmltodict
|
||||
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import BackendDict, get_random_hex, unix_time
|
||||
from moto.core.utils import BackendDict, unix_time
|
||||
from moto.moto_api._internal import mock_random
|
||||
from moto.utilities.tagging_service import TaggingService
|
||||
|
||||
from .configuration import DEFAULT_CONFIGURATION_DATA
|
||||
@ -58,7 +59,7 @@ class ConfigurationRevision(BaseModel):
|
||||
|
||||
class Configuration(BaseModel):
|
||||
def __init__(self, account_id, region, name, engine_type, engine_version):
|
||||
self.id = f"c-{get_random_hex(6)}"
|
||||
self.id = f"c-{mock_random.get_random_hex(6)}"
|
||||
self.arn = f"arn:aws:mq:{region}:{account_id}:configuration:{self.id}"
|
||||
self.created = unix_time()
|
||||
|
||||
@ -160,7 +161,7 @@ class Broker(BaseModel):
|
||||
users,
|
||||
):
|
||||
self.name = name
|
||||
self.id = get_random_hex(6)
|
||||
self.id = mock_random.get_random_hex(6)
|
||||
self.arn = f"arn:aws:mq:{region}:{account_id}:broker:{self.id}"
|
||||
self.state = "RUNNING"
|
||||
self.created = unix_time()
|
||||
@ -217,7 +218,7 @@ class Broker(BaseModel):
|
||||
self.configurations = None
|
||||
else:
|
||||
current_config = configuration or {
|
||||
"id": f"c-{get_random_hex(6)}",
|
||||
"id": f"c-{mock_random.get_random_hex(6)}",
|
||||
"revision": 1,
|
||||
}
|
||||
self.configurations = {
|
||||
|
@ -1,9 +1,8 @@
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.ec2 import ec2_backends
|
||||
from moto.core.utils import BackendDict
|
||||
import uuid
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
import datetime
|
||||
from random import choice
|
||||
|
||||
from .exceptions import ResourceNotFoundException, ValidationException
|
||||
|
||||
@ -83,7 +82,7 @@ class OpsworkInstance(BaseModel):
|
||||
self.infrastructure_class = "ec2 (fixed)"
|
||||
self.platform = "linux (fixed)"
|
||||
|
||||
self.id = "{0}".format(uuid.uuid4())
|
||||
self.id = "{0}".format(random.uuid4())
|
||||
self.created_at = datetime.datetime.utcnow()
|
||||
|
||||
def start(self):
|
||||
@ -273,7 +272,7 @@ class Layer(BaseModel):
|
||||
self.install_updates_on_boot = install_updates_on_boot
|
||||
self.use_ebs_optimized_instances = use_ebs_optimized_instances
|
||||
|
||||
self.id = "{0}".format(uuid.uuid4())
|
||||
self.id = "{0}".format(random.uuid4())
|
||||
self.created_at = datetime.datetime.utcnow()
|
||||
|
||||
def __eq__(self, other):
|
||||
@ -369,7 +368,7 @@ class Stack(BaseModel):
|
||||
self.default_root_device_type = default_root_device_type
|
||||
self.agent_version = agent_version
|
||||
|
||||
self.id = "{0}".format(uuid.uuid4())
|
||||
self.id = "{0}".format(random.uuid4())
|
||||
self.layers = []
|
||||
self.apps = []
|
||||
self.account_number = account_id
|
||||
@ -381,7 +380,8 @@ class Stack(BaseModel):
|
||||
def generate_hostname(self):
|
||||
# this doesn't match amazon's implementation
|
||||
return "{theme}-{rand}-(moto)".format(
|
||||
theme=self.hostname_theme, rand=[choice("abcdefghijhk") for _ in range(4)]
|
||||
theme=self.hostname_theme,
|
||||
rand=[random.choice("abcdefghijhk") for _ in range(4)],
|
||||
)
|
||||
|
||||
@property
|
||||
@ -469,7 +469,7 @@ class App(BaseModel):
|
||||
if environment is None:
|
||||
self.environment = {}
|
||||
|
||||
self.id = "{0}".format(uuid.uuid4())
|
||||
self.id = "{0}".format(random.uuid4())
|
||||
self.created_at = datetime.datetime.utcnow()
|
||||
|
||||
def __eq__(self, other):
|
||||
|
@ -1,6 +1,6 @@
|
||||
import random
|
||||
import re
|
||||
import string
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
|
||||
|
||||
MASTER_ACCOUNT_EMAIL = "master@example.com"
|
||||
|
@ -1,15 +1,15 @@
|
||||
from datetime import datetime
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import BackendDict, unix_time
|
||||
from moto.moto_api._internal import mock_random
|
||||
from moto.utilities.tagging_service import TaggingService
|
||||
from uuid import uuid4
|
||||
|
||||
from .exceptions import ApplicationNotFound, EventStreamNotFound
|
||||
|
||||
|
||||
class App(BaseModel):
|
||||
def __init__(self, account_id, name):
|
||||
self.application_id = str(uuid4()).replace("-", "")
|
||||
self.application_id = str(mock_random.uuid4()).replace("-", "")
|
||||
self.arn = (
|
||||
f"arn:aws:mobiletargeting:us-east-1:{account_id}:apps/{self.application_id}"
|
||||
)
|
||||
|
@ -1,11 +1,10 @@
|
||||
import re
|
||||
import string
|
||||
from datetime import datetime
|
||||
import random
|
||||
from uuid import uuid4
|
||||
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import unix_time, BackendDict
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
from moto.organizations import organizations_backends
|
||||
from moto.ram.exceptions import (
|
||||
MalformedArnException,
|
||||
@ -43,7 +42,9 @@ class ResourceShare(BaseModel):
|
||||
self.region = region
|
||||
|
||||
self.allow_external_principals = kwargs.get("allowExternalPrincipals", True)
|
||||
self.arn = f"arn:aws:ram:{self.region}:{account_id}:resource-share/{uuid4()}"
|
||||
self.arn = (
|
||||
f"arn:aws:ram:{self.region}:{account_id}:resource-share/{random.uuid4()}"
|
||||
)
|
||||
self.creation_time = datetime.utcnow()
|
||||
self.feature_set = "STANDARD"
|
||||
self.last_updated_time = datetime.utcnow()
|
||||
|
@ -1,7 +1,6 @@
|
||||
import copy
|
||||
import datetime
|
||||
import os
|
||||
import random
|
||||
import string
|
||||
|
||||
from collections import defaultdict
|
||||
@ -9,9 +8,9 @@ from jinja2 import Template
|
||||
from re import compile as re_compile
|
||||
from collections import OrderedDict
|
||||
from moto.core import BaseBackend, BaseModel, CloudFormationModel
|
||||
|
||||
from moto.core.utils import iso_8601_datetime_with_milliseconds, BackendDict
|
||||
from moto.ec2.models import ec2_backends
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
from .exceptions import (
|
||||
RDSClientError,
|
||||
DBClusterNotFoundError,
|
||||
|
@ -4,8 +4,8 @@ import datetime
|
||||
from collections import OrderedDict
|
||||
from moto.core import BaseBackend, BaseModel, CloudFormationModel
|
||||
from moto.core.utils import iso_8601_datetime_with_milliseconds, BackendDict
|
||||
from moto.utilities.utils import random_string
|
||||
from moto.ec2 import ec2_backends
|
||||
from moto.moto_api._internal import mock_random
|
||||
from .exceptions import (
|
||||
ClusterAlreadyExistsFaultError,
|
||||
ClusterNotFoundError,
|
||||
@ -1050,7 +1050,7 @@ class RedshiftBackend(BaseBackend):
|
||||
db_user = user_prefix + db_user
|
||||
return {
|
||||
"DbUser": db_user,
|
||||
"DbPassword": random_string(32),
|
||||
"DbPassword": mock_random.get_random_string(32),
|
||||
"Expiration": expiration,
|
||||
}
|
||||
else:
|
||||
|
@ -1,10 +1,9 @@
|
||||
import re
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
import random
|
||||
|
||||
from moto.core import BaseBackend
|
||||
from moto.core.utils import BackendDict, iso_8601_datetime_without_milliseconds
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
from moto.redshiftdata.exceptions import ValidationException, ResourceNotFoundException
|
||||
|
||||
|
||||
@ -20,7 +19,7 @@ class Statement:
|
||||
):
|
||||
now = iso_8601_datetime_without_milliseconds(datetime.now())
|
||||
|
||||
self.id = str(uuid.uuid4())
|
||||
self.id = str(random.uuid4())
|
||||
self.cluster_identifier = cluster_identifier
|
||||
self.created_at = now
|
||||
self.database = database
|
||||
|
@ -1,10 +1,10 @@
|
||||
"""RekognitionBackend class with methods for supported APIs."""
|
||||
|
||||
import random
|
||||
import string
|
||||
|
||||
from moto.core import BaseBackend
|
||||
from moto.core.utils import BackendDict
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
|
||||
|
||||
class RekognitionBackend(BaseBackend):
|
||||
|
@ -1,8 +1,7 @@
|
||||
import uuid
|
||||
|
||||
from moto.core import BaseBackend
|
||||
from moto.core.exceptions import RESTError
|
||||
from moto.core.utils import BackendDict
|
||||
from moto.moto_api._internal import mock_random
|
||||
|
||||
from moto.s3 import s3_backends
|
||||
from moto.ec2 import ec2_backends
|
||||
@ -612,7 +611,7 @@ class ResourceGroupsTaggingAPIBackend(BaseBackend):
|
||||
return None, result
|
||||
|
||||
# Didn't hit StopIteration so there's stuff left in generator
|
||||
new_token = str(uuid.uuid4())
|
||||
new_token = str(mock_random.uuid4())
|
||||
self._pages[new_token] = {"gen": generator, "misc": next_item}
|
||||
|
||||
# Token used up, might as well bin now, if you call it again your an idiot
|
||||
@ -658,7 +657,7 @@ class ResourceGroupsTaggingAPIBackend(BaseBackend):
|
||||
return None, result
|
||||
|
||||
# Didn't hit StopIteration so there's stuff left in generator
|
||||
new_token = str(uuid.uuid4())
|
||||
new_token = str(mock_random.uuid4())
|
||||
self._pages[new_token] = {"gen": generator, "misc": next_item}
|
||||
|
||||
# Token used up, might as well bin now, if you call it again your an idiot
|
||||
@ -704,7 +703,7 @@ class ResourceGroupsTaggingAPIBackend(BaseBackend):
|
||||
return None, result
|
||||
|
||||
# Didn't hit StopIteration so there's stuff left in generator
|
||||
new_token = str(uuid.uuid4())
|
||||
new_token = str(mock_random.uuid4())
|
||||
self._pages[new_token] = {"gen": generator, "misc": next_item}
|
||||
|
||||
# Token used up, might as well bin now, if you call it again your an idiot
|
||||
|
@ -1,11 +1,8 @@
|
||||
"""Route53Backend class with methods for supported APIs."""
|
||||
import itertools
|
||||
from collections import defaultdict
|
||||
import re
|
||||
|
||||
import string
|
||||
import random
|
||||
import uuid
|
||||
from collections import defaultdict
|
||||
from jinja2 import Template
|
||||
|
||||
from moto.route53.exceptions import (
|
||||
@ -23,6 +20,7 @@ from moto.route53.exceptions import (
|
||||
)
|
||||
from moto.core import BaseBackend, BaseModel, CloudFormationModel
|
||||
from moto.core.utils import BackendDict
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
from moto.utilities.paginator import paginate
|
||||
from .utils import PAGINATION_MODEL
|
||||
|
||||
@ -645,7 +643,7 @@ class Route53Backend(BaseBackend):
|
||||
return zone
|
||||
|
||||
def create_health_check(self, caller_reference, health_check_args):
|
||||
health_check_id = str(uuid.uuid4())
|
||||
health_check_id = str(random.uuid4())
|
||||
health_check = HealthCheck(health_check_id, caller_reference, health_check_args)
|
||||
health_check.set_children(health_check_args.get("children"))
|
||||
health_check.set_regions(health_check_args.get("regions"))
|
||||
@ -749,7 +747,7 @@ class Route53Backend(BaseBackend):
|
||||
raise QueryLoggingConfigAlreadyExists()
|
||||
|
||||
# Create an instance of the query logging config.
|
||||
query_logging_config_id = str(uuid.uuid4())
|
||||
query_logging_config_id = str(random.uuid4())
|
||||
query_logging_config = QueryLoggingConfig(
|
||||
query_logging_config_id, hosted_zone_id, log_group_arn
|
||||
)
|
||||
|
@ -5,10 +5,11 @@ from ipaddress import ip_address, ip_network, IPv4Address
|
||||
import re
|
||||
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import get_random_hex, BackendDict
|
||||
from moto.core.utils import BackendDict
|
||||
from moto.ec2 import ec2_backends
|
||||
from moto.ec2.exceptions import InvalidSubnetIdError
|
||||
from moto.ec2.exceptions import InvalidSecurityGroupNotFoundError
|
||||
from moto.moto_api._internal import mock_random
|
||||
from moto.route53resolver.exceptions import (
|
||||
InvalidParameterException,
|
||||
InvalidRequestException,
|
||||
@ -114,7 +115,7 @@ class ResolverRule(BaseModel): # pylint: disable=too-many-instance-attributes
|
||||
# of X-Amzn-Trace-Id. We don't have that info, so a random number
|
||||
# of similar format and length will be used.
|
||||
self.status_message = (
|
||||
f"[Trace id: 1-{get_random_hex(8)}-{get_random_hex(24)}] "
|
||||
f"[Trace id: 1-{mock_random.get_random_hex(8)}-{mock_random.get_random_hex(24)}] "
|
||||
f"Successfully created Resolver Rule"
|
||||
)
|
||||
self.share_status = "SHARED_WITH_ME"
|
||||
@ -199,7 +200,7 @@ class ResolverEndpoint(BaseModel): # pylint: disable=too-many-instance-attribut
|
||||
# of X-Amzn-Trace-Id. We don't have that info, so a random number
|
||||
# of similar format and length will be used.
|
||||
self.status_message = (
|
||||
f"[Trace id: 1-{get_random_hex(8)}-{get_random_hex(24)}] "
|
||||
f"[Trace id: 1-{mock_random.get_random_hex(8)}-{mock_random.get_random_hex(24)}] "
|
||||
f"Successfully created Resolver Endpoint"
|
||||
)
|
||||
self.creation_time = datetime.now(timezone.utc).isoformat()
|
||||
@ -228,7 +229,9 @@ class ResolverEndpoint(BaseModel): # pylint: disable=too-many-instance-attribut
|
||||
"""
|
||||
subnets = defaultdict(dict)
|
||||
for entry in self.ip_addresses:
|
||||
subnets[entry["SubnetId"]][entry["Ip"]] = f"rni-{get_random_hex(17)}"
|
||||
subnets[entry["SubnetId"]][
|
||||
entry["Ip"]
|
||||
] = f"rni-{mock_random.get_random_hex(17)}"
|
||||
return subnets
|
||||
|
||||
def create_eni(self):
|
||||
@ -298,7 +301,7 @@ class ResolverEndpoint(BaseModel): # pylint: disable=too-many-instance-attribut
|
||||
self.ip_addresses.append(ip_address)
|
||||
self.ip_address_count = len(self.ip_addresses)
|
||||
|
||||
eni_id = f"rni-{get_random_hex(17)}"
|
||||
eni_id = f"rni-{mock_random.get_random_hex(17)}"
|
||||
self.subnets[ip_address["SubnetId"]][ip_address["Ip"]] = eni_id
|
||||
|
||||
eni_info = self.ec2_backend.create_network_interface(
|
||||
@ -390,7 +393,7 @@ class Route53ResolverBackend(BaseBackend):
|
||||
f"VPC. Conflict with resolver rule '{resolver_rule_id}'"
|
||||
)
|
||||
|
||||
rule_association_id = f"rslvr-rrassoc-{get_random_hex(17)}"
|
||||
rule_association_id = f"rslvr-rrassoc-{mock_random.get_random_hex(17)}"
|
||||
rule_association = ResolverRuleAssociation(
|
||||
self.region_name, rule_association_id, resolver_rule_id, vpc_id, name
|
||||
)
|
||||
@ -509,9 +512,7 @@ class Route53ResolverBackend(BaseBackend):
|
||||
f"'{creator_request_id}' already exists"
|
||||
)
|
||||
|
||||
endpoint_id = (
|
||||
f"rslvr-{'in' if direction == 'INBOUND' else 'out'}-{get_random_hex(17)}"
|
||||
)
|
||||
endpoint_id = f"rslvr-{'in' if direction == 'INBOUND' else 'out'}-{mock_random.get_random_hex(17)}"
|
||||
resolver_endpoint = ResolverEndpoint(
|
||||
self.account_id,
|
||||
region,
|
||||
@ -605,7 +606,7 @@ class Route53ResolverBackend(BaseBackend):
|
||||
f"'{creator_request_id}' already exists"
|
||||
)
|
||||
|
||||
rule_id = f"rslvr-rr-{get_random_hex(17)}"
|
||||
rule_id = f"rslvr-rr-{mock_random.get_random_hex(17)}"
|
||||
resolver_rule = ResolverRule(
|
||||
self.account_id,
|
||||
region,
|
||||
|
@ -5,20 +5,17 @@ import datetime
|
||||
import copy
|
||||
import itertools
|
||||
import codecs
|
||||
import random
|
||||
import string
|
||||
import tempfile
|
||||
import threading
|
||||
import pytz
|
||||
import sys
|
||||
import uuid
|
||||
import urllib.parse
|
||||
|
||||
from bisect import insort
|
||||
from importlib import reload
|
||||
from moto.core import BaseBackend, BaseModel, CloudFormationModel
|
||||
from moto.core import CloudWatchMetricProvider
|
||||
|
||||
from moto.core.utils import (
|
||||
iso_8601_datetime_without_milliseconds_s3,
|
||||
rfc_1123_datetime,
|
||||
@ -28,6 +25,7 @@ from moto.core.utils import (
|
||||
)
|
||||
from moto.cloudwatch.models import MetricDatum
|
||||
from moto.moto_api import state_manager
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
from moto.moto_api._internal.managed_state_model import ManagedState
|
||||
from moto.utilities.tagging_service import TaggingService
|
||||
from moto.utilities.utils import LowercaseDict, md5_hash
|
||||
@ -80,7 +78,7 @@ class FakeDeleteMarker(BaseModel):
|
||||
self.key = key
|
||||
self.name = key.name
|
||||
self.last_modified = datetime.datetime.utcnow()
|
||||
self._version_id = str(uuid.uuid4())
|
||||
self._version_id = str(random.uuid4())
|
||||
|
||||
@property
|
||||
def last_modified_ISO8601(self):
|
||||
@ -1728,7 +1726,7 @@ class S3Backend(BaseBackend, CloudWatchMetricProvider):
|
||||
storage=storage,
|
||||
etag=etag,
|
||||
is_versioned=bucket.is_versioned,
|
||||
version_id=str(uuid.uuid4()) if bucket.is_versioned else "null",
|
||||
version_id=str(random.uuid4()) if bucket.is_versioned else "null",
|
||||
multipart=multipart,
|
||||
encryption=encryption,
|
||||
kms_key_id=kms_key_id,
|
||||
|
@ -7,7 +7,6 @@ import urllib.parse
|
||||
|
||||
from moto import settings
|
||||
from moto.core.utils import (
|
||||
amzn_request_id,
|
||||
extract_region_from_aws_authorization,
|
||||
str_to_rfc_1123_datetime,
|
||||
)
|
||||
@ -23,6 +22,7 @@ from moto.s3bucket_path.utils import (
|
||||
parse_key_name as bucketpath_parse_key_name,
|
||||
is_delete_keys as bucketpath_is_delete_keys,
|
||||
)
|
||||
from moto.utilities.aws_headers import amzn_request_id
|
||||
|
||||
from .exceptions import (
|
||||
BucketAlreadyExists,
|
||||
|
@ -1,7 +1,8 @@
|
||||
from collections import defaultdict
|
||||
from datetime import datetime
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import get_random_hex, BackendDict
|
||||
from moto.core.utils import BackendDict
|
||||
from moto.moto_api._internal import mock_random
|
||||
from moto.s3.exceptions import (
|
||||
WrongPublicAccessBlockAccountIdError,
|
||||
NoSuchPublicAccessBlockConfiguration,
|
||||
@ -22,7 +23,7 @@ class AccessPoint(BaseModel):
|
||||
public_access_block_configuration,
|
||||
):
|
||||
self.name = name
|
||||
self.alias = f"{name}-{get_random_hex(34)}-s3alias"
|
||||
self.alias = f"{name}-{mock_random.get_random_hex(34)}-s3alias"
|
||||
self.bucket = bucket
|
||||
self.created = datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%f")
|
||||
self.arn = f"arn:aws:s3:us-east-1:{account_id}:accesspoint/{name}"
|
||||
|
@ -2,9 +2,9 @@ import json
|
||||
import xmltodict
|
||||
|
||||
from moto.core.responses import BaseResponse
|
||||
from moto.core.utils import amzn_request_id
|
||||
from moto.s3.exceptions import S3ClientError
|
||||
from moto.s3.responses import S3_PUBLIC_ACCESS_BLOCK_CONFIGURATION
|
||||
from moto.utilities.aws_headers import amzn_request_id
|
||||
from .models import s3control_backends
|
||||
|
||||
|
||||
|
@ -3,7 +3,7 @@ import json
|
||||
from moto.sagemaker.exceptions import AWSValidationException
|
||||
|
||||
from moto.core.responses import BaseResponse
|
||||
from moto.core.utils import amzn_request_id
|
||||
from moto.utilities.aws_headers import amzn_request_id
|
||||
from .models import sagemaker_backends
|
||||
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
import time
|
||||
import json
|
||||
import uuid
|
||||
import datetime
|
||||
|
||||
from typing import List, Tuple
|
||||
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import BackendDict
|
||||
from moto.moto_api._internal import mock_random
|
||||
from .exceptions import (
|
||||
SecretNotFoundException,
|
||||
SecretHasNoValueException,
|
||||
@ -221,7 +221,7 @@ class SecretsManagerBackend(BaseBackend):
|
||||
if version_id:
|
||||
self._client_request_token_validator(version_id)
|
||||
else:
|
||||
version_id = str(uuid.uuid4())
|
||||
version_id = str(mock_random.uuid4())
|
||||
return version_id
|
||||
|
||||
def get_secret_value(self, secret_id, version_id, version_stage):
|
||||
@ -512,7 +512,7 @@ class SecretsManagerBackend(BaseBackend):
|
||||
self._client_request_token_validator(client_request_token)
|
||||
new_version_id = client_request_token
|
||||
else:
|
||||
new_version_id = str(uuid.uuid4())
|
||||
new_version_id = str(mock_random.uuid4())
|
||||
|
||||
# We add the new secret version as "pending". The previous version remains
|
||||
# as "current" for now. Once we've passed the new secret through the lambda
|
||||
|
@ -1,6 +1,6 @@
|
||||
import random
|
||||
import string
|
||||
import re
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
|
||||
|
||||
def random_password(
|
||||
|
@ -1,8 +1,8 @@
|
||||
import random
|
||||
import string
|
||||
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import BackendDict, unix_time
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
from moto.utilities.tagging_service import TaggingService
|
||||
|
||||
from .exceptions import (
|
||||
|
@ -1,6 +1,6 @@
|
||||
import random
|
||||
import string
|
||||
from email.utils import parseaddr
|
||||
from moto.moto_api._internal import mock_random as random
|
||||
|
||||
|
||||
def random_hex(length):
|
||||
|
@ -1,5 +1,6 @@
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import BackendDict, get_random_hex
|
||||
from moto.core.utils import BackendDict
|
||||
from moto.moto_api._internal import mock_random
|
||||
|
||||
|
||||
class SigningProfile(BaseModel):
|
||||
@ -16,7 +17,7 @@ class SigningProfile(BaseModel):
|
||||
|
||||
self.status = "Active"
|
||||
self.arn = f"arn:aws:signer:{region}:{account_id}:/signing-profiles/{name}"
|
||||
self.profile_version = get_random_hex(10)
|
||||
self.profile_version = mock_random.get_random_hex(10)
|
||||
self.profile_version_arn = f"{self.arn}/{self.profile_version}"
|
||||
|
||||
def cancel(self):
|
||||
|
@ -1,5 +1,4 @@
|
||||
import datetime
|
||||
import uuid
|
||||
import json
|
||||
|
||||
import requests
|
||||
@ -12,6 +11,7 @@ from moto.core.utils import (
|
||||
camelcase_to_underscores,
|
||||
BackendDict,
|
||||
)
|
||||
from moto.moto_api._internal import mock_random
|
||||
from moto.sqs import sqs_backends
|
||||
from moto.sqs.exceptions import MissingParameter
|
||||
|
||||
@ -60,7 +60,7 @@ class Topic(CloudFormationModel):
|
||||
self.content_based_deduplication = "false"
|
||||
|
||||
def publish(self, message, subject=None, message_attributes=None, group_id=None):
|
||||
message_id = str(uuid.uuid4())
|
||||
message_id = str(mock_random.uuid4())
|
||||
subscriptions, _ = self.sns_backend.list_subscriptions(self.arn)
|
||||
for subscription in subscriptions:
|
||||
subscription.publish(
|
||||
@ -424,7 +424,7 @@ class PlatformEndpoint(BaseModel):
|
||||
self.custom_user_data = custom_user_data
|
||||
self.token = token
|
||||
self.attributes = attributes
|
||||
self.id = uuid.uuid4()
|
||||
self.id = mock_random.uuid4()
|
||||
self.arn = f"arn:aws:sns:{region}:{account_id}:endpoint/{self.application.platform}/{self.application.name}/{self.id}"
|
||||
self.messages = OrderedDict()
|
||||
self.__fixup_attributes()
|
||||
@ -449,7 +449,7 @@ class PlatformEndpoint(BaseModel):
|
||||
raise SnsEndpointDisabled("Endpoint %s disabled" % self.id)
|
||||
|
||||
# This is where we would actually send a message
|
||||
message_id = str(uuid.uuid4())
|
||||
message_id = str(mock_random.uuid4())
|
||||
self.messages[message_id] = message
|
||||
return message_id
|
||||
|
||||
@ -651,7 +651,7 @@ class SNSBackend(BaseBackend):
|
||||
if len(message) > MAXIMUM_SMS_MESSAGE_BYTES:
|
||||
raise ValueError("SMS message must be less than 1600 bytes")
|
||||
|
||||
message_id = str(uuid.uuid4())
|
||||
message_id = str(mock_random.uuid4())
|
||||
self.sms_messages[message_id] = (phone_number, message)
|
||||
return message_id
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user