diff --git a/.github/workflows/asf-updates.yml b/.github/workflows/asf-updates.yml index 6596d7a90eb89..a7bf1d52ecbf1 100644 --- a/.github/workflows/asf-updates.yml +++ b/.github/workflows/asf-updates.yml @@ -43,6 +43,7 @@ jobs: run: | source .venv/bin/activate python3 -m localstack.aws.scaffold upgrade + make format-modified - name: Check for changes id: check-for-changes diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2cb395b4c8b42..6aba3b4fb7f53 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,32 +2,19 @@ # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/psf/black - rev: 22.3.0 + rev: 23.10.0 hooks: - id: black - - repo: https://github.com/pycqa/isort - rev: 5.12.0 + - repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.1.0 hooks: - - id: isort - name: isort (python) - - id: isort - name: isort (cython) - types: [cython] - - id: isort - name: isort (pyi) - types: [pyi] - - - repo: https://github.com/pycqa/flake8 - rev: 6.0.0 - hooks: - - id: flake8 - entry: pflake8 - additional_dependencies: - - pyproject-flake8 + - id: ruff + args: [--fix, --exit-non-zero-on-fix] - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.0.1 + rev: v4.5.0 hooks: - id: end-of-file-fixer - id: trailing-whitespace diff --git a/Makefile b/Makefile index cf7bc522cc0b7..51cd75e9ddc84 100644 --- a/Makefile +++ b/Makefile @@ -203,19 +203,19 @@ test-docker-mount-code: DOCKER_FLAGS="$(DOCKER_FLAGS) --entrypoint= -v `pwd`/localstack/config.py:/opt/code/localstack/localstack/config.py -v `pwd`/localstack/constants.py:/opt/code/localstack/localstack/constants.py -v `pwd`/localstack/utils:/opt/code/localstack/localstack/utils -v `pwd`/localstack/services:/opt/code/localstack/localstack/services -v `pwd`/localstack/aws:/opt/code/localstack/localstack/aws -v `pwd`/Makefile:/opt/code/localstack/Makefile -v $$PACKAGES_DIR/moto:/opt/code/localstack/.venv/lib/python3.11/site-packages/moto/ -e TEST_PATH=\\'$(TEST_PATH)\\' -e LAMBDA_JAVA_OPTS=$(LAMBDA_JAVA_OPTS) $(ENTRYPOINT)" CMD="make test" make docker-run lint: ## Run code linter to check code style - ($(VENV_RUN); python -m pflake8 --show-source) + ($(VENV_RUN); python -m ruff check --show-source .) lint-modified: ## Run code linter on modified files - ($(VENV_RUN); python -m pflake8 --show-source `git diff --diff-filter=d --name-only HEAD | grep '\.py$$' | xargs` ) + ($(VENV_RUN); python -m ruff check --show-source `git diff --diff-filter=d --name-only HEAD | grep '\.py$$' | xargs` ) check-aws-markers: ## Lightweight check to ensure all AWS tests have proper compatibilty markers set ($(VENV_RUN); python -m pytest --co tests/aws/) -format: ## Run black and isort code formatter - ($(VENV_RUN); python -m isort localstack tests; python -m black localstack tests ) +format: ## Run black and ruff code formatter + ($(VENV_RUN); python -m ruff check --show-source --fix .; python -m black .) -format-modified: ## Run black and isort code formatter on modified files - ($(VENV_RUN); python -m isort `git diff --diff-filter=d --name-only HEAD | grep '\.py$$' | xargs`; python -m black `git diff --diff-filter=d --name-only HEAD | grep '\.py$$' | xargs` ) +format-modified: ## Run black and ruff code formatter on modified files + ($(VENV_RUN); python -m ruff check --show-source --fix `git diff --diff-filter=d --name-only HEAD | grep '\.py$$' | xargs`; python -m black `git diff --diff-filter=d --name-only HEAD | grep '\.py$$' | xargs` ) init-precommit: ## install te pre-commit hook into your local git repository ($(VENV_RUN); pre-commit install) diff --git a/localstack/aws/api/acm/__init__.py b/localstack/aws/api/acm/__init__.py index e595fdb2fa8aa..1ac52c97ad7b1 100644 --- a/localstack/aws/api/acm/__init__.py +++ b/localstack/aws/api/acm/__init__.py @@ -515,7 +515,6 @@ class UpdateCertificateOptionsRequest(ServiceRequest): class AcmApi: - service = "acm" version = "2015-12-08" diff --git a/localstack/aws/api/apigateway/__init__.py b/localstack/aws/api/apigateway/__init__.py index bde344046ad4b..9ad3b82e64621 100644 --- a/localstack/aws/api/apigateway/__init__.py +++ b/localstack/aws/api/apigateway/__init__.py @@ -1602,7 +1602,6 @@ class VpcLinks(TypedDict, total=False): class ApigatewayApi: - service = "apigateway" version = "2015-07-09" diff --git a/localstack/aws/api/cloudcontrol/__init__.py b/localstack/aws/api/cloudcontrol/__init__.py index 139a674976275..52ba734a3c847 100644 --- a/localstack/aws/api/cloudcontrol/__init__.py +++ b/localstack/aws/api/cloudcontrol/__init__.py @@ -305,7 +305,6 @@ class UpdateResourceOutput(TypedDict, total=False): class CloudcontrolApi: - service = "cloudcontrol" version = "2021-09-30" diff --git a/localstack/aws/api/cloudformation/__init__.py b/localstack/aws/api/cloudformation/__init__.py index 17de95eac4e34..884fe1b94b149 100644 --- a/localstack/aws/api/cloudformation/__init__.py +++ b/localstack/aws/api/cloudformation/__init__.py @@ -2279,7 +2279,6 @@ class ValidateTemplateOutput(TypedDict, total=False): class CloudformationApi: - service = "cloudformation" version = "2010-05-15" diff --git a/localstack/aws/api/cloudwatch/__init__.py b/localstack/aws/api/cloudwatch/__init__.py index 9ca932af994c8..8ba43fab94caa 100644 --- a/localstack/aws/api/cloudwatch/__init__.py +++ b/localstack/aws/api/cloudwatch/__init__.py @@ -1097,7 +1097,6 @@ class UntagResourceOutput(TypedDict, total=False): class CloudwatchApi: - service = "cloudwatch" version = "2010-08-01" diff --git a/localstack/aws/api/config/__init__.py b/localstack/aws/api/config/__init__.py index 35031fdd67a0c..3615176dd8963 100644 --- a/localstack/aws/api/config/__init__.py +++ b/localstack/aws/api/config/__init__.py @@ -2895,7 +2895,6 @@ class UntagResourceRequest(ServiceRequest): class ConfigApi: - service = "config" version = "2014-11-12" diff --git a/localstack/aws/api/dynamodb/__init__.py b/localstack/aws/api/dynamodb/__init__.py index c3220793561a1..799e447893e5c 100644 --- a/localstack/aws/api/dynamodb/__init__.py +++ b/localstack/aws/api/dynamodb/__init__.py @@ -2140,7 +2140,6 @@ class UpdateTimeToLiveOutput(TypedDict, total=False): class DynamodbApi: - service = "dynamodb" version = "2012-08-10" diff --git a/localstack/aws/api/dynamodbstreams/__init__.py b/localstack/aws/api/dynamodbstreams/__init__.py index 8ff67ebe6feaf..b95f9df353e80 100644 --- a/localstack/aws/api/dynamodbstreams/__init__.py +++ b/localstack/aws/api/dynamodbstreams/__init__.py @@ -221,7 +221,6 @@ class ListStreamsOutput(TypedDict, total=False): class DynamodbstreamsApi: - service = "dynamodbstreams" version = "2012-08-10" diff --git a/localstack/aws/api/ec2/__init__.py b/localstack/aws/api/ec2/__init__.py index 94640eed04936..d2c28364338a8 100644 --- a/localstack/aws/api/ec2/__init__.py +++ b/localstack/aws/api/ec2/__init__.py @@ -17540,7 +17540,6 @@ class WithdrawByoipCidrResult(TypedDict, total=False): class Ec2Api: - service = "ec2" version = "2016-11-15" diff --git a/localstack/aws/api/es/__init__.py b/localstack/aws/api/es/__init__.py index b715624d5ab41..93cb5e8d47659 100644 --- a/localstack/aws/api/es/__init__.py +++ b/localstack/aws/api/es/__init__.py @@ -1536,7 +1536,6 @@ class UpgradeElasticsearchDomainResponse(TypedDict, total=False): class EsApi: - service = "es" version = "2015-01-01" diff --git a/localstack/aws/api/events/__init__.py b/localstack/aws/api/events/__init__.py index abeea5b8fe680..b6ad68a073397 100644 --- a/localstack/aws/api/events/__init__.py +++ b/localstack/aws/api/events/__init__.py @@ -1467,7 +1467,6 @@ class UpdateEndpointResponse(TypedDict, total=False): class EventsApi: - service = "events" version = "2015-10-07" diff --git a/localstack/aws/api/firehose/__init__.py b/localstack/aws/api/firehose/__init__.py index 26779928990ce..46034ed633587 100644 --- a/localstack/aws/api/firehose/__init__.py +++ b/localstack/aws/api/firehose/__init__.py @@ -1111,7 +1111,6 @@ class UpdateDestinationOutput(TypedDict, total=False): class FirehoseApi: - service = "firehose" version = "2015-08-04" diff --git a/localstack/aws/api/iam/__init__.py b/localstack/aws/api/iam/__init__.py index 07b59ff214a2b..89fad1be9b3a8 100644 --- a/localstack/aws/api/iam/__init__.py +++ b/localstack/aws/api/iam/__init__.py @@ -2279,7 +2279,6 @@ class UploadSigningCertificateResponse(TypedDict, total=False): class IamApi: - service = "iam" version = "2010-05-08" diff --git a/localstack/aws/api/kinesis/__init__.py b/localstack/aws/api/kinesis/__init__.py index f6c46f37f2a59..3ed9e28265714 100644 --- a/localstack/aws/api/kinesis/__init__.py +++ b/localstack/aws/api/kinesis/__init__.py @@ -646,7 +646,6 @@ class UpdateStreamModeInput(ServiceRequest): class KinesisApi: - service = "kinesis" version = "2013-12-02" diff --git a/localstack/aws/api/kms/__init__.py b/localstack/aws/api/kms/__init__.py index c1a0ef16817d0..be5abda0a79ba 100644 --- a/localstack/aws/api/kms/__init__.py +++ b/localstack/aws/api/kms/__init__.py @@ -1210,7 +1210,6 @@ class VerifyResponse(TypedDict, total=False): class KmsApi: - service = "kms" version = "2014-11-01" diff --git a/localstack/aws/api/lambda_/__init__.py b/localstack/aws/api/lambda_/__init__.py index 2cf734bdb7db9..f6402754fab2e 100644 --- a/localstack/aws/api/lambda_/__init__.py +++ b/localstack/aws/api/lambda_/__init__.py @@ -1710,7 +1710,6 @@ class UpdateFunctionUrlConfigResponse(TypedDict, total=False): class LambdaApi: - service = "lambda" version = "2015-03-31" diff --git a/localstack/aws/api/logs/__init__.py b/localstack/aws/api/logs/__init__.py index 28da368153390..a472b52dd498f 100644 --- a/localstack/aws/api/logs/__init__.py +++ b/localstack/aws/api/logs/__init__.py @@ -944,7 +944,6 @@ class UntagResourceRequest(ServiceRequest): class LogsApi: - service = "logs" version = "2014-03-28" diff --git a/localstack/aws/api/opensearch/__init__.py b/localstack/aws/api/opensearch/__init__.py index 279a8e4cb5fe3..618132943a731 100644 --- a/localstack/aws/api/opensearch/__init__.py +++ b/localstack/aws/api/opensearch/__init__.py @@ -1901,7 +1901,6 @@ class UpgradeDomainResponse(TypedDict, total=False): class OpensearchApi: - service = "opensearch" version = "2021-01-01" diff --git a/localstack/aws/api/ram/__init__.py b/localstack/aws/api/ram/__init__.py index 4525c8a29088c..c13c0a9f3135f 100644 --- a/localstack/aws/api/ram/__init__.py +++ b/localstack/aws/api/ram/__init__.py @@ -868,7 +868,6 @@ class UpdateResourceShareResponse(TypedDict, total=False): class RamApi: - service = "ram" version = "2018-01-04" diff --git a/localstack/aws/api/redshift/__init__.py b/localstack/aws/api/redshift/__init__.py index d2ce32fe03f72..18d66f23883a7 100644 --- a/localstack/aws/api/redshift/__init__.py +++ b/localstack/aws/api/redshift/__init__.py @@ -3119,7 +3119,6 @@ class UsageLimitList(TypedDict, total=False): class RedshiftApi: - service = "redshift" version = "2012-12-01" diff --git a/localstack/aws/api/resource_groups/__init__.py b/localstack/aws/api/resource_groups/__init__.py index 126128d1495d5..8c7220c0cad3e 100644 --- a/localstack/aws/api/resource_groups/__init__.py +++ b/localstack/aws/api/resource_groups/__init__.py @@ -417,7 +417,6 @@ class UpdateGroupQueryOutput(TypedDict, total=False): class ResourceGroupsApi: - service = "resource-groups" version = "2017-11-27" diff --git a/localstack/aws/api/resourcegroupstaggingapi/__init__.py b/localstack/aws/api/resourcegroupstaggingapi/__init__.py index 2aa3ec94d15ee..53c23416b39e0 100644 --- a/localstack/aws/api/resourcegroupstaggingapi/__init__.py +++ b/localstack/aws/api/resourcegroupstaggingapi/__init__.py @@ -241,7 +241,6 @@ class UntagResourcesOutput(TypedDict, total=False): class ResourcegroupstaggingapiApi: - service = "resourcegroupstaggingapi" version = "2017-01-26" diff --git a/localstack/aws/api/route53/__init__.py b/localstack/aws/api/route53/__init__.py index 4879294f3d24f..5639fb69c7d5d 100644 --- a/localstack/aws/api/route53/__init__.py +++ b/localstack/aws/api/route53/__init__.py @@ -1878,7 +1878,6 @@ class UpdateTrafficPolicyInstanceResponse(TypedDict, total=False): class Route53Api: - service = "route53" version = "2013-04-01" diff --git a/localstack/aws/api/route53resolver/__init__.py b/localstack/aws/api/route53resolver/__init__.py index 00f08fe473dd8..cd34b494e2169 100644 --- a/localstack/aws/api/route53resolver/__init__.py +++ b/localstack/aws/api/route53resolver/__init__.py @@ -1325,7 +1325,6 @@ class UpdateResolverRuleResponse(TypedDict, total=False): class Route53ResolverApi: - service = "route53resolver" version = "2018-04-01" diff --git a/localstack/aws/api/s3/__init__.py b/localstack/aws/api/s3/__init__.py index 6486c661c7720..6f4e71ac4579f 100644 --- a/localstack/aws/api/s3/__init__.py +++ b/localstack/aws/api/s3/__init__.py @@ -3255,7 +3255,6 @@ class PostResponse(TypedDict, total=False): class S3Api: - service = "s3" version = "2006-03-01" diff --git a/localstack/aws/api/s3control/__init__.py b/localstack/aws/api/s3control/__init__.py index fd25ec0489181..2bba88a884d14 100644 --- a/localstack/aws/api/s3control/__init__.py +++ b/localstack/aws/api/s3control/__init__.py @@ -1783,7 +1783,6 @@ class UpdateJobStatusResult(TypedDict, total=False): class S3ControlApi: - service = "s3control" version = "2018-08-20" diff --git a/localstack/aws/api/scheduler/__init__.py b/localstack/aws/api/scheduler/__init__.py index ebf5d58003244..d8afa69687315 100644 --- a/localstack/aws/api/scheduler/__init__.py +++ b/localstack/aws/api/scheduler/__init__.py @@ -451,7 +451,6 @@ class UpdateScheduleOutput(TypedDict, total=False): class SchedulerApi: - service = "scheduler" version = "2021-06-30" diff --git a/localstack/aws/api/secretsmanager/__init__.py b/localstack/aws/api/secretsmanager/__init__.py index 438eb3d3cfd82..d60566322e685 100644 --- a/localstack/aws/api/secretsmanager/__init__.py +++ b/localstack/aws/api/secretsmanager/__init__.py @@ -521,7 +521,6 @@ class ValidateResourcePolicyResponse(TypedDict, total=False): class SecretsmanagerApi: - service = "secretsmanager" version = "2017-10-17" diff --git a/localstack/aws/api/ses/__init__.py b/localstack/aws/api/ses/__init__.py index 31a4a385c6b69..5551cf230973f 100644 --- a/localstack/aws/api/ses/__init__.py +++ b/localstack/aws/api/ses/__init__.py @@ -1372,7 +1372,6 @@ class VerifyEmailIdentityResponse(TypedDict, total=False): class SesApi: - service = "ses" version = "2010-12-01" diff --git a/localstack/aws/api/sns/__init__.py b/localstack/aws/api/sns/__init__.py index 76374c95f9e5d..b8f573e7cb0de 100644 --- a/localstack/aws/api/sns/__init__.py +++ b/localstack/aws/api/sns/__init__.py @@ -734,7 +734,6 @@ class VerifySMSSandboxPhoneNumberResult(TypedDict, total=False): class SnsApi: - service = "sns" version = "2010-03-31" diff --git a/localstack/aws/api/sqs/__init__.py b/localstack/aws/api/sqs/__init__.py index 17856ca9054af..04055063246bb 100644 --- a/localstack/aws/api/sqs/__init__.py +++ b/localstack/aws/api/sqs/__init__.py @@ -494,7 +494,6 @@ class UntagQueueRequest(ServiceRequest): class SqsApi: - service = "sqs" version = "2012-11-05" diff --git a/localstack/aws/api/ssm/__init__.py b/localstack/aws/api/ssm/__init__.py index 483b710c69ff9..1807be8fa9a98 100644 --- a/localstack/aws/api/ssm/__init__.py +++ b/localstack/aws/api/ssm/__init__.py @@ -5477,7 +5477,6 @@ class UpdateServiceSettingResult(TypedDict, total=False): class SsmApi: - service = "ssm" version = "2014-11-06" diff --git a/localstack/aws/api/stepfunctions/__init__.py b/localstack/aws/api/stepfunctions/__init__.py index 87520a3477392..a4efbe38cc428 100644 --- a/localstack/aws/api/stepfunctions/__init__.py +++ b/localstack/aws/api/stepfunctions/__init__.py @@ -1118,7 +1118,6 @@ class UpdateStateMachineOutput(TypedDict, total=False): class StepfunctionsApi: - service = "stepfunctions" version = "2016-11-23" diff --git a/localstack/aws/api/sts/__init__.py b/localstack/aws/api/sts/__init__.py index b5db0238e1a47..931a4355bbb7c 100644 --- a/localstack/aws/api/sts/__init__.py +++ b/localstack/aws/api/sts/__init__.py @@ -252,7 +252,6 @@ class GetSessionTokenResponse(TypedDict, total=False): class StsApi: - service = "sts" version = "2011-06-15" diff --git a/localstack/aws/api/support/__init__.py b/localstack/aws/api/support/__init__.py index 06d91b05e7256..133efb9191517 100644 --- a/localstack/aws/api/support/__init__.py +++ b/localstack/aws/api/support/__init__.py @@ -468,7 +468,6 @@ class ResolveCaseResponse(TypedDict, total=False): class SupportApi: - service = "support" version = "2013-04-15" diff --git a/localstack/aws/api/swf/__init__.py b/localstack/aws/api/swf/__init__.py index 0e109d83c0437..bef30794b69f8 100644 --- a/localstack/aws/api/swf/__init__.py +++ b/localstack/aws/api/swf/__init__.py @@ -1452,7 +1452,6 @@ class WorkflowTypeInfos(TypedDict, total=False): class SwfApi: - service = "swf" version = "2012-01-25" diff --git a/localstack/aws/api/transcribe/__init__.py b/localstack/aws/api/transcribe/__init__.py index 0d47819c6abda..67019b7c30a08 100644 --- a/localstack/aws/api/transcribe/__init__.py +++ b/localstack/aws/api/transcribe/__init__.py @@ -1030,7 +1030,6 @@ class UpdateVocabularyResponse(TypedDict, total=False): class TranscribeApi: - service = "transcribe" version = "2017-10-26" diff --git a/localstack/aws/protocol/validate.py b/localstack/aws/protocol/validate.py index f58bf55feb094..78ddc65b756af 100644 --- a/localstack/aws/protocol/validate.py +++ b/localstack/aws/protocol/validate.py @@ -25,7 +25,6 @@ class Error(NamedTuple): class ParameterValidationError(Exception): - error: Error def __init__(self, error: Error) -> None: diff --git a/localstack/aws/scaffold.py b/localstack/aws/scaffold.py index 2974a57bf73dc..e704fab804a96 100644 --- a/localstack/aws/scaffold.py +++ b/localstack/aws/scaffold.py @@ -493,28 +493,7 @@ def generate_code(service_name: str, doc: bool = False) -> str: output = io.StringIO() generate_service_types(output, model, doc=doc) generate_service_api(output, model, doc=doc) - - code = output.getvalue() - - try: - import autoflake - import isort - from black import FileMode, format_str - - # try to remove unused imports - code = autoflake.fix_code(code, remove_all_unused_imports=True) - - # try to format with black - code = format_str(code, mode=FileMode(line_length=100)) - - # try to sort imports - code = isort.code(code, config=isort.Config(profile="black", line_length=100)) - except ImportError: - click.echo( - "Skip code cleaning / formatting due to missing tools (autoflake, isort, black)..." - ) - - return code + return output.getvalue() def create_code_directory(service_name: str, code: str, base_path: str): diff --git a/localstack/aws/serving/wsgi.py b/localstack/aws/serving/wsgi.py index 43799be4c13ab..ca1a488a18467 100644 --- a/localstack/aws/serving/wsgi.py +++ b/localstack/aws/serving/wsgi.py @@ -2,7 +2,7 @@ from typing import TYPE_CHECKING, Iterable if TYPE_CHECKING: - from _typeshed.wsgi import WSGIEnvironment, StartResponse + from _typeshed.wsgi import StartResponse, WSGIEnvironment from werkzeug.datastructures import Headers, MultiDict from werkzeug.wrappers import Request diff --git a/localstack/extensions/api/aws.py b/localstack/extensions/api/aws.py index 6690a8b0b8724..39f4036fe2a30 100644 --- a/localstack/extensions/api/aws.py +++ b/localstack/extensions/api/aws.py @@ -5,10 +5,14 @@ ServiceRequest, ServiceResponse, ) -from localstack.aws.chain import CompositeHandler, CompositeResponseHandler, ExceptionHandler +from localstack.aws.chain import ( + CompositeHandler, + CompositeResponseHandler, + ExceptionHandler, + HandlerChain, +) from localstack.aws.chain import Handler as RequestHandler from localstack.aws.chain import Handler as ResponseHandler -from localstack.aws.chain import HandlerChain __all__ = [ "RequestContext", diff --git a/localstack/http/proxy.py b/localstack/http/proxy.py index 3f95a63602206..c5d125cbe0102 100644 --- a/localstack/http/proxy.py +++ b/localstack/http/proxy.py @@ -25,7 +25,6 @@ def forward( class Proxy(HttpClient): - preserve_host: bool def __init__( diff --git a/localstack/services/acm/provider.py b/localstack/services/acm/provider.py index 9c5e82260cd8c..2daf5c4f24add 100644 --- a/localstack/services/acm/provider.py +++ b/localstack/services/acm/provider.py @@ -18,7 +18,6 @@ @patch(acm_models.CertBundle.describe) def describe(describe_orig, self): - # TODO fix! Terrible hack (for parity). Moto adds certain required fields only if status is PENDING_VALIDATION. cert_status = self.status self.status = "PENDING_VALIDATION" diff --git a/localstack/services/apigateway/helpers.py b/localstack/services/apigateway/helpers.py index 6e0d32b6c6265..1b5c9646ef4c4 100644 --- a/localstack/services/apigateway/helpers.py +++ b/localstack/services/apigateway/helpers.py @@ -923,7 +923,6 @@ def is_api_key_required(path_payload: dict) -> bool: return False def create_authorizers(security_schemes: dict) -> None: - for security_scheme_name, security_config in security_schemes.items(): aws_apigateway_authorizer = security_config.get(OpenAPIExt.AUTHORIZER, {}) if not aws_apigateway_authorizer: diff --git a/localstack/services/apigateway/invocations.py b/localstack/services/apigateway/invocations.py index 78b2c6e3b6a7d..49e0a16916186 100644 --- a/localstack/services/apigateway/invocations.py +++ b/localstack/services/apigateway/invocations.py @@ -146,7 +146,6 @@ def should_validate_request(validator): def validate_api_key(api_key: str, invocation_context: ApiInvocationContext): - usage_plan_ids = [] client = connect_to( aws_access_key_id=invocation_context.account_id, region_name=invocation_context.region_name diff --git a/localstack/services/apigateway/provider.py b/localstack/services/apigateway/provider.py index 9c5e6ecc1d004..dfab0165b6f13 100644 --- a/localstack/services/apigateway/provider.py +++ b/localstack/services/apigateway/provider.py @@ -1230,7 +1230,6 @@ def import_documentation_parts( mode: PutMode = None, fail_on_warnings: Boolean = None, ) -> DocumentationPartIds: - body_data = body.read() openapi_spec = parse_json_or_yaml(to_str(body_data)) @@ -1690,7 +1689,6 @@ def import_rest_api( fail_on_warnings: Boolean = None, parameters: MapOfStringToString = None, ) -> RestApi: - body_data = body.read() # create rest api diff --git a/localstack/services/certificatemanager/resource_providers/aws_certificatemanager_certificate.py b/localstack/services/certificatemanager/resource_providers/aws_certificatemanager_certificate.py index 4b11f96525b23..d79d62975e87f 100644 --- a/localstack/services/certificatemanager/resource_providers/aws_certificatemanager_certificate.py +++ b/localstack/services/certificatemanager/resource_providers/aws_certificatemanager_certificate.py @@ -41,7 +41,6 @@ class Tag(TypedDict): class CertificateManagerCertificateProvider( ResourceProvider[CertificateManagerCertificateProperties] ): - TYPE = "AWS::CertificateManager::Certificate" # Autogenerated. Don't change SCHEMA = util.get_schema_path(Path(__file__)) # Autogenerated. Don't change diff --git a/localstack/services/cloudformation/engine/template_deployer.py b/localstack/services/cloudformation/engine/template_deployer.py index 1f95f8d0698f9..4d6624073be9f 100644 --- a/localstack/services/cloudformation/engine/template_deployer.py +++ b/localstack/services/cloudformation/engine/template_deployer.py @@ -830,9 +830,9 @@ def deploy_stack(self): action="CREATE", ) except Exception as e: - log_method = getattr(LOG, "info") + log_method = LOG.info if config.CFN_VERBOSE_ERRORS: - log_method = getattr(LOG, "exception") + log_method = LOG.exception log_method("Unable to create stack %s: %s", self.stack.stack_name, e) self.stack.set_stack_status("CREATE_FAILED") raise @@ -924,9 +924,9 @@ def _safe_lookup_is_deleted(r_id): e, ) else: - log_method = getattr(LOG, "warning") + log_method = LOG.warning if config.CFN_VERBOSE_ERRORS: - log_method = getattr(LOG, "exception") + log_method = LOG.exception log_method( "Failed delete of resource with id %s in iteration cycle %d. Retrying in next cycle.", resource_id, @@ -1172,9 +1172,9 @@ def _run(*args): self.do_apply_changes_in_loop(changes, stack) status = f"{action}_COMPLETE" except Exception as e: - log_method = getattr(LOG, "debug") + log_method = LOG.debug if config.CFN_VERBOSE_ERRORS: - log_method = getattr(LOG, "exception") + log_method = LOG.exception log_method( 'Error applying changes for CloudFormation stack "%s": %s %s', stack.stack_name, @@ -1248,9 +1248,9 @@ def do_apply_changes_in_loop(self, changes, stack): del changes[j] updated = True except DependencyNotYetSatisfied as e: - log_method = getattr(LOG, "debug") + log_method = LOG.debug if config.CFN_VERBOSE_ERRORS: - log_method = getattr(LOG, "exception") + log_method = LOG.exception log_method( 'Dependencies for "%s" not yet satisfied, retrying in next loop: %s', resource_id, @@ -1449,7 +1449,7 @@ def resolve_outputs(account_id: str, region_name: str, stack) -> list[dict]: ) value = details["Value"] except Exception as e: - log_method = getattr(LOG, "debug") + log_method = LOG.debug if config.CFN_VERBOSE_ERRORS: raise # unresolvable outputs cause a stack failure # log_method = getattr(LOG, "exception") diff --git a/localstack/services/cloudformation/engine/template_utils.py b/localstack/services/cloudformation/engine/template_utils.py index 3e4873b6a736d..7ad467e9079e4 100644 --- a/localstack/services/cloudformation/engine/template_utils.py +++ b/localstack/services/cloudformation/engine/template_utils.py @@ -51,7 +51,6 @@ def resolve_dependencies(d: dict, evaluated_conditions: dict[str, bool]) -> set[ # { "Fn::Sub" : [ "Hello ${Name}", { "Name": "SomeName" } ] } variables_found = re.findall("\\${([^}]+)}", v[0]) for var in variables_found: - if var in v[1]: # variable is included in provided mapping and can either be a static value or another reference if isinstance(v[1][var], dict): diff --git a/localstack/services/cloudformation/provider.py b/localstack/services/cloudformation/provider.py index 491d24188c93b..a4b5996403798 100644 --- a/localstack/services/cloudformation/provider.py +++ b/localstack/services/cloudformation/provider.py @@ -156,7 +156,6 @@ def __init__(self, message=None): class CloudformationProvider(CloudformationApi): @handler("CreateStack", expand=False) def create_stack(self, context: RequestContext, request: CreateStackInput) -> CreateStackOutput: - # TODO: test what happens when both TemplateUrl and Body are specified state = get_cloudformation_store(context.account_id, context.region) template_body = request.get("TemplateBody") or "" @@ -644,7 +643,6 @@ def describe_change_set( stack_name: StackNameOrId = None, next_token: NextToken = None, ) -> DescribeChangeSetOutput: - # only relevant if change_set_name isn't an ARN if not ARN_CHANGESET_REGEX.match(change_set_name): if not stack_name: @@ -682,7 +680,6 @@ def delete_change_set( change_set_name: ChangeSetNameOrId, stack_name: StackNameOrId = None, ) -> DeleteChangeSetOutput: - # only relevant if change_set_name isn't an ARN if not ARN_CHANGESET_REGEX.match(change_set_name): if not stack_name: @@ -808,7 +805,6 @@ def describe_stack_resources( logical_resource_id: LogicalResourceId = None, physical_resource_id: PhysicalResourceId = None, ) -> DescribeStackResourcesOutput: - if physical_resource_id and stack_name: raise ValidationError("Cannot specify both StackName and PhysicalResourceId") # TODO: filter stack by PhysicalResourceId! diff --git a/localstack/services/cloudformation/resource_provider.py b/localstack/services/cloudformation/resource_provider.py index 7e7bd2a432392..407ce9b7955e5 100644 --- a/localstack/services/cloudformation/resource_provider.py +++ b/localstack/services/cloudformation/resource_provider.py @@ -266,9 +266,9 @@ def invoke_function( except Exception as e: if action_name == "Remove" and check_not_found_exception(e, resource_type, resource): return - log_method = getattr(LOG, "warning") + log_method = LOG.warning if config.CFN_VERBOSE_ERRORS: - log_method = getattr(LOG, "exception") + log_method = LOG.exception log_method("Error calling %s with params: %s for resource: %s", function, params, resource) raise e @@ -660,7 +660,6 @@ def deploy_loop( return event if event.status == OperationStatus.SUCCESS: - if not isinstance(resource_provider, LegacyResourceProvider): # branch for non-legacy providers # TODO: move out of if? (physical res id can be set earlier possibly) diff --git a/localstack/services/cloudformation/scaffolding/templates/test_parity_template.py.j2 b/localstack/services/cloudformation/scaffolding/templates/test_parity_template.py.j2 index b3d0128062355..6cf269aa392db 100644 --- a/localstack/services/cloudformation/scaffolding/templates/test_parity_template.py.j2 +++ b/localstack/services/cloudformation/scaffolding/templates/test_parity_template.py.j2 @@ -1,4 +1,4 @@ -# flake8: noqa +# ruff: noqa # LocalStack Resource Provider Scaffolding {{ scaffolding_version }} import pytest diff --git a/localstack/services/cloudwatch/provider.py b/localstack/services/cloudwatch/provider.py index 59f6a931a38a0..5a18e8790b05d 100644 --- a/localstack/services/cloudwatch/provider.py +++ b/localstack/services/cloudwatch/provider.py @@ -352,9 +352,8 @@ def put_metric_alarm( context: RequestContext, request: PutMetricAlarmInput, ) -> None: - # missing will be the default, when not set (but it will not explicitly be set) - if not request.get("TreatMissingData", "missing") in [ + if request.get("TreatMissingData", "missing") not in [ "breaching", "notBreaching", "ignore", @@ -371,7 +370,7 @@ def put_metric_alarm( if value % 60 != 0: raise ValidationError("Period must be 10, 30 or a multiple of 60") if request.get("Statistic"): - if not request.get("Statistic") in [ + if request.get("Statistic") not in [ "SampleCount", "Average", "Sum", diff --git a/localstack/services/cloudwatch/resource_providers/aws_cloudwatch_alarm.py b/localstack/services/cloudwatch/resource_providers/aws_cloudwatch_alarm.py index a9b794086cc83..bee2901577fe6 100644 --- a/localstack/services/cloudwatch/resource_providers/aws_cloudwatch_alarm.py +++ b/localstack/services/cloudwatch/resource_providers/aws_cloudwatch_alarm.py @@ -71,7 +71,6 @@ class MetricDataQuery(TypedDict): class CloudWatchAlarmProvider(ResourceProvider[CloudWatchAlarmProperties]): - TYPE = "AWS::CloudWatch::Alarm" # Autogenerated. Don't change SCHEMA = util.get_schema_path(Path(__file__)) # Autogenerated. Don't change diff --git a/localstack/services/cloudwatch/resource_providers/aws_cloudwatch_compositealarm.py b/localstack/services/cloudwatch/resource_providers/aws_cloudwatch_compositealarm.py index 5c7e4e7c4e45c..e2ec95828eb8e 100644 --- a/localstack/services/cloudwatch/resource_providers/aws_cloudwatch_compositealarm.py +++ b/localstack/services/cloudwatch/resource_providers/aws_cloudwatch_compositealarm.py @@ -32,7 +32,6 @@ class CloudWatchCompositeAlarmProperties(TypedDict): class CloudWatchCompositeAlarmProvider(ResourceProvider[CloudWatchCompositeAlarmProperties]): - TYPE = "AWS::CloudWatch::CompositeAlarm" # Autogenerated. Don't change SCHEMA = util.get_schema_path(Path(__file__)) # Autogenerated. Don't change diff --git a/localstack/services/dynamodb/provider.py b/localstack/services/dynamodb/provider.py index fa719c8438502..0532252db262c 100644 --- a/localstack/services/dynamodb/provider.py +++ b/localstack/services/dynamodb/provider.py @@ -348,7 +348,6 @@ def modify_context_region(context: RequestContext, region: str): class DynamoDBProvider(DynamodbApi, ServiceLifecycleHook): - server: DynamodbServer """The instance of the server managing the instance of DynamoDB local""" diff --git a/localstack/services/dynamodb/resource_providers/aws_dynamodb_table.py b/localstack/services/dynamodb/resource_providers/aws_dynamodb_table.py index bfbb099dc21e5..18c7c279e41e3 100644 --- a/localstack/services/dynamodb/resource_providers/aws_dynamodb_table.py +++ b/localstack/services/dynamodb/resource_providers/aws_dynamodb_table.py @@ -127,7 +127,6 @@ class ImportSourceSpecification(TypedDict): class DynamoDBTableProvider(ResourceProvider[DynamoDBTableProperties]): - TYPE = "AWS::DynamoDB::Table" # Autogenerated. Don't change SCHEMA = util.get_schema_path(Path(__file__)) # Autogenerated. Don't change diff --git a/localstack/services/ec2/provider.py b/localstack/services/ec2/provider.py index 40e22f8a49639..21db8ab2acde2 100644 --- a/localstack/services/ec2/provider.py +++ b/localstack/services/ec2/provider.py @@ -355,7 +355,6 @@ def create_launch_template( context: RequestContext, request: CreateLaunchTemplateRequest, ) -> CreateLaunchTemplateResult: - # parameter validation if not request["LaunchTemplateData"]: raise MissingParameterError(parameter="LaunchTemplateData") @@ -372,7 +371,6 @@ def modify_launch_template( context: RequestContext, request: ModifyLaunchTemplateRequest, ) -> ModifyLaunchTemplateResult: - backend = get_ec2_backend(context.account_id, context.region) template_id = ( request["LaunchTemplateId"] diff --git a/localstack/services/ecr/resource_providers/aws_ecr_repository.py b/localstack/services/ecr/resource_providers/aws_ecr_repository.py index 4f547e0ad54f1..67a3755e00077 100644 --- a/localstack/services/ecr/resource_providers/aws_ecr_repository.py +++ b/localstack/services/ecr/resource_providers/aws_ecr_repository.py @@ -55,7 +55,6 @@ class EncryptionConfiguration(TypedDict): class ECRRepositoryProvider(ResourceProvider[ECRRepositoryProperties]): - TYPE = "AWS::ECR::Repository" # Autogenerated. Don't change SCHEMA = util.get_schema_path(Path(__file__)) # Autogenerated. Don't change diff --git a/localstack/services/es/provider.py b/localstack/services/es/provider.py index 72f3fd273959e..7b1ddd724665b 100644 --- a/localstack/services/es/provider.py +++ b/localstack/services/es/provider.py @@ -11,9 +11,6 @@ AdvancedOptions, AdvancedSecurityOptionsInput, AutoTuneOptionsInput, -) -from localstack.aws.api.es import BaseException as EsBaseException -from localstack.aws.api.es import ( CognitoOptions, CompatibleElasticsearchVersionsList, CompatibleVersionsMap, @@ -62,6 +59,7 @@ ValidationException, VPCOptions, ) +from localstack.aws.api.es import BaseException as EsBaseException from localstack.aws.api.opensearch import ( ClusterConfig, CompatibleVersionsList, diff --git a/localstack/services/events/provider.py b/localstack/services/events/provider.py index d29ad6c7a0002..f3d60de37aba5 100644 --- a/localstack/services/events/provider.py +++ b/localstack/services/events/provider.py @@ -108,7 +108,6 @@ def get_store(context: RequestContext) -> EventsStore: def test_event_pattern( self, context: RequestContext, event_pattern: EventPattern, event: String ) -> TestEventPatternResponse: - # https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_TestEventPattern.html # Test event pattern uses event pattern to match against event. # So event pattern keys must be in the event keys and values must match. diff --git a/localstack/services/events/scheduler.py b/localstack/services/events/scheduler.py index a8b6206a178ea..d6dfa66c06ec9 100644 --- a/localstack/services/events/scheduler.py +++ b/localstack/services/events/scheduler.py @@ -33,7 +33,6 @@ def do_run(self): class JobScheduler: - _instance = None def __init__(self): diff --git a/localstack/services/firehose/provider.py b/localstack/services/firehose/provider.py index 857463052fb16..ecbec164ff9c3 100644 --- a/localstack/services/firehose/provider.py +++ b/localstack/services/firehose/provider.py @@ -530,7 +530,6 @@ def _put_records( self._add_missing_record_attributes(unprocessed_records) for destination in delivery_stream_description.get("Destinations", []): - # apply processing steps to incoming items proc_config = {} for child in destination.values(): diff --git a/localstack/services/iam/provider.py b/localstack/services/iam/provider.py index 86c9f035c336a..aa4639933f5d9 100644 --- a/localstack/services/iam/provider.py +++ b/localstack/services/iam/provider.py @@ -4,9 +4,16 @@ from typing import Dict, List, Optional from urllib.parse import quote -from moto.iam.models import AccessKey, AWSManagedPolicy, IAMBackend, InlinePolicy, Policy +from moto.iam.models import ( + AccessKey, + AWSManagedPolicy, + IAMBackend, + InlinePolicy, + Policy, + filter_items_with_path_prefix, + iam_backends, +) from moto.iam.models import Role as MotoRole -from moto.iam.models import filter_items_with_path_prefix, iam_backends from moto.iam.policy_validation import VALID_STATEMENT_ELEMENTS from localstack import config diff --git a/localstack/services/iam/resource_providers/aws_iam_accesskey.py b/localstack/services/iam/resource_providers/aws_iam_accesskey.py index 694c970943634..a945e5af67a47 100644 --- a/localstack/services/iam/resource_providers/aws_iam_accesskey.py +++ b/localstack/services/iam/resource_providers/aws_iam_accesskey.py @@ -25,7 +25,6 @@ class IAMAccessKeyProperties(TypedDict): class IAMAccessKeyProvider(ResourceProvider[IAMAccessKeyProperties]): - TYPE = "AWS::IAM::AccessKey" # Autogenerated. Don't change SCHEMA = util.get_schema_path(Path(__file__)) # Autogenerated. Don't change diff --git a/localstack/services/iam/resource_providers/aws_iam_group.py b/localstack/services/iam/resource_providers/aws_iam_group.py index b2452c10c2c20..360648734604f 100644 --- a/localstack/services/iam/resource_providers/aws_iam_group.py +++ b/localstack/services/iam/resource_providers/aws_iam_group.py @@ -32,7 +32,6 @@ class Policy(TypedDict): class IAMGroupProvider(ResourceProvider[IAMGroupProperties]): - TYPE = "AWS::IAM::Group" # Autogenerated. Don't change SCHEMA = util.get_schema_path(Path(__file__)) # Autogenerated. Don't change diff --git a/localstack/services/iam/resource_providers/aws_iam_instanceprofile.py b/localstack/services/iam/resource_providers/aws_iam_instanceprofile.py index df75caefedede..9d21cad5aafae 100644 --- a/localstack/services/iam/resource_providers/aws_iam_instanceprofile.py +++ b/localstack/services/iam/resource_providers/aws_iam_instanceprofile.py @@ -24,7 +24,6 @@ class IAMInstanceProfileProperties(TypedDict): class IAMInstanceProfileProvider(ResourceProvider[IAMInstanceProfileProperties]): - TYPE = "AWS::IAM::InstanceProfile" # Autogenerated. Don't change SCHEMA = util.get_schema_path(Path(__file__)) # Autogenerated. Don't change diff --git a/localstack/services/iam/resource_providers/aws_iam_managedpolicy.py b/localstack/services/iam/resource_providers/aws_iam_managedpolicy.py index afc11f7b2af93..0bca0e5a02169 100644 --- a/localstack/services/iam/resource_providers/aws_iam_managedpolicy.py +++ b/localstack/services/iam/resource_providers/aws_iam_managedpolicy.py @@ -29,7 +29,6 @@ class IAMManagedPolicyProperties(TypedDict): class IAMManagedPolicyProvider(ResourceProvider[IAMManagedPolicyProperties]): - TYPE = "AWS::IAM::ManagedPolicy" # Autogenerated. Don't change SCHEMA = util.get_schema_path(Path(__file__)) # Autogenerated. Don't change diff --git a/localstack/services/iam/resource_providers/aws_iam_policy.py b/localstack/services/iam/resource_providers/aws_iam_policy.py index 0cfedd58e2490..97fdb19341b57 100644 --- a/localstack/services/iam/resource_providers/aws_iam_policy.py +++ b/localstack/services/iam/resource_providers/aws_iam_policy.py @@ -29,7 +29,6 @@ class IAMPolicyProperties(TypedDict): class IAMPolicyProvider(ResourceProvider[IAMPolicyProperties]): - TYPE = "AWS::IAM::Policy" # Autogenerated. Don't change SCHEMA = util.get_schema_path(Path(__file__)) # Autogenerated. Don't change diff --git a/localstack/services/iam/resource_providers/aws_iam_role.py b/localstack/services/iam/resource_providers/aws_iam_role.py index ce22bc37f6b35..de7007462b16f 100644 --- a/localstack/services/iam/resource_providers/aws_iam_role.py +++ b/localstack/services/iam/resource_providers/aws_iam_role.py @@ -45,7 +45,6 @@ class Tag(TypedDict): class IAMRoleProvider(ResourceProvider[IAMRoleProperties]): - TYPE = "AWS::IAM::Role" # Autogenerated. Don't change SCHEMA = util.get_schema_path(Path(__file__)) # Autogenerated. Don't change diff --git a/localstack/services/iam/resource_providers/aws_iam_servicelinkedrole.py b/localstack/services/iam/resource_providers/aws_iam_servicelinkedrole.py index 5f13604e5f30c..2437966df10e7 100644 --- a/localstack/services/iam/resource_providers/aws_iam_servicelinkedrole.py +++ b/localstack/services/iam/resource_providers/aws_iam_servicelinkedrole.py @@ -24,7 +24,6 @@ class IAMServiceLinkedRoleProperties(TypedDict): class IAMServiceLinkedRoleProvider(ResourceProvider[IAMServiceLinkedRoleProperties]): - TYPE = "AWS::IAM::ServiceLinkedRole" # Autogenerated. Don't change SCHEMA = util.get_schema_path(Path(__file__)) # Autogenerated. Don't change diff --git a/localstack/services/iam/resource_providers/aws_iam_user.py b/localstack/services/iam/resource_providers/aws_iam_user.py index 5b4b1d88c582d..c1b6cbe5fb9e7 100644 --- a/localstack/services/iam/resource_providers/aws_iam_user.py +++ b/localstack/services/iam/resource_providers/aws_iam_user.py @@ -45,7 +45,6 @@ class Tag(TypedDict): class IAMUserProvider(ResourceProvider[IAMUserProperties]): - TYPE = "AWS::IAM::User" # Autogenerated. Don't change SCHEMA = util.get_schema_path(Path(__file__)) # Autogenerated. Don't change diff --git a/localstack/services/kinesis/provider.py b/localstack/services/kinesis/provider.py index 14b32c16edb7c..5b0d856e594b1 100644 --- a/localstack/services/kinesis/provider.py +++ b/localstack/services/kinesis/provider.py @@ -54,7 +54,6 @@ def find_stream_for_consumer(consumer_arn): class KinesisProvider(KinesisApi, ServiceLifecycleHook): - server_manager: KinesisServerManager def __init__(self): diff --git a/localstack/services/kinesis/resource_providers/aws_kinesis_stream.py b/localstack/services/kinesis/resource_providers/aws_kinesis_stream.py index 10f1a1cceb9b5..24ec6c9b79c35 100644 --- a/localstack/services/kinesis/resource_providers/aws_kinesis_stream.py +++ b/localstack/services/kinesis/resource_providers/aws_kinesis_stream.py @@ -41,7 +41,6 @@ class Tag(TypedDict): class KinesisStreamProvider(ResourceProvider[KinesisStreamProperties]): - TYPE = "AWS::Kinesis::Stream" # Autogenerated. Don't change SCHEMA = util.get_schema_path(Path(__file__)) # Autogenerated. Don't change diff --git a/localstack/services/kinesis/resource_providers/aws_kinesis_streamconsumer.py b/localstack/services/kinesis/resource_providers/aws_kinesis_streamconsumer.py index 0d0ef25b23bae..80279e6ecf849 100644 --- a/localstack/services/kinesis/resource_providers/aws_kinesis_streamconsumer.py +++ b/localstack/services/kinesis/resource_providers/aws_kinesis_streamconsumer.py @@ -26,7 +26,6 @@ class KinesisStreamConsumerProperties(TypedDict): class KinesisStreamConsumerProvider(ResourceProvider[KinesisStreamConsumerProperties]): - TYPE = "AWS::Kinesis::StreamConsumer" # Autogenerated. Don't change SCHEMA = util.get_schema_path(Path(__file__)) # Autogenerated. Don't change diff --git a/localstack/services/kinesisfirehose/resource_providers/aws_kinesisfirehose_deliverystream.py b/localstack/services/kinesisfirehose/resource_providers/aws_kinesisfirehose_deliverystream.py index f4145d37bbc22..6764a783667f0 100644 --- a/localstack/services/kinesisfirehose/resource_providers/aws_kinesisfirehose_deliverystream.py +++ b/localstack/services/kinesisfirehose/resource_providers/aws_kinesisfirehose_deliverystream.py @@ -344,7 +344,6 @@ class Tag(TypedDict): class KinesisFirehoseDeliveryStreamProvider( ResourceProvider[KinesisFirehoseDeliveryStreamProperties] ): - TYPE = "AWS::KinesisFirehose::DeliveryStream" # Autogenerated. Don't change SCHEMA = util.get_schema_path(Path(__file__)) # Autogenerated. Don't change diff --git a/localstack/services/kms/resource_providers/aws_kms_alias.py b/localstack/services/kms/resource_providers/aws_kms_alias.py index ccb4456e2d918..81ecef65ca520 100644 --- a/localstack/services/kms/resource_providers/aws_kms_alias.py +++ b/localstack/services/kms/resource_providers/aws_kms_alias.py @@ -22,7 +22,6 @@ class KMSAliasProperties(TypedDict): class KMSAliasProvider(ResourceProvider[KMSAliasProperties]): - TYPE = "AWS::KMS::Alias" # Autogenerated. Don't change SCHEMA = util.get_schema_path(Path(__file__)) # Autogenerated. Don't change diff --git a/localstack/services/kms/resource_providers/aws_kms_key.py b/localstack/services/kms/resource_providers/aws_kms_key.py index 3bdd0d1f26c4f..f781ea47c64ec 100644 --- a/localstack/services/kms/resource_providers/aws_kms_key.py +++ b/localstack/services/kms/resource_providers/aws_kms_key.py @@ -37,7 +37,6 @@ class Tag(TypedDict): class KMSKeyProvider(ResourceProvider[KMSKeyProperties]): - TYPE = "AWS::KMS::Key" # Autogenerated. Don't change SCHEMA = util.get_schema_path(Path(__file__)) # Autogenerated. Don't change diff --git a/localstack/services/lambda_/event_source_listeners/event_source_listener.py b/localstack/services/lambda_/event_source_listeners/event_source_listener.py index d24be3e27fdfb..df28085ba7c9c 100644 --- a/localstack/services/lambda_/event_source_listeners/event_source_listener.py +++ b/localstack/services/lambda_/event_source_listeners/event_source_listener.py @@ -24,9 +24,11 @@ def start(self, invoke_adapter: Optional[EventSourceAdapter] = None): def start_listeners(event_source_mapping: Dict): # force import EventSourceListener subclasses # otherwise they will not be detected by EventSourceListener.get(service_type) - from . import dynamodb_event_source_listener # noqa: F401 - from . import kinesis_event_source_listener # noqa: F401 - from . import sqs_event_source_listener # noqa: F401 + from . import ( + dynamodb_event_source_listener, # noqa: F401 + kinesis_event_source_listener, # noqa: F401 + sqs_event_source_listener, # noqa: F401 + ) source_arn = event_source_mapping.get("EventSourceArn") or "" parts = source_arn.split(":") @@ -46,9 +48,11 @@ def start_listeners_for_asf(event_source_mapping: Dict, lambda_service: LambdaSe """limited version of start_listeners for the new provider during migration""" # force import EventSourceListener subclasses # otherwise they will not be detected by EventSourceListener.get(service_type) - from . import dynamodb_event_source_listener # noqa: F401 - from . import kinesis_event_source_listener # noqa: F401 - from . import sqs_event_source_listener # noqa: F401 + from . import ( + dynamodb_event_source_listener, # noqa: F401 + kinesis_event_source_listener, # noqa: F401 + sqs_event_source_listener, # noqa: F401 + ) source_arn = event_source_mapping.get("EventSourceArn") or "" parts = source_arn.split(":") diff --git a/localstack/services/lambda_/invocation/event_manager.py b/localstack/services/lambda_/invocation/event_manager.py index 1fe9446a1a574..5ebd3b1c16728 100644 --- a/localstack/services/lambda_/invocation/event_manager.py +++ b/localstack/services/lambda_/invocation/event_manager.py @@ -485,7 +485,7 @@ def stop(self) -> None: self.poller, id(self), ) - with (self.lifecycle_lock): + with self.lifecycle_lock: if self.stopped.is_set(): LOG.debug("Event manager already stopped!") return diff --git a/localstack/services/lambda_/lambda_api.py b/localstack/services/lambda_/lambda_api.py index b7a3c945d102f..b5de0767e6c98 100644 --- a/localstack/services/lambda_/lambda_api.py +++ b/localstack/services/lambda_/lambda_api.py @@ -1423,7 +1423,6 @@ def update_function_configuration(function): def generate_policy_statement(sid, action, arn, sourcearn, principal, url_auth_type): - statement = { "Sid": sid, "Effect": "Allow", diff --git a/localstack/services/lambda_/lambda_executors.py b/localstack/services/lambda_/lambda_executors.py index 92fa62494ba0b..1858911963a4d 100644 --- a/localstack/services/lambda_/lambda_executors.py +++ b/localstack/services/lambda_/lambda_executors.py @@ -227,7 +227,8 @@ class LambdaExecutorPlugin: def initialize(self): """Called once, for any active plugin to run initialization logic (e.g., downloading dependencies). - Uses lazy initialization - i.e., runs only after the first should_apply() call returns True""" + Uses lazy initialization - i.e., runs only after the first should_apply() call returns True + """ pass def should_apply(self, context: InvocationContext) -> bool: @@ -238,7 +239,8 @@ def prepare_invocation( self, context: InvocationContext ) -> Optional[Union[AdditionalInvocationOptions, InvocationResult]]: """Return additional invocation options for given Lambda invocation context. Optionally, an - InvocationResult can be returned, in which case the result is returned to the client right away.""" + InvocationResult can be returned, in which case the result is returned to the client right away. + """ return None def process_result( @@ -505,7 +507,8 @@ def cleanup(self, arn=None): def provide_file_to_lambda(self, local_file: str, inv_context: InvocationContext) -> str: """Make the given file available to the Lambda process (e.g., by copying into the container) for the - given invocation context; Returns the path to the file that will be available to the Lambda handler.""" + given invocation context; Returns the path to the file that will be available to the Lambda handler. + """ raise NotImplementedError def apply_plugin_patches(self, inv_context: InvocationContext) -> Optional[InvocationResult]: @@ -910,7 +913,8 @@ def _should_use_stay_open_mode( check_port: bool = False, ) -> bool: """Return whether to use stay-open execution mode - if we're running in Docker, the given IP - is defined, and if the target API endpoint is available (optionally, if check_port is True).""" + is defined, and if the target API endpoint is available (optionally, if check_port is True). + """ if not lambda_docker_ip: func_arn = lambda_function.arn() container_name = self.get_container_name(func_arn) @@ -1382,7 +1386,6 @@ def _execute_in_custom_runtime( def _execute( self, lambda_function: LambdaFunction, inv_context: InvocationContext ) -> InvocationResult: - # apply plugin patches to prepare invocation context result = self.apply_plugin_patches(inv_context) if isinstance(result, InvocationResult): @@ -1592,7 +1595,6 @@ def execute_javascript_lambda( return result def execute_go_lambda(self, event, context, main_file, lambda_function: LambdaFunction = None): - if lambda_function: lambda_function.envvars["AWS_LAMBDA_FUNCTION_HANDLER"] = main_file lambda_function.envvars["AWS_LAMBDA_EVENT_BODY"] = json.dumps(json_safe(event)) diff --git a/localstack/services/lambda_/lambda_utils.py b/localstack/services/lambda_/lambda_utils.py index aa43ea7c784db..ac86b7bcdb894 100644 --- a/localstack/services/lambda_/lambda_utils.py +++ b/localstack/services/lambda_/lambda_utils.py @@ -326,7 +326,6 @@ def parse_and_apply_numeric_filter( return False for idx in range(0, len(numeric_filter), 2): - try: if numeric_filter[idx] == ">" and not (record_value > float(numeric_filter[idx + 1])): return False diff --git a/localstack/services/lambda_/provider.py b/localstack/services/lambda_/provider.py index fbeac249e0410..5e46d5aab7c45 100644 --- a/localstack/services/lambda_/provider.py +++ b/localstack/services/lambda_/provider.py @@ -47,9 +47,6 @@ FunctionName, FunctionUrlAuthType, FunctionUrlQualifier, -) -from localstack.aws.api.lambda_ import FunctionVersion as FunctionVersionApi -from localstack.aws.api.lambda_ import ( GetAccountSettingsResponse, GetCodeSigningConfigResponse, GetFunctionCodeSigningConfigResponse, @@ -116,9 +113,6 @@ ResourceNotFoundException, Runtime, RuntimeVersionConfig, -) -from localstack.aws.api.lambda_ import ServiceException as LambdaServiceException -from localstack.aws.api.lambda_ import ( SnapStart, SnapStartApplyOn, SnapStartOptimizationStatus, @@ -137,6 +131,8 @@ UpdateFunctionUrlConfigResponse, Version, ) +from localstack.aws.api.lambda_ import FunctionVersion as FunctionVersionApi +from localstack.aws.api.lambda_ import ServiceException as LambdaServiceException from localstack.aws.connect import connect_to from localstack.services.edge import ROUTER from localstack.services.lambda_ import api_utils @@ -2212,7 +2208,6 @@ def create_code_signing_config( description: Description = None, code_signing_policies: CodeSigningPolicies = None, ) -> CreateCodeSigningConfigResponse: - state = lambda_stores[context.account_id][context.region] # TODO: can there be duplicates? csc_id = f"csc-{get_random_hex(17)}" # e.g. 'csc-077c33b4c19e26036' @@ -2639,7 +2634,6 @@ def list_provisioned_concurrency_configs( configs = [] for qualifier, pc_config in fn.provisioned_concurrency_configs.items(): - if api_utils.qualifier_is_alias(qualifier): alias = fn.aliases.get(qualifier) fn_arn = api_utils.qualified_lambda_arn( diff --git a/localstack/services/lambda_/resource_providers/lambda_alias.py b/localstack/services/lambda_/resource_providers/lambda_alias.py index 96cb9ec870693..ac05446ca5bde 100644 --- a/localstack/services/lambda_/resource_providers/lambda_alias.py +++ b/localstack/services/lambda_/resource_providers/lambda_alias.py @@ -40,7 +40,6 @@ class AliasRoutingConfiguration(TypedDict): class LambdaAliasProvider(ResourceProvider[LambdaAliasProperties]): - TYPE = "AWS::Lambda::Alias" # Autogenerated. Don't change SCHEMA = util.get_schema_path(Path(__file__)) # Autogenerated. Don't change diff --git a/localstack/services/lambda_/urlrouter.py b/localstack/services/lambda_/urlrouter.py index 3daf150b47f2b..87c9d41560f95 100644 --- a/localstack/services/lambda_/urlrouter.py +++ b/localstack/services/lambda_/urlrouter.py @@ -23,7 +23,6 @@ class FunctionUrlRouter: - router: Router[Handler] lambda_service: LambdaService diff --git a/localstack/services/logs/models.py b/localstack/services/logs/models.py index 794341a2464d6..5e2ba973cab93 100644 --- a/localstack/services/logs/models.py +++ b/localstack/services/logs/models.py @@ -11,7 +11,6 @@ def get_moto_logs_backend(account_id: str, region_name: str) -> MotoLogsBackend: class LogsStore(BaseStore): - # maps resource ARN to tags TAGS: Dict[str, Dict[str, str]] = CrossRegionAttribute(default=dict) diff --git a/localstack/services/logs/provider.py b/localstack/services/logs/provider.py index 35e96de79b69e..0c6297168acb5 100644 --- a/localstack/services/logs/provider.py +++ b/localstack/services/logs/provider.py @@ -7,9 +7,8 @@ from typing import Callable, Dict from moto.core.utils import unix_time_millis -from moto.logs.models import LogEvent +from moto.logs.models import LogEvent, LogsBackend from moto.logs.models import LogGroup as MotoLogGroup -from moto.logs.models import LogsBackend from moto.logs.models import LogStream as MotoLogStream from localstack.aws.accounts import get_aws_account_id diff --git a/localstack/services/opensearch/resource_providers/aws_opensearchservice_domain.py b/localstack/services/opensearch/resource_providers/aws_opensearchservice_domain.py index 4da61b6ef56f2..96b8c60ec0b2b 100644 --- a/localstack/services/opensearch/resource_providers/aws_opensearchservice_domain.py +++ b/localstack/services/opensearch/resource_providers/aws_opensearchservice_domain.py @@ -166,7 +166,6 @@ class SoftwareUpdateOptions(TypedDict): class OpenSearchServiceDomainProvider(ResourceProvider[OpenSearchServiceDomainProperties]): - TYPE = "AWS::OpenSearchService::Domain" # Autogenerated. Don't change SCHEMA = util.get_schema_path(Path(__file__)) # Autogenerated. Don't change diff --git a/localstack/services/route53/resource_providers/aws_route53_healthcheck.py b/localstack/services/route53/resource_providers/aws_route53_healthcheck.py index e53f1e18a5060..ddd156b7e638f 100644 --- a/localstack/services/route53/resource_providers/aws_route53_healthcheck.py +++ b/localstack/services/route53/resource_providers/aws_route53_healthcheck.py @@ -28,7 +28,6 @@ class HealthCheckTag(TypedDict): class Route53HealthCheckProvider(ResourceProvider[Route53HealthCheckProperties]): - TYPE = "AWS::Route53::HealthCheck" # Autogenerated. Don't change SCHEMA = util.get_schema_path(Path(__file__)) # Autogenerated. Don't change diff --git a/localstack/services/route53/resource_providers/aws_route53_recordset.py b/localstack/services/route53/resource_providers/aws_route53_recordset.py index ed4754f2c0ba8..3d2ede5828761 100644 --- a/localstack/services/route53/resource_providers/aws_route53_recordset.py +++ b/localstack/services/route53/resource_providers/aws_route53_recordset.py @@ -57,7 +57,6 @@ class GeoLocation(TypedDict): class Route53RecordSetProvider(ResourceProvider[Route53RecordSetProperties]): - TYPE = "AWS::Route53::RecordSet" # Autogenerated. Don't change SCHEMA = util.get_schema_path(Path(__file__)) # Autogenerated. Don't change diff --git a/localstack/services/s3/cors.py b/localstack/services/s3/cors.py index 6e2dc36603381..bf17f3b950dbb 100644 --- a/localstack/services/s3/cors.py +++ b/localstack/services/s3/cors.py @@ -45,7 +45,6 @@ def buckets(self) -> set[str]: class S3CorsHandler(Handler): - bucket_cors_index: BucketCorsIndex def __init__(self, bucket_cors_index: BucketCorsIndex): diff --git a/localstack/services/s3/legacy/multipart_content.py b/localstack/services/s3/legacy/multipart_content.py index 5a77655eded57..cbb063ff21f7d 100644 --- a/localstack/services/s3/legacy/multipart_content.py +++ b/localstack/services/s3/legacy/multipart_content.py @@ -52,7 +52,7 @@ def expand_multipart_filename(data, headers): filename = None - for (disposition, _) in _iter_multipart_parts(data_bytes, boundary): + for disposition, _ in _iter_multipart_parts(data_bytes, boundary): if disposition.get("name") == "file" and "filename" in disposition: filename = disposition["filename"] break @@ -61,7 +61,7 @@ def expand_multipart_filename(data, headers): # Found nothing, return unaltered return data - for (disposition, part) in _iter_multipart_parts(data_bytes, boundary): + for disposition, part in _iter_multipart_parts(data_bytes, boundary): if disposition.get("name") == "key" and b"${filename}" in part: search = boundary + part replace = boundary + part.replace(b"${filename}", filename.encode("utf8")) @@ -89,13 +89,13 @@ def find_multipart_key_value(data, headers, field_name="success_action_redirect" boundary = params["boundary"].encode("ascii") data_bytes = to_bytes(data) - for (disposition, part) in _iter_multipart_parts(data_bytes, boundary): + for disposition, part in _iter_multipart_parts(data_bytes, boundary): if disposition.get("name") == "key": _, value = part.split(b"\r\n\r\n", 1) key = value.rstrip(b"\r\n--").decode("utf8") if key: - for (disposition, part) in _iter_multipart_parts(data_bytes, boundary): + for disposition, part in _iter_multipart_parts(data_bytes, boundary): if disposition.get("name") == field_name: _, value = part.split(b"\r\n\r\n", 1) field_value = value.rstrip(b"\r\n--").decode("utf8") diff --git a/localstack/services/s3/legacy/s3_listener.py b/localstack/services/s3/legacy/s3_listener.py index 2d19a8e075b27..f85580cb65e84 100644 --- a/localstack/services/s3/legacy/s3_listener.py +++ b/localstack/services/s3/legacy/s3_listener.py @@ -24,9 +24,8 @@ from localstack.aws.connect import connect_to from localstack.aws.protocol.serializer import gen_amzn_requestid from localstack.config import get_protocol as get_service_protocol -from localstack.services.generic_proxy import ProxyListener +from localstack.services.generic_proxy import ProxyListener, is_cors_origin_allowed from localstack.services.generic_proxy import append_cors_headers as _append_default_cors_headers -from localstack.services.generic_proxy import is_cors_origin_allowed from localstack.services.s3.legacy import multipart_content from localstack.services.s3.legacy.s3_utils import ( ALLOWED_HEADER_OVERRIDES, @@ -606,7 +605,6 @@ def append_cors_headers( cors = BackendState.cors_config(bucket_name) assert cors except Exception: - # add default LocalStack CORS if the bucket is not configured and the origin is allowed if is_cors_origin_allowed(request_headers): _append_default_cors_headers(request_headers=request_headers, response=response) @@ -636,7 +634,6 @@ def append_cors_headers( for allowed in allowed_origins: allowed = allowed or "" if origin in allowed or re.match(allowed.replace("*", ".*"), origin): - response.headers["Access-Control-Allow-Origin"] = origin if "AllowedMethod" in rule: response.headers["Access-Control-Allow-Methods"] = ( diff --git a/localstack/services/s3/legacy/s3_utils.py b/localstack/services/s3/legacy/s3_utils.py index fb06bb56f6e95..05fec33a465b1 100644 --- a/localstack/services/s3/legacy/s3_utils.py +++ b/localstack/services/s3/legacy/s3_utils.py @@ -205,7 +205,6 @@ def is_expired(expiry_datetime): def authenticate_presign_url(method, path, headers, data=None): - url = "{}{}".format(config.get_edge_url(), path) parsed = urlparse.urlparse(url) query_params = parse_qs(parsed.query) @@ -346,7 +345,6 @@ def authenticate_presign_url(method, path, headers, data=None): def authenticate_presign_url_signv2(method, path, headers, data, url, query_params, request_dict): - # Calculating Signature aws_request = create_request_object(request_dict) credentials = Credentials( @@ -371,7 +369,6 @@ def authenticate_presign_url_signv2(method, path, headers, data, url, query_para signature = query_sig if query_sig != signature: - return requests_error_response_xml_signature_calculation( code=403, code_string="SignatureDoesNotMatch", diff --git a/localstack/services/s3/notifications.py b/localstack/services/s3/notifications.py index 72fa49a2a4b6e..bc199569ffc47 100644 --- a/localstack/services/s3/notifications.py +++ b/localstack/services/s3/notifications.py @@ -349,7 +349,7 @@ def _validate_notification(self, verification_ctx: BucketVerificationContext): if filter_rules := configuration.get("Filter", {}).get("Key", {}).get("FilterRules"): for rule in filter_rules: rule["Name"] = rule["Name"].capitalize() - if not rule["Name"] in ["Suffix", "Prefix"]: + if rule["Name"] not in ["Suffix", "Prefix"]: raise _create_invalid_argument_exc( "filter rule name must be either prefix or suffix", rule["Name"], diff --git a/localstack/services/s3/provider.py b/localstack/services/s3/provider.py index 19a14ffe315d5..797f4028de55a 100644 --- a/localstack/services/s3/provider.py +++ b/localstack/services/s3/provider.py @@ -6,9 +6,9 @@ from operator import itemgetter from typing import IO, Dict, List, Optional from urllib.parse import quote, urlparse -from zoneinfo import ZoneInfo import moto.s3.responses as moto_s3_responses +from zoneinfo import ZoneInfo from localstack import config from localstack.aws.api import CommonServiceException, RequestContext, ServiceException, handler @@ -783,7 +783,7 @@ def complete_multipart_upload( bucket_name = request["Bucket"] moto_bucket = get_bucket_from_moto(get_moto_s3_backend(context), bucket_name) - if not (upload_id := request.get("UploadId")) in moto_bucket.multiparts: + if (upload_id := request.get("UploadId")) not in moto_bucket.multiparts: raise NoSuchUpload( "The specified upload does not exist. The upload ID may be invalid, or the upload may have been aborted or completed.", UploadId=upload_id, @@ -801,7 +801,7 @@ def upload_part(self, context: RequestContext, request: UploadPartRequest) -> Up bucket_name = request["Bucket"] moto_backend = get_moto_s3_backend(context) moto_bucket = get_bucket_from_moto(moto_backend, bucket=bucket_name) - if not (upload_id := request.get("UploadId")) in moto_bucket.multiparts: + if (upload_id := request.get("UploadId")) not in moto_bucket.multiparts: raise NoSuchUpload( "The specified upload does not exist. The upload ID may be invalid, or the upload may have been aborted or completed.", UploadId=upload_id, @@ -847,7 +847,6 @@ def list_multipart_uploads( context: RequestContext, request: ListMultipartUploadsRequest, ) -> ListMultipartUploadsOutput: - # TODO: implement KeyMarker and UploadIdMarker (using sort) # implement Delimiter and MaxUploads # see https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListMultipartUploads.html @@ -1926,4 +1925,4 @@ def key_is_locked(self): return False - setattr(moto_s3_models.FakeKey, "is_locked", property(key_is_locked)) + moto_s3_models.FakeKey.is_locked = property(key_is_locked) diff --git a/localstack/services/s3/utils.py b/localstack/services/s3/utils.py index aca614504ef70..3d3d4ea35009b 100644 --- a/localstack/services/s3/utils.py +++ b/localstack/services/s3/utils.py @@ -7,7 +7,6 @@ import zlib from typing import IO, Any, Dict, Literal, NamedTuple, Optional, Protocol, Tuple, Type, Union from urllib import parse as urlparser -from zoneinfo import ZoneInfo import moto.s3.models as moto_s3_models import xmltodict @@ -15,6 +14,7 @@ from botocore.utils import InvalidArnException from moto.s3.exceptions import MissingBucket from moto.s3.models import FakeBucket, FakeDeleteMarker, FakeKey +from zoneinfo import ZoneInfo from localstack import config from localstack.aws.api import CommonServiceException, RequestContext diff --git a/localstack/services/s3/v3/models.py b/localstack/services/s3/v3/models.py index 37732ced5466a..de472e4f66f18 100644 --- a/localstack/services/s3/v3/models.py +++ b/localstack/services/s3/v3/models.py @@ -4,6 +4,7 @@ from datetime import datetime from secrets import token_urlsafe from typing import Literal, NamedTuple, Optional, Union + from zoneinfo import ZoneInfo from localstack import config diff --git a/localstack/services/s3/validation.py b/localstack/services/s3/validation.py index 2278033f33e30..7752d8f3887a2 100644 --- a/localstack/services/s3/validation.py +++ b/localstack/services/s3/validation.py @@ -1,7 +1,7 @@ import datetime -from zoneinfo import ZoneInfo from botocore.utils import InvalidArnException +from zoneinfo import ZoneInfo from localstack.aws.api import CommonServiceException from localstack.aws.api.s3 import ( @@ -23,9 +23,9 @@ InventoryId, ObjectCannedACL, Permission, + WebsiteConfiguration, ) from localstack.aws.api.s3 import Type as GranteeType -from localstack.aws.api.s3 import WebsiteConfiguration from localstack.services.s3 import constants as s3_constants from localstack.services.s3.exceptions import InvalidRequest, MalformedACLError, MalformedXML from localstack.services.s3.utils import ( @@ -390,7 +390,6 @@ def validate_cors_configuration(cors_configuration: CORSConfiguration): optional_rule_fields = {"AllowedHeaders", "ExposeHeaders", "MaxAgeSeconds", "ID"} for rule in rules: - if not validate_dict_fields(rule, required_rule_fields, optional_rule_fields): raise MalformedXML() diff --git a/localstack/services/scheduler/resource_providers/aws_scheduler_schedule.py b/localstack/services/scheduler/resource_providers/aws_scheduler_schedule.py index ecb72a54179f8..adfc5316062ab 100644 --- a/localstack/services/scheduler/resource_providers/aws_scheduler_schedule.py +++ b/localstack/services/scheduler/resource_providers/aws_scheduler_schedule.py @@ -124,7 +124,6 @@ class Target(TypedDict): class SchedulerScheduleProvider(ResourceProvider[SchedulerScheduleProperties]): - TYPE = "AWS::Scheduler::Schedule" # Autogenerated. Don't change SCHEMA = util.get_schema_path(Path(__file__)) # Autogenerated. Don't change diff --git a/localstack/services/scheduler/resource_providers/aws_scheduler_schedulegroup.py b/localstack/services/scheduler/resource_providers/aws_scheduler_schedulegroup.py index 653094fd83e82..913ce73707551 100644 --- a/localstack/services/scheduler/resource_providers/aws_scheduler_schedulegroup.py +++ b/localstack/services/scheduler/resource_providers/aws_scheduler_schedulegroup.py @@ -31,7 +31,6 @@ class Tag(TypedDict): class SchedulerScheduleGroupProvider(ResourceProvider[SchedulerScheduleGroupProperties]): - TYPE = "AWS::Scheduler::ScheduleGroup" # Autogenerated. Don't change SCHEMA = util.get_schema_path(Path(__file__)) # Autogenerated. Don't change diff --git a/localstack/services/secretsmanager/provider.py b/localstack/services/secretsmanager/provider.py index f57fb87b7d5aa..19e5c2f7473f3 100644 --- a/localstack/services/secretsmanager/provider.py +++ b/localstack/services/secretsmanager/provider.py @@ -333,7 +333,6 @@ def moto_smb_get_secret_value(fn, self, secret_id, version_id, version_stage): @patch(SecretsManagerBackend.create_secret) def moto_smb_create_secret(fn, self, name, *args, **kwargs): - # Creating a secret with a SecretId equal to one that is scheduled for # deletion should raise an 'InvalidRequestException'. secret: Optional[FakeSecret] = self.secrets.get(name) @@ -723,8 +722,8 @@ def put_resource_policy_response(self): def apply_patches(): secretsmanager_utils.secret_arn = get_arn_binding_for - setattr(SecretsManagerBackend, "get_resource_policy", get_resource_policy_model) - setattr(SecretsManagerResponse, "get_resource_policy", get_resource_policy_response) + SecretsManagerBackend.get_resource_policy = get_resource_policy_model + SecretsManagerResponse.get_resource_policy = get_resource_policy_response if not hasattr(SecretsManagerBackend, "delete_resource_policy"): SecretsManagerBackend.delete_resource_policy = delete_resource_policy_model diff --git a/localstack/services/ses/provider.py b/localstack/services/ses/provider.py index 637e7e676cba7..f32d46e96c2c4 100644 --- a/localstack/services/ses/provider.py +++ b/localstack/services/ses/provider.py @@ -186,7 +186,6 @@ def register_ses_api_resource(): class SesProvider(SesApi, ServiceLifecycleHook): - # # Lifecycle Hooks # diff --git a/localstack/services/sqs/resource_providers/aws_sqs_queue.py b/localstack/services/sqs/resource_providers/aws_sqs_queue.py index 82969ef6ce49d..54d587f20263c 100644 --- a/localstack/services/sqs/resource_providers/aws_sqs_queue.py +++ b/localstack/services/sqs/resource_providers/aws_sqs_queue.py @@ -61,7 +61,6 @@ class Tag(TypedDict): class SQSQueueProvider(ResourceProvider[SQSQueueProperties]): - TYPE = "AWS::SQS::Queue" # Autogenerated. Don't change SCHEMA = util.get_schema_path(Path(__file__)) # Autogenerated. Don't change diff --git a/localstack/services/sqs/resource_providers/aws_sqs_queuepolicy.py b/localstack/services/sqs/resource_providers/aws_sqs_queuepolicy.py index bbba70450369d..227b9bcd45be6 100644 --- a/localstack/services/sqs/resource_providers/aws_sqs_queuepolicy.py +++ b/localstack/services/sqs/resource_providers/aws_sqs_queuepolicy.py @@ -24,7 +24,6 @@ class SQSQueuePolicyProperties(TypedDict): class SQSQueuePolicyProvider(ResourceProvider[SQSQueuePolicyProperties]): - TYPE = "AWS::SQS::QueuePolicy" # Autogenerated. Don't change SCHEMA = util.get_schema_path(Path(__file__)) # Autogenerated. Don't change diff --git a/localstack/services/stepfunctions/asl/component/state/state_choice/comparison/operator/implementations/is_operator.py b/localstack/services/stepfunctions/asl/component/state/state_choice/comparison/operator/implementations/is_operator.py index 3c60bce1299fa..2e51f07337f99 100644 --- a/localstack/services/stepfunctions/asl/component/state/state_choice/comparison/operator/implementations/is_operator.py +++ b/localstack/services/stepfunctions/asl/component/state/state_choice/comparison/operator/implementations/is_operator.py @@ -61,7 +61,7 @@ def impl_name() -> str: @staticmethod def eval(env: Environment, value: Any) -> None: variable = env.stack.pop() - res = not isinstance(variable, NoSuchVariable) is value + res = isinstance(variable, NoSuchVariable) is not value env.stack.append(res) diff --git a/localstack/services/stepfunctions/asl/component/state/state_execution/state_map/iteration/itemprocessor/inline_item_processor_worker.py b/localstack/services/stepfunctions/asl/component/state/state_execution/state_map/iteration/itemprocessor/inline_item_processor_worker.py index 41d7a27550269..0b4d9064363c7 100644 --- a/localstack/services/stepfunctions/asl/component/state/state_execution/state_map/iteration/itemprocessor/inline_item_processor_worker.py +++ b/localstack/services/stepfunctions/asl/component/state/state_execution/state_map/iteration/itemprocessor/inline_item_processor_worker.py @@ -17,7 +17,6 @@ class InlineItemProcessorWorker(IterationWorker): - _item_selector: Final[Optional[ItemSelector]] def __init__( diff --git a/localstack/services/stepfunctions/asl/component/state/state_execution/state_map/iteration/iterator/iterator_worker.py b/localstack/services/stepfunctions/asl/component/state/state_execution/state_map/iteration/iterator/iterator_worker.py index 28bcd5a333e04..249501fdd3816 100644 --- a/localstack/services/stepfunctions/asl/component/state/state_execution/state_map/iteration/iterator/iterator_worker.py +++ b/localstack/services/stepfunctions/asl/component/state/state_execution/state_map/iteration/iterator/iterator_worker.py @@ -15,7 +15,6 @@ class IteratorWorker(IterationWorker): - _parameters: Final[Optional[Parameters]] def __init__( diff --git a/localstack/services/stepfunctions/asl/component/state/state_execution/state_map/max_concurrency.py b/localstack/services/stepfunctions/asl/component/state/state_execution/state_map/max_concurrency.py index 40ddd8d2fac85..bdafe576882de 100644 --- a/localstack/services/stepfunctions/asl/component/state/state_execution/state_map/max_concurrency.py +++ b/localstack/services/stepfunctions/asl/component/state/state_execution/state_map/max_concurrency.py @@ -4,7 +4,6 @@ class MaxConcurrency(Component): - DEFAULT: Final[int] = 0 # No limit. def __init__(self, num: int = DEFAULT): diff --git a/localstack/services/stepfunctions/asl/component/state/state_execution/state_task/service/resource.py b/localstack/services/stepfunctions/asl/component/state/state_execution/state_task/service/resource.py index 3405562439913..ce1d4288d5a5c 100644 --- a/localstack/services/stepfunctions/asl/component/state/state_execution/state_task/service/resource.py +++ b/localstack/services/stepfunctions/asl/component/state/state_execution/state_task/service/resource.py @@ -126,7 +126,6 @@ def __init__(self, resource_arn: ResourceARN): class LambdaResource(Resource): - function_name: Final[str] def __init__(self, resource_arn: ResourceARN): diff --git a/localstack/services/stepfunctions/asl/component/state/state_execution/state_task/service/state_task_service_api_gateway.py b/localstack/services/stepfunctions/asl/component/state/state_execution/state_task/service/state_task_service_api_gateway.py index 5eae9960a2268..abe2e6be1eb57 100644 --- a/localstack/services/stepfunctions/asl/component/state/state_execution/state_task/service/state_task_service_api_gateway.py +++ b/localstack/services/stepfunctions/asl/component/state/state_execution/state_task/service/state_task_service_api_gateway.py @@ -99,7 +99,6 @@ def __init__(self, parameters: TaskParameters, response: Response): class StateTaskServiceApiGateway(StateTaskServiceCallback): - _SUPPORTED_API_PARAM_BINDINGS: Final[dict[str, set[str]]] = { SupportedApiCalls.invoke: set(TaskParameters.__required_keys__) # noqa } diff --git a/localstack/services/stepfunctions/asl/component/state/state_execution/state_task/service/state_task_service_sfn.py b/localstack/services/stepfunctions/asl/component/state/state_execution/state_task/service/state_task_service_sfn.py index 51e7a91d0dc28..b3c1d742b1f06 100644 --- a/localstack/services/stepfunctions/asl/component/state/state_execution/state_task/service/state_task_service_sfn.py +++ b/localstack/services/stepfunctions/asl/component/state/state_execution/state_task/service/state_task_service_sfn.py @@ -142,7 +142,6 @@ def _normalised_parameters_bindings(self, raw_parameters: dict[str, str]) -> dic if self.resource.api_action.lower() == "startexecution": optional_input = normalised_parameters.get("input") if not isinstance(optional_input, str): - # AWS Sfn's documentation states: # If you don't include any JSON input data, you still must include the two braces. if optional_input is None: diff --git a/localstack/services/stepfunctions/asl/eval/program_state.py b/localstack/services/stepfunctions/asl/eval/program_state.py index 197399a3c4082..54e326a3cc4bc 100644 --- a/localstack/services/stepfunctions/asl/eval/program_state.py +++ b/localstack/services/stepfunctions/asl/eval/program_state.py @@ -45,7 +45,6 @@ def _validate_next_state_name(next_state_name: Optional[str]) -> bool: class ProgramError(ProgramState): - error: Final[Optional[ExecutionFailedEventDetails]] def __init__(self, error: Optional[ExecutionFailedEventDetails]): diff --git a/localstack/services/stepfunctions/packages.py b/localstack/services/stepfunctions/packages.py index e3474ee2873f0..81f0699b90696 100644 --- a/localstack/services/stepfunctions/packages.py +++ b/localstack/services/stepfunctions/packages.py @@ -87,7 +87,6 @@ def _install(self, target: InstallTarget) -> None: install_dir = self._get_install_dir(target) install_destination = self._get_install_marker_path(install_dir) if not os.path.exists(install_destination): - # Download layer that contains the necessary jars def download_stepfunctions_jar(image, image_digest, target_path): registry_base = "https://registry-1.docker.io" diff --git a/localstack/state/pickle.py b/localstack/state/pickle.py index 3f4a3587bb613..a8a139340261a 100644 --- a/localstack/state/pickle.py +++ b/localstack/state/pickle.py @@ -51,7 +51,6 @@ def register(cls: Type = None, subclasses: bool = False): """ def _wrapper(fn: Any | Callable[[PythonPickler, Any], None]): - if inspect.isclass(fn) and issubclass(fn, ObjectStateReducer): if cls is not None: raise ValueError("superfluous cls attribute for registering classes") diff --git a/localstack/testing/aws/asf_utils.py b/localstack/testing/aws/asf_utils.py index f555b317ecb13..c1d8c2aad1533 100644 --- a/localstack/testing/aws/asf_utils.py +++ b/localstack/testing/aws/asf_utils.py @@ -119,7 +119,7 @@ def check_provider_signature(sub_class: type, base_class: type, method_name: str try: base_function = getattr(base_class, method_name) # unwrap from the handler decorator - base_function = getattr(base_function, "__wrapped__") + base_function = base_function.__wrapped__ sub_spec = inspect.getfullargspec(sub_function) base_spec = inspect.getfullargspec(base_function) diff --git a/localstack/testing/pytest/cloudtrail_tracking.py b/localstack/testing/pytest/cloudtrail_tracking.py index 98ee25639a540..bb4a127249b5e 100644 --- a/localstack/testing/pytest/cloudtrail_tracking.py +++ b/localstack/testing/pytest/cloudtrail_tracking.py @@ -34,7 +34,9 @@ def cfn_store_events_role_arn(request, create_iam_role_with_policy, aws_client): # check that the user has run the bootstrap stack try: - step_function_arn = aws_client.ssm.get_parameter(Name="cloudtrail-stepfunction-arn",)[ + step_function_arn = aws_client.ssm.get_parameter( + Name="cloudtrail-stepfunction-arn", + )[ "Parameter" ]["Value"] except aws_client.ssm.exceptions.ParameterNotFound: diff --git a/localstack/testing/pytest/find_orphaned_snapshots.py b/localstack/testing/pytest/find_orphaned_snapshots.py index 98322d604ccef..349f70edfc1cc 100644 --- a/localstack/testing/pytest/find_orphaned_snapshots.py +++ b/localstack/testing/pytest/find_orphaned_snapshots.py @@ -21,7 +21,6 @@ def pytest_addoption(parser: Parser, pluginmanager: PytestPluginManager): @pytest.hookimpl def pytest_collection_modifyitems(session: Session, config: Config, items: list[Item]): - # for each file load the corresponding snapshot file ff = config.getoption("--filter-fixtures") diff --git a/localstack/testing/pytest/fixtures.py b/localstack/testing/pytest/fixtures.py index 10668cb734d08..695d0308075c7 100644 --- a/localstack/testing/pytest/fixtures.py +++ b/localstack/testing/pytest/fixtures.py @@ -223,6 +223,7 @@ def s3_empty_bucket(aws_client): """ Returns a factory that given a bucket name, deletes all objects and deletes all object versions """ + # Boto resource would make this a straightforward task, but our internal client does not support Boto resource # FIXME: this won't work when bucket has more than 1000 objects def factory(bucket_name: str): @@ -691,7 +692,6 @@ def _create_key(region_name: str = None, **kwargs): for region_name, key_id in key_ids: try: - # shortest amount of time you can schedule the deletion aws_client_factory(region_name=region_name).kms.schedule_key_deletion( KeyId=key_id, PendingWindowInDays=7 diff --git a/localstack/testing/pytest/marker_report.py b/localstack/testing/pytest/marker_report.py index 82acd8a18b9db..03b8bc28f87d2 100644 --- a/localstack/testing/pytest/marker_report.py +++ b/localstack/testing/pytest/marker_report.py @@ -117,7 +117,6 @@ def pytest_collection_modifyitems( json.dump(dataclasses.asdict(report), fd, indent=2, sort_keys=True) if config.option.marker_report_tinybird_upload: - project_name = os.environ.get("MARKER_REPORT_PROJECT_NAME", "localstack") datasource_name = "pytest_markers__v0" token = os.environ.get("MARKER_REPORT_TINYBIRD_TOKEN") diff --git a/localstack/testing/pytest/snapshot.py b/localstack/testing/pytest/snapshot.py index eecd4bb6022d8..96f4675e4c2dd 100644 --- a/localstack/testing/pytest/snapshot.py +++ b/localstack/testing/pytest/snapshot.py @@ -9,7 +9,7 @@ from _pytest.nodes import Item from _pytest.reports import TestReport from _pytest.runner import CallInfo -from pluggy.callers import _Result +from pluggy import Result from localstack.testing.snapshots import SnapshotAssertionError, SnapshotSession from localstack.testing.snapshots.report import render_report @@ -37,7 +37,7 @@ def pytest_addoption(parser: Parser, pluginmanager: PytestPluginManager): def pytest_runtest_makereport(item: Item, call: CallInfo[None]) -> Optional[TestReport]: use_legacy_report = os.environ.get("SNAPSHOT_LEGACY_REPORT", "0") == "1" - result: _Result = yield + result: Result = yield report: TestReport = result.get_result() if call.excinfo is not None and isinstance(call.excinfo.value, SnapshotAssertionError): @@ -69,9 +69,7 @@ def pytest_runtest_call(item: Item) -> None: paths = [] if not is_aws(): # only skip for local tests - for m in item.iter_markers(name="skip_snapshot_verify"): - skip_paths = m.kwargs.get("paths", []) skip_condition = m.kwargs.get("condition") diff --git a/localstack/testing/snapshots/report.py b/localstack/testing/snapshots/report.py index 3aa101f8b1f6e..39f80d1e2a35a 100644 --- a/localstack/testing/snapshots/report.py +++ b/localstack/testing/snapshots/report.py @@ -44,7 +44,7 @@ def __lt__(self, other): raise ValueError("Incompatible types") parts = zip(self.split("/"), other.split("/")) - for (sa, sb) in parts: + for sa, sb in parts: if sa < sb: return True @@ -127,7 +127,7 @@ def _render_path_part(part): printstr = f">> match key: {result.key}\n" - for (a, b) in sorted(lines, key=lambda x: PatchPath(x[0])): + for a, b in sorted(lines, key=lambda x: PatchPath(x[0])): printstr += f"\t{b}\n" # you can add more entries to the lists to combine effects (e.g. red & underlined) diff --git a/localstack/utils/analytics/client.py b/localstack/utils/analytics/client.py index d4a379244ecd1..7467204ded9d3 100644 --- a/localstack/utils/analytics/client.py +++ b/localstack/utils/analytics/client.py @@ -17,7 +17,6 @@ class SessionResponse: - response: Dict[str, Any] status: int diff --git a/localstack/utils/aws/aws_models.py b/localstack/utils/aws/aws_models.py index 5a7af086f9caa..d77a553a328fd 100644 --- a/localstack/utils/aws/aws_models.py +++ b/localstack/utils/aws/aws_models.py @@ -181,7 +181,6 @@ def __init__(self, arn, id, signing_profile_version_arns): class LambdaFunction(Component): - QUALIFIER_LATEST: str = "$LATEST" def __init__(self, arn): diff --git a/localstack/utils/server/http2_server.py b/localstack/utils/server/http2_server.py index f8a214735c60c..d910bab8c1b83 100644 --- a/localstack/utils/server/http2_server.py +++ b/localstack/utils/server/http2_server.py @@ -13,10 +13,9 @@ from hypercorn.config import Config from hypercorn.events import Closed from hypercorn.protocol import http_stream -from quart import Quart +from quart import Quart, make_response, request from quart import app as quart_app from quart import asgi as quart_asgi -from quart import make_response, request from quart import utils as quart_utils from quart.app import _cancel_all_tasks diff --git a/localstack/utils/testutil.py b/localstack/utils/testutil.py index b83587ecafd9b..c48ab1c5e7f45 100644 --- a/localstack/utils/testutil.py +++ b/localstack/utils/testutil.py @@ -196,7 +196,8 @@ def create_lambda_function( **kwargs, ): """Utility method to create a new function via the Lambda API - CAVEAT: Does NOT wait until the function is ready/active. The fixture create_lambda_function waits until ready.""" + CAVEAT: Does NOT wait until the function is ready/active. The fixture create_lambda_function waits until ready. + """ if envvars is None: envvars = {} if tags is None: diff --git a/pyproject.toml b/pyproject.toml index daa490d8ea03d..22739e7683675 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,17 +8,60 @@ line_length = 100 include = '(localstack/.*\.py$|tests/.*\.py$)' extend_exclude = '(localstack/infra|localstack/node_modules|.filesystem|localstack/services/stepfunctions/asl/antlr/runtime)' -[tool.isort] -profile = 'black' -extend_skip = ['localstack/infra/', 'localstack/node_modules', 'bin', '.filesystem', 'localstack/services/stepfunctions/asl/antlr/runtime'] -line_length = 100 - -# call using pflake8 -[tool.flake8] -max-line-length = 110 -ignore = 'E203,E266,E501,W503,F403' -select = 'B,C,E,F,I,W,T4,B9' -exclude = 'node_modules,.venv*,venv*,dist,build,target,*.egg-info,fixes,localstack/infra,localstack/node_modules,.filesystem,.git,localstack/services/stepfunctions/asl/antlr/runtime' +[tool.ruff] +# Always generate Python 3.8-compatible code. +target-version = "py38" +line-length = 110 +ignore = [ + "B005", # TODO Using `.strip()` with multi-character strings is misleading + "B006", # TODO Do not use mutable data structures for argument defaults + "B007", # TODO Loop control variable x not used within loop body + "B008", # TODO Do not perform function call `Queue` in argument defaults + "B011", # TODO Do not `assert False` (`python -O` removes these calls), raise `AssertionError()` + "B016", # TODO Cannot raise a literal. Did you intend to return it or raise an Exception? + "B017", # TODO `pytest.raises(Exception)` should be considered evil + "B018", # TODO Found useless expression. Either assign it to a variable or remove it. + "B019", # TODO Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks + "B020", # TODO Loop control variable `invalid_values` overrides iterable it iterates + "B022", # TODO No arguments passed to `contextlib.suppress`. No exceptions will be suppressed and therefore this context manager is redundant + "B023", # TODO Function definition does not bind loop variable `server` + "B024", # TODO x is an abstract base class, but it has no abstract methods + "B026", # TODO Star-arg unpacking after a keyword argument is strongly discouraged + "B027", # TODO `Server.do_shutdown` is an empty method in an abstract base class, but has no abstract decorator + "B028", # TODO No explicit `stacklevel` keyword argument found + "B034", # TODO `re.sub` should pass `count` and `flags` as keyword arguments to avoid confusion due to unintuitive argument positions + "B904", # TODO Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling + "C401", # TODO Unnecessary generator (rewrite as a `set` comprehension) + "C402", # TODO Unnecessary generator (rewrite as a `dict` comprehension) + "C403", # TODO Unnecessary `list` comprehension (rewrite as a `set` comprehension) + "C405", # TODO Unnecessary `list` literal (rewrite as a `set` literal) + "C408", # TODO Unnecessary `list` call (rewrite as a literal) + "C411", # TODO Unnecessary `list` call (remove the outer call to `list()`) + "C414", # TODO Unnecessary `list` call within `sorted()` + "C416", # TODO Unnecessary `set` comprehension + "C417", # TODO Replace `map` with a generator expression + "C418", # TODO Unnecessary `dict` literal passed to `dict()` (remove the outer call to `dict()`) + "C419", # TODO Unnecessary list comprehension. + "C901", # TODO function is too complex + "E402", # TODO Module level import not at top of file + "E501", # E501 Line too long - handled by black, see https://docs.astral.sh/ruff/faq/#is-ruff-compatible-with-black + "E721", # TODO Do not compare types, use `isinstance()` + "F403", # TODO `from localstack.services.cloudformation.models import *` used; unable to detect undefined names + "T201", # TODO `print` found + "T203", # TODO `pprint` found +] +select = ["B", "C", "E", "F", "I", "W", "T", "B9"] +exclude = [ + ".venv*", + "venv*", + "dist", + "build", + "target", + "*.egg-info", + ".filesystem", + ".git", + "localstack/services/stepfunctions/asl/antlr/runtime" + ] [tool.coverage.run] relative_files = true diff --git a/setup.cfg b/setup.cfg index cf5639f7f0234..a8bcd2e43c829 100644 --- a/setup.cfg +++ b/setup.cfg @@ -71,7 +71,7 @@ runtime = cbor2>=5.2.0 crontab>=0.22.6 dnspython>=1.16.0 - docker==6.0.1 + docker>=6.1.1 flask>=3.0.0 flask-cors>=4.0.0 hypercorn>=0.14.4 @@ -83,12 +83,14 @@ runtime = jsonschema<=4.19.0 localstack-client>=2.0 moto-ext[all]==4.2.6.post1 - opensearch-py==2.1.1 + opensearch-py>=2.3.2 pymongo>=4.2.0 pyopenssl>=23.0.0 Quart>=0.19.2 readerwriterlock>=1.0.7 requests-aws4auth>=1.0 + # explicitly set urllib3 to force its usage / ensure compatibility + urllib3>=2.0.7 Werkzeug>=3.0.0 xmltodict>=0.13.0 @@ -100,33 +102,26 @@ full = test = # coverage version should be synced with bin/Dockerfile.base coverage[toml]>=5.5 - deepdiff==6.3.1 + deepdiff>=6.4.1 jsonpath-ng>=1.5.3 - pytest==6.2.4 + pluggy>=1.3.0 + pytest==7.4.2 pytest-split>=0.8.0 pytest-httpserver>=1.0.1 - pytest-rerunfailures==10.0 + pytest-rerunfailures==12.0 pytest-tinybird>=0.2.0 aws-cdk-lib>=2.88.0 # for developing localstack dev = - autoflake - black==22.3.0 + black==23.10.0 coveralls>=3.3.1 Cython - flake8-black>=0.3.6 - flake8-isort>=6.0.0 - flake8-quotes>=3.3.2 - flake8>=6.0.0 - isort==5.12.0 networkx>=2.8.4 pandoc - pre-commit==2.13.0 + pre-commit==3.5.0 pypandoc - # enables flake8 configuration through pyproject.toml - # TODO remove pin once codebase is upgraded to flake8 6.1.0 - pyproject-flake8>=6.0.0.post1,<6.1.0 + ruff==0.1.0 rstr>=3.2.0 # not strictly necessary for development, but provides type hint support for a better developer experience diff --git a/tests/aws/services/apigateway/test_apigateway_basic.py b/tests/aws/services/apigateway/test_apigateway_basic.py index 128769223c208..8f4aaaf609bb4 100644 --- a/tests/aws/services/apigateway/test_apigateway_basic.py +++ b/tests/aws/services/apigateway/test_apigateway_basic.py @@ -124,7 +124,6 @@ def integration_lambda(create_lambda_function): class TestAPIGateway: - # endpoint paths API_PATH_LAMBDA_PROXY_BACKEND = "/lambda/foo1" API_PATH_LAMBDA_PROXY_BACKEND_WITH_PATH_PARAM = "/lambda/{test_param1}" @@ -691,7 +690,6 @@ def test_api_gateway_handle_domain_name(self, aws_client): apigw_client.delete_domain_name(domainName=domain_name) def _test_api_gateway_lambda_proxy_integration_any_method(self, fn_name, path): - # create API Gateway and connect it to the Lambda proxy backend lambda_uri = arns.lambda_function_arn(fn_name, TEST_AWS_ACCOUNT_ID, TEST_AWS_REGION_NAME) target_uri = arns.apigateway_invocations_arn(lambda_uri, TEST_AWS_REGION_NAME) @@ -723,7 +721,6 @@ def _test_api_gateway_lambda_proxy_integration_any_method(self, fn_name, path): def test_apigateway_with_custom_authorization_method( self, create_rest_apigw, aws_client, integration_lambda ): - # create Lambda function lambda_uri = arns.lambda_function_arn( integration_lambda, TEST_AWS_ACCOUNT_ID, TEST_AWS_REGION_NAME @@ -1006,7 +1003,6 @@ def test_apigateway_with_step_function_integration( aws_client, snapshot, ): - snapshot.add_transformer(snapshot.transform.key_value("executionArn", "executionArn")) snapshot.add_transformer( snapshot.transform.jsonpath( @@ -1287,7 +1283,6 @@ def test_api_gateway_update_resource_path_part(self, create_rest_apigw, aws_clie def test_response_headers_invocation_with_apigw( self, aws_client, create_rest_apigw, create_lambda_function, create_role_with_policy ): - _, role_arn = create_role_with_policy( "Allow", "lambda:InvokeFunction", json.dumps(APIGATEWAY_ASSUME_ROLE_POLICY), "*" ) @@ -1979,7 +1974,6 @@ def test_api_gateway_kinesis_integration( def test_api_gateway_sqs_integration_with_event_source( self, aws_client, integration_lambda, sqs_queue ): - # create API Gateway and connect it to the target queue result = connect_api_gateway_to_sqs( "test_gateway4", diff --git a/tests/aws/services/apigateway/test_apigateway_import.py b/tests/aws/services/apigateway/test_apigateway_import.py index 5df0ec7e18675..609c5a862afd8 100644 --- a/tests/aws/services/apigateway/test_apigateway_import.py +++ b/tests/aws/services/apigateway/test_apigateway_import.py @@ -729,7 +729,6 @@ def test_import_with_circular_models_and_request_validation( @markers.aws.validated def test_import_with_stage_variables(self, import_apigw, aws_client, echo_http_server_post): - spec_file = load_file(OAS_30_STAGE_VARIABLES) import_resp, root_id = import_apigw(body=spec_file, failOnWarnings=True) rest_api_id = import_resp["id"] diff --git a/tests/aws/services/cloudformation/api/test_extensions_modules.py b/tests/aws/services/cloudformation/api/test_extensions_modules.py index 21d0c16be057b..755f2d66accd7 100644 --- a/tests/aws/services/cloudformation/api/test_extensions_modules.py +++ b/tests/aws/services/cloudformation/api/test_extensions_modules.py @@ -10,7 +10,6 @@ class TestExtensionsModules: @pytest.mark.skip(reason="feature not supported") @markers.aws.validated def test_module_usage(self, deploy_cfn_template, register_extension, snapshot, aws_client): - artifact_path = os.path.join( os.path.dirname(__file__), "../artifacts/extensions/modules/localstack-testing-testmodule-module.zip", diff --git a/tests/aws/services/cloudformation/api/test_extensions_resourcetypes.py b/tests/aws/services/cloudformation/api/test_extensions_resourcetypes.py index efeb05496b497..5f9bb51952efe 100644 --- a/tests/aws/services/cloudformation/api/test_extensions_resourcetypes.py +++ b/tests/aws/services/cloudformation/api/test_extensions_resourcetypes.py @@ -12,7 +12,6 @@ class TestExtensionsResourceTypes: def test_deploy_resource_type( self, deploy_cfn_template, register_extension, snapshot, aws_client ): - artifact_path = os.path.join( os.path.dirname(__file__), "../artifacts/extensions/resourcetypes/localstack-testing-deployableresource.zip", diff --git a/tests/aws/services/cloudformation/api/test_stack_policies.py b/tests/aws/services/cloudformation/api/test_stack_policies.py index 50c7c351f7293..2a33fc462c06f 100644 --- a/tests/aws/services/cloudformation/api/test_stack_policies.py +++ b/tests/aws/services/cloudformation/api/test_stack_policies.py @@ -167,7 +167,6 @@ def test_set_empty_policy_with_url( def test_set_policy_both_policy_and_url( self, deploy_cfn_template, s3_create_bucket, snapshot, aws_client ): - """Test to validate the API behavior when trying to set a Stack policy using both the body and the URL""" stack = deploy_cfn_template( diff --git a/tests/aws/services/cloudformation/api/test_update_stack.py b/tests/aws/services/cloudformation/api/test_update_stack.py index e813bb7e8324a..495fdba5e9100 100644 --- a/tests/aws/services/cloudformation/api/test_update_stack.py +++ b/tests/aws/services/cloudformation/api/test_update_stack.py @@ -360,7 +360,6 @@ def test_update_with_invalid_rollback_configuration_errors( @markers.aws.validated @pytest.mark.skip(reason="The update value is not being applied") def test_update_with_rollback_configuration(deploy_cfn_template, aws_client): - aws_client.cloudwatch.put_metric_alarm( AlarmName="HighResourceUsage", ComparisonOperator="GreaterThanThreshold", diff --git a/tests/aws/services/cloudformation/resource_providers/iam/aws_iam_user/test_parity.py b/tests/aws/services/cloudformation/resource_providers/iam/aws_iam_user/test_parity.py index e07e0a0303834..c3e6024d1cdc5 100644 --- a/tests/aws/services/cloudformation/resource_providers/iam/aws_iam_user/test_parity.py +++ b/tests/aws/services/cloudformation/resource_providers/iam/aws_iam_user/test_parity.py @@ -1,4 +1,4 @@ -# flake8: noqa +# ruff: noqa # LocalStack Resource Provider Scaffolding v1 import os diff --git a/tests/aws/services/cloudformation/resource_providers/iam/test_iam.py b/tests/aws/services/cloudformation/resource_providers/iam/test_iam.py index 629c90326940e..b99b2a5ea66fb 100644 --- a/tests/aws/services/cloudformation/resource_providers/iam/test_iam.py +++ b/tests/aws/services/cloudformation/resource_providers/iam/test_iam.py @@ -147,7 +147,6 @@ def test_iam_user_access_key(deploy_cfn_template, snapshot, aws_client): @markers.aws.validated def test_update_inline_policy(deploy_cfn_template, snapshot, aws_client): - snapshot.add_transformer(snapshot.transform.iam_api()) snapshot.add_transformer(snapshot.transform.key_value("PolicyName", "policy-name")) snapshot.add_transformer(snapshot.transform.key_value("RoleName", "role-name")) diff --git a/tests/aws/services/cloudformation/resources/test_ec2.py b/tests/aws/services/cloudformation/resources/test_ec2.py index a60c575080648..bf108f0adf83c 100644 --- a/tests/aws/services/cloudformation/resources/test_ec2.py +++ b/tests/aws/services/cloudformation/resources/test_ec2.py @@ -30,7 +30,6 @@ def test_vpc_creates_default_sg(deploy_cfn_template, aws_client): @markers.aws.validated def test_cfn_with_multiple_route_tables(deploy_cfn_template, aws_client): - result = deploy_cfn_template( template_path=os.path.join(THIS_FOLDER, "../../../templates/template36.yaml"), max_wait=180, diff --git a/tests/aws/services/cloudformation/resources/test_sam.py b/tests/aws/services/cloudformation/resources/test_sam.py index abfa80299e226..a571deaf83384 100644 --- a/tests/aws/services/cloudformation/resources/test_sam.py +++ b/tests/aws/services/cloudformation/resources/test_sam.py @@ -24,7 +24,6 @@ def test_sam_policies(deploy_cfn_template, snapshot, aws_client): @markers.aws.unknown def test_sam_template(deploy_cfn_template, aws_client): - # deploy template func_name = f"test-{short_uid()}" deploy_cfn_template( diff --git a/tests/aws/services/cloudformation/resources/test_sns.py b/tests/aws/services/cloudformation/resources/test_sns.py index 2fc7695d0e1d8..2fd327615b992 100644 --- a/tests/aws/services/cloudformation/resources/test_sns.py +++ b/tests/aws/services/cloudformation/resources/test_sns.py @@ -66,7 +66,6 @@ def test_sns_subscription(deploy_cfn_template, aws_client): @markers.aws.validated def test_deploy_stack_with_sns_topic(deploy_cfn_template, aws_client): - stack = deploy_cfn_template( template_path=os.path.join( os.path.dirname(__file__), "../../../templates/deploy_template_2.yaml" diff --git a/tests/aws/services/cloudformation/resources/test_stepfunctions.py b/tests/aws/services/cloudformation/resources/test_stepfunctions.py index 622a8b381e5c4..d4acba18f5b1e 100644 --- a/tests/aws/services/cloudformation/resources/test_stepfunctions.py +++ b/tests/aws/services/cloudformation/resources/test_stepfunctions.py @@ -257,7 +257,6 @@ def test_retry_and_catch(deploy_cfn_template, aws_client): @markers.aws.validated def test_cfn_statemachine_with_dependencies(deploy_cfn_template, aws_client): - stack = deploy_cfn_template( template_path=os.path.join( os.path.dirname(__file__), "../../../templates/statemachine_test.json" diff --git a/tests/aws/services/cloudformation/test_template_engine.py b/tests/aws/services/cloudformation/test_template_engine.py index 06d6db6106604..9107308397388 100644 --- a/tests/aws/services/cloudformation/test_template_engine.py +++ b/tests/aws/services/cloudformation/test_template_engine.py @@ -75,7 +75,6 @@ def create_macro( macro_name, function_path, deploy_cfn_template, create_lambda_function, lambda_client ): - macro_function_path = function_path func_name = f"test_lambda_{short_uid()}" diff --git a/tests/aws/services/cloudwatch/test_cloudwatch.py b/tests/aws/services/cloudwatch/test_cloudwatch.py index b8897c84ab5d7..258eab8882d73 100644 --- a/tests/aws/services/cloudwatch/test_cloudwatch.py +++ b/tests/aws/services/cloudwatch/test_cloudwatch.py @@ -217,7 +217,6 @@ def test_raw_metric_data(self, aws_client): @markers.aws.validated def test_multiple_dimensions(self, aws_client): - namespaces = [ f"ns1-{short_uid()}", f"ns2-{short_uid()}", diff --git a/tests/aws/services/firehose/test_firehose.py b/tests/aws/services/firehose/test_firehose.py index c32512739602f..799d678493144 100644 --- a/tests/aws/services/firehose/test_firehose.py +++ b/tests/aws/services/firehose/test_firehose.py @@ -348,7 +348,6 @@ def assert_s3_contents(): def test_delivery_stream_with_kinesis_as_source( self, s3_bucket, kinesis_create_stream, cleanups, aws_client ): - bucket_arn = arns.s3_bucket_arn(s3_bucket) stream_name = f"test-stream-{short_uid()}" log_group_name = f"group{short_uid()}" diff --git a/tests/aws/services/kms/test_kms.py b/tests/aws/services/kms/test_kms.py index 025d84c3d0770..abb31fc2a3f3d 100644 --- a/tests/aws/services/kms/test_kms.py +++ b/tests/aws/services/kms/test_kms.py @@ -69,7 +69,6 @@ def kms_api_snapshot_transformer(self, snapshot): @markers.aws.validated def test_create_alias(self, kms_create_alias, kms_create_key, snapshot): - alias_name = f"{short_uid()}" alias_key_id = kms_create_key()["KeyId"] with pytest.raises(Exception) as e: @@ -236,7 +235,6 @@ def test_disable_and_enable_key(self, kms_create_key, aws_client): # Not sure how useful this test is, as it just fails during key validation, before grant-specific logic kicks in. @markers.aws.validated def test_create_grant_with_invalid_key(self, user_arn, aws_client): - with pytest.raises(ClientError) as e: aws_client.kms.create_grant( KeyId="invalid", diff --git a/tests/aws/services/lambda_/functions/lambda_introspect.py b/tests/aws/services/lambda_/functions/lambda_introspect.py index a0a3bf9758efc..dd77591474a9c 100644 --- a/tests/aws/services/lambda_/functions/lambda_introspect.py +++ b/tests/aws/services/lambda_/functions/lambda_introspect.py @@ -9,7 +9,6 @@ def handler(event, context): - if event.get("wait"): time.sleep(event["wait"]) diff --git a/tests/aws/services/lambda_/test_lambda.py b/tests/aws/services/lambda_/test_lambda.py index 8879d0f47d80d..d2d8708af4718 100644 --- a/tests/aws/services/lambda_/test_lambda.py +++ b/tests/aws/services/lambda_/test_lambda.py @@ -966,7 +966,6 @@ def test_lambda_url_invocation_exception(self, create_lambda_function, snapshot, class TestLambdaPermissions: @markers.aws.validated def test_lambda_permission_url_invocation(self, create_lambda_function, snapshot, aws_client): - function_name = f"test-function-{short_uid()}" create_lambda_function( func_name=function_name, diff --git a/tests/aws/services/lambda_/test_lambda_api.py b/tests/aws/services/lambda_/test_lambda_api.py index 96a316d930951..11fb69d3965e5 100644 --- a/tests/aws/services/lambda_/test_lambda_api.py +++ b/tests/aws/services/lambda_/test_lambda_api.py @@ -1794,7 +1794,6 @@ def test_create_tag_on_fn_create(self, create_lambda_function, snapshot, aws_cli @markers.aws.validated def test_tag_lifecycle(self, create_lambda_function, snapshot, fn_arn, aws_client): - # 1. add tag tag_single_response = aws_client.lambda_.tag_resource(Resource=fn_arn, Tags={"A": "tag-a"}) snapshot.match("tag_single_response", tag_single_response) @@ -2498,7 +2497,6 @@ def test_function_concurrency(self, create_lambda_function, snapshot, aws_client @pytest.mark.skipif(condition=is_old_provider(), reason="not supported") class TestLambdaProvisionedConcurrency: - # TODO: test ARN # TODO: test shorthand ARN @markers.aws.validated @@ -4124,7 +4122,6 @@ class TestLambdaEventSourceMappings: @pytest.mark.skipif(condition=is_old_provider(), reason="new provider only") @markers.aws.validated def test_event_source_mapping_exceptions(self, snapshot, aws_client): - with pytest.raises(aws_client.lambda_.exceptions.ResourceNotFoundException) as e: aws_client.lambda_.get_event_source_mapping(UUID=long_uid()) snapshot.match("get_unknown_uuid", e.value.response) diff --git a/tests/aws/services/lambda_/test_lambda_integration_dynamodbstreams.py b/tests/aws/services/lambda_/test_lambda_integration_dynamodbstreams.py index 7f53b6ce0dd10..bca9f5ab5c832 100644 --- a/tests/aws/services/lambda_/test_lambda_integration_dynamodbstreams.py +++ b/tests/aws/services/lambda_/test_lambda_integration_dynamodbstreams.py @@ -98,7 +98,6 @@ def test_dynamodb_event_source_mapping( snapshot, aws_client, ): - function_name = f"lambda_func-{short_uid()}" role = f"test-lambda-role-{short_uid()}" policy_name = f"test-lambda-policy-{short_uid()}" @@ -170,7 +169,6 @@ def test_disabled_dynamodb_event_source_mapping( snapshot, aws_client, ): - function_name = f"lambda_func-{short_uid()}" ddb_table = f"ddb_table-{short_uid()}" items = [ @@ -432,7 +430,6 @@ def test_dynamodb_event_filter( snapshot, aws_client, ): - function_name = f"lambda_func-{short_uid()}" table_name = f"test-table-{short_uid()}" max_retries = 50 @@ -531,7 +528,6 @@ def test_dynamodb_invalid_event_filter( snapshot, aws_client, ): - function_name = f"lambda_func-{short_uid()}" table_name = f"test-table-{short_uid()}" diff --git a/tests/aws/services/lambda_/test_lambda_integration_kinesis.py b/tests/aws/services/lambda_/test_lambda_integration_kinesis.py index 0c314fdf2f88d..5297b76efe6e0 100644 --- a/tests/aws/services/lambda_/test_lambda_integration_kinesis.py +++ b/tests/aws/services/lambda_/test_lambda_integration_kinesis.py @@ -206,7 +206,6 @@ def test_kinesis_event_source_trim_horizon( snapshot, aws_client, ): - function_name = f"lambda_func-{short_uid()}" stream_name = f"test-foobar-{short_uid()}" num_records_per_batch = 10 diff --git a/tests/aws/services/lambda_/test_lambda_whitebox.py b/tests/aws/services/lambda_/test_lambda_whitebox.py index 7d68fa79773a1..8ffbcc9b3f0c6 100644 --- a/tests/aws/services/lambda_/test_lambda_whitebox.py +++ b/tests/aws/services/lambda_/test_lambda_whitebox.py @@ -99,7 +99,6 @@ def _handler(_request: Request): # using pytest HTTPServer instead of the fixture because this test is still based on unittest with HTTPServer() as server: - server.expect_request("").respond_with_handler(_handler) http_endpoint = server.url_for("/") diff --git a/tests/aws/services/logs/test_logs.py b/tests/aws/services/logs/test_logs.py index 0fe667b012115..a69ef5848d128 100644 --- a/tests/aws/services/logs/test_logs.py +++ b/tests/aws/services/logs/test_logs.py @@ -438,7 +438,6 @@ def list_objects(): def test_put_subscription_filter_kinesis( self, logs_log_group, logs_log_stream, create_iam_role_with_policy, aws_client ): - kinesis_name = f"test-kinesis-{short_uid()}" filter_name = "Destination" aws_client.kinesis.create_stream(StreamName=kinesis_name, ShardCount=1) diff --git a/tests/aws/services/opensearch/test_opensearch.py b/tests/aws/services/opensearch/test_opensearch.py index 7723ac13490a8..022fcaba0488c 100644 --- a/tests/aws/services/opensearch/test_opensearch.py +++ b/tests/aws/services/opensearch/test_opensearch.py @@ -28,9 +28,8 @@ ) from localstack.services.opensearch.packages import opensearch_package from localstack.testing.pytest import markers -from localstack.utils.common import call_safe, poll_condition, retry +from localstack.utils.common import call_safe, poll_condition, retry, short_uid, start_worker_thread from localstack.utils.common import safe_requests as requests -from localstack.utils.common import short_uid, start_worker_thread from localstack.utils.strings import to_str LOG = logging.getLogger(__name__) diff --git a/tests/aws/services/redshift/test_redshift.py b/tests/aws/services/redshift/test_redshift.py index 5619d3f328fbc..ca2afc1319598 100644 --- a/tests/aws/services/redshift/test_redshift.py +++ b/tests/aws/services/redshift/test_redshift.py @@ -7,7 +7,6 @@ class TestRedshift: @markers.aws.unknown def test_create_clusters(self, aws_client): - # create cluster_id = f"c={short_uid()}" response = aws_client.redshift.create_cluster( diff --git a/tests/aws/services/route53resolver/test_route53resolver.py b/tests/aws/services/route53resolver/test_route53resolver.py index 13d18733a1600..32f8600ac5c39 100644 --- a/tests/aws/services/route53resolver/test_route53resolver.py +++ b/tests/aws/services/route53resolver/test_route53resolver.py @@ -69,7 +69,6 @@ def _is_endpoint_deleted(): @markers.snapshot.skip_snapshot_verify(paths=["$..ResolverEndpointType"]) class TestRoute53Resolver: - # TODO: make this class level? @pytest.fixture(scope="function") def setup_resources(self, aws_client, cleanups): diff --git a/tests/aws/services/s3/test_s3.py b/tests/aws/services/s3/test_s3.py index 29260cb7b11cb..418c632d0b24b 100644 --- a/tests/aws/services/s3/test_s3.py +++ b/tests/aws/services/s3/test_s3.py @@ -14,7 +14,6 @@ from operator import itemgetter from typing import TYPE_CHECKING from urllib.parse import SplitResult, parse_qs, quote, urlencode, urlparse, urlunsplit -from zoneinfo import ZoneInfo import boto3 as boto3 import pytest @@ -25,6 +24,7 @@ from botocore.auth import SigV4Auth from botocore.client import Config from botocore.exceptions import ClientError +from zoneinfo import ZoneInfo from localstack import config, constants from localstack.aws.api.s3 import StorageClass @@ -362,7 +362,6 @@ def test_region_header_exists(self, s3_create_bucket, snapshot, aws_client): # TODO list-buckets contains other buckets when running in CI @markers.snapshot.skip_snapshot_verify(paths=["$..Prefix", "$..list-buckets.Buckets"]) def test_delete_bucket_with_content(self, s3_bucket, s3_empty_bucket, snapshot, aws_client): - snapshot.add_transformer(snapshot.transform.s3_api()) bucket_name = s3_bucket @@ -3253,7 +3252,6 @@ def test_s3_uppercase_key_names(self, s3_create_bucket, snapshot, aws_client): def test_s3_download_object_with_lambda( self, s3_create_bucket, create_lambda_function, lambda_su_role, aws_client ): - bucket_name = f"bucket-{short_uid()}" function_name = f"func-{short_uid()}" key = f"key-{short_uid()}" @@ -5707,7 +5705,6 @@ def test_cross_account_access(self, primary_client, secondary_client): class TestS3TerraformRawRequests: @markers.aws.only_localstack def test_terraform_request_sequence(self, aws_client): - reqs = load_file( os.path.join( os.path.dirname(__file__), @@ -5957,7 +5954,6 @@ def test_put_object_with_md5_and_chunk_signature_bad_headers( aws_client, presigned_snapshot_transformers, ): - snapshotted = False if verify_signature: monkeypatch.setattr(config, "S3_SKIP_SIGNATURE_VALIDATION", False) @@ -7636,7 +7632,6 @@ def test_routing_rules_order(self, s3_bucket, aws_client, allow_bucket_acl): paths=["$.invalid-website-conf-1.Error.ArgumentValue"] ) def test_validate_website_configuration(self, s3_bucket, snapshot, aws_client): - website_configurations = [ # can't have slash in the suffix { diff --git a/tests/aws/services/s3/test_s3_api.py b/tests/aws/services/s3/test_s3_api.py index 56455658445cc..d79af3c99591e 100644 --- a/tests/aws/services/s3/test_s3_api.py +++ b/tests/aws/services/s3/test_s3_api.py @@ -800,7 +800,6 @@ def test_s3_bucket_encryption_sse_s3(self, s3_bucket, aws_client, snapshot): condition=is_not_native_provider, paths=["$..BucketKeyEnabled"] ) def test_s3_bucket_encryption_sse_kms(self, s3_bucket, kms_key, aws_client, snapshot): - put_bucket_enc = aws_client.s3.put_bucket_encryption( Bucket=s3_bucket, ServerSideEncryptionConfiguration={ diff --git a/tests/aws/services/secretsmanager/test_secretsmanager.py b/tests/aws/services/secretsmanager/test_secretsmanager.py index 446942507f12d..ce7d23bffde18 100644 --- a/tests/aws/services/secretsmanager/test_secretsmanager.py +++ b/tests/aws/services/secretsmanager/test_secretsmanager.py @@ -322,7 +322,7 @@ def test_resource_policy(self, secret_name, aws_client): SecretId=secret_name, ForceDeleteWithoutRecovery=True ) - @pytest.mark.skip(condition=is_new_provider(), reason="needs lambda usage rework") + @pytest.mark.skipif(condition=is_new_provider(), reason="needs lambda usage rework") @markers.aws.unknown def test_rotate_secret_with_lambda_1( self, secret_name, create_secret, create_lambda_function, aws_client diff --git a/tests/aws/services/sns/test_sns.py b/tests/aws/services/sns/test_sns.py index 3342737f9007c..6d840119c3a83 100644 --- a/tests/aws/services/sns/test_sns.py +++ b/tests/aws/services/sns/test_sns.py @@ -122,7 +122,6 @@ def test_create_topic_with_attributes(self, sns_create_topic, snapshot, aws_clie @markers.aws.validated def test_tags(self, sns_create_topic, snapshot, aws_client): - topic_arn = sns_create_topic()["TopicArn"] with pytest.raises(ClientError) as exc: aws_client.sns.tag_resource( @@ -2046,7 +2045,6 @@ def test_publish_fifo_messages_to_dlq( raw_message_delivery, aws_client, ): - # the hash isn't the same because of the Binary attributes (maybe decoding order?) snapshot.add_transformer( snapshot.transform.key_value( @@ -2538,7 +2536,6 @@ class TestSNSFilter: def test_filter_policy( self, sqs_create_queue, sns_create_topic, sns_create_sqs_subscription, snapshot, aws_client ): - topic_arn = sns_create_topic()["TopicArn"] queue_url = sqs_create_queue() subscription = sns_create_sqs_subscription(topic_arn=topic_arn, queue_url=queue_url) @@ -2637,7 +2634,6 @@ def get_filter_policy(): def test_exists_filter_policy( self, sqs_create_queue, sns_create_topic, sns_create_sqs_subscription, snapshot, aws_client ): - topic_arn = sns_create_topic()["TopicArn"] queue_url = sqs_create_queue() subscription = sns_create_sqs_subscription(topic_arn=topic_arn, queue_url=queue_url) @@ -2919,7 +2915,6 @@ def test_filter_policy_on_message_body( raw_message_delivery, aws_client, ): - topic_arn = sns_create_topic()["TopicArn"] queue_url = sqs_create_queue() subscription = sns_create_sqs_subscription(topic_arn=topic_arn, queue_url=queue_url) @@ -3020,7 +3015,6 @@ def test_filter_policy_on_message_body( def test_filter_policy_for_batch( self, sqs_create_queue, sns_create_topic, sns_create_sqs_subscription, snapshot, aws_client ): - topic_arn = sns_create_topic()["TopicArn"] queue_url_with_filter = sqs_create_queue() subscription_with_filter = sns_create_sqs_subscription( @@ -3251,7 +3245,6 @@ class TestSNSPlatformEndpoint: def test_subscribe_platform_endpoint( self, sns_create_topic, sns_subscription, sns_create_platform_application, aws_client ): - sns_backend = SnsProvider.get_store(TEST_AWS_ACCOUNT_ID, TEST_AWS_REGION_NAME) topic_arn = sns_create_topic()["TopicArn"] diff --git a/tests/aws/services/sqs/test_sqs.py b/tests/aws/services/sqs/test_sqs.py index be2689f7a2e74..5c49d16535a98 100644 --- a/tests/aws/services/sqs/test_sqs.py +++ b/tests/aws/services/sqs/test_sqs.py @@ -1743,7 +1743,6 @@ def test_queue_list_nonexistent_tags(self, sqs_create_queue, aws_client): @markers.aws.validated def test_publish_get_delete_message(self, sqs_create_queue, aws_client): - # visibility part handled by test_receive_terminate_visibility_timeout queue_name = f"queue-{short_uid()}" queue_url = sqs_create_queue(QueueName=queue_name) @@ -2387,7 +2386,6 @@ def test_send_message_with_invalid_payload_characters(self, sqs_create_queue, aw @markers.aws.validated def test_dead_letter_queue_config(self, sqs_create_queue): - queue_name = f"queue-{short_uid()}" dead_letter_queue_name = f"dead_letter_queue-{short_uid()}" diff --git a/tests/aws/services/stepfunctions/templates/errorhandling/error_handling_templates.py b/tests/aws/services/stepfunctions/templates/errorhandling/error_handling_templates.py index aa0809ae3e7b4..549b8a69e0cd5 100644 --- a/tests/aws/services/stepfunctions/templates/errorhandling/error_handling_templates.py +++ b/tests/aws/services/stepfunctions/templates/errorhandling/error_handling_templates.py @@ -7,7 +7,6 @@ class ErrorHandlingTemplate(TemplateLoader): - # State Machines. AWS_SDK_TASK_FAILED_S3_LIST_OBJECTS: Final[str] = os.path.join( _THIS_FOLDER, "statemachines/aws_sdk_task_error_s3_list_objects.json5" diff --git a/tests/aws/templates/macros/add_standard_attributes.py b/tests/aws/templates/macros/add_standard_attributes.py index 5c7f752105bf9..2b7045615e98a 100644 --- a/tests/aws/templates/macros/add_standard_attributes.py +++ b/tests/aws/templates/macros/add_standard_attributes.py @@ -5,7 +5,6 @@ def handler(event, context): def add_standard_attributes(fragment): - fragment["FifoTopic"] = True fragment["ContentBasedDeduplication"] = True diff --git a/tests/aws/templates/macros/return_invalid_template.py b/tests/aws/templates/macros/return_invalid_template.py index 1c43d0c2c9c30..4db14cb423d75 100644 --- a/tests/aws/templates/macros/return_invalid_template.py +++ b/tests/aws/templates/macros/return_invalid_template.py @@ -1,4 +1,3 @@ def handler(event, context): - # anything else than success is considered failed return {"requestId": event["requestId"], "status": "success", "fragment": "invalid"} diff --git a/tests/aws/test_moto.py b/tests/aws/test_moto.py index 5bbb0b36fb522..0244e16b4bc1a 100644 --- a/tests/aws/test_moto.py +++ b/tests/aws/test_moto.py @@ -326,17 +326,17 @@ def _dispatch(action, params): # Test fallback implementation raises a service exception which has the additional attribute "BucketName" with pytest.raises(ServiceException) as e: _dispatch("GetObject", {"Bucket": bucket_name, "Key": "key"}) - assert getattr(e.value, "BucketName") == bucket_name + assert e.value.BucketName == bucket_name # Test provider implementation raises a service exception with pytest.raises(ServiceException) as e: _dispatch("ListObjects", {"Bucket": bucket_name}) - assert getattr(e.value, "BucketName") == bucket_name + assert e.value.BucketName == bucket_name # Test provider uses call_moto, which raises a service exception with pytest.raises(ServiceException) as e: _dispatch("ListObjectsV2", {"Bucket": bucket_name}) - assert getattr(e.value, "BucketName") == bucket_name + assert e.value.BucketName == bucket_name # Test provider raises NotImplementedAvoidFallbackError, avoiding a fall-through, raising the "not implemented" directly with pytest.raises(NotImplementedError) as e: diff --git a/tests/aws/test_notifications.py b/tests/aws/test_notifications.py index bd47b5ad2d333..e7229c930c458 100644 --- a/tests/aws/test_notifications.py +++ b/tests/aws/test_notifications.py @@ -23,7 +23,6 @@ def test_sqs_queue_names(self, aws_client): def test_sns_to_sqs( self, sqs_create_queue, sns_create_topic, sqs_receive_num_messages, aws_client ): - # create topic and queue queue_url = sqs_create_queue() topic_info = sns_create_topic() diff --git a/tests/unit/test_cloudwatch.py b/tests/unit/test_cloudwatch.py index 115783397dede..13f0bc5b40561 100644 --- a/tests/unit/test_cloudwatch.py +++ b/tests/unit/test_cloudwatch.py @@ -21,7 +21,6 @@ class TestAlarmScheduler: TEST_5_M_OF_N = "'- - - X -'" def test_comparison_operation_mapping(self): - a = 3 b = 4 diff --git a/tests/unit/test_common.py b/tests/unit/test_common.py index 6bb79cd319239..de52385e837d9 100644 --- a/tests/unit/test_common.py +++ b/tests/unit/test_common.py @@ -6,10 +6,10 @@ import time import zipfile from datetime import date, datetime, timezone -from zoneinfo import ZoneInfo import pytest import yaml +from zoneinfo import ZoneInfo from localstack import config from localstack.utils import common @@ -487,7 +487,8 @@ def test_create_archive(self): def test_unzip_bad_crc(self): """Test unzipping of files with incorrect CRC codes - usually works with native `unzip` command, - but seems to fail with zipfile module under certain Python versions (extracts 0-bytes files)""" + but seems to fail with zipfile module under certain Python versions (extracts 0-bytes files) + """ # base64-encoded zip file with a single entry with incorrect CRC (created by Node.js 18 / Serverless) zip_base64 = """ diff --git a/tests/unit/test_kms.py b/tests/unit/test_kms.py index 3abcf70903bad..109b8d09630ec 100644 --- a/tests/unit/test_kms.py +++ b/tests/unit/test_kms.py @@ -4,6 +4,5 @@ def test_alias_name_validator(): - with pytest.raises(Exception): validate_alias_name("test-alias") diff --git a/tests/unit/test_misc.py b/tests/unit/test_misc.py index b6907d3ca2cb7..b397e7d8b5ae9 100644 --- a/tests/unit/test_misc.py +++ b/tests/unit/test_misc.py @@ -153,7 +153,6 @@ async def run(): # This test is not enabled in CI, it is just used for manual # testing to debug https://github.com/localstack/localstack/issues/213 def run_parallel_download(): - file_length = 10000000 class DownloadListener(ProxyListener): diff --git a/tests/unit/test_partition_rewriter.py b/tests/unit/test_partition_rewriter.py index 629950da66543..f62104c5603c9 100644 --- a/tests/unit/test_partition_rewriter.py +++ b/tests/unit/test_partition_rewriter.py @@ -331,7 +331,7 @@ def echo(_request: WerkzeugRequest) -> Response: handler_data["received_request"] = _request response = Response() response.set_data(_request.data) - response.headers = request.headers + response.headers = _request.headers handler_data["sent_request"] = response return response diff --git a/tests/unit/test_s3.py b/tests/unit/test_s3.py index 698f4ecef170c..0dfb0d91b908a 100644 --- a/tests/unit/test_s3.py +++ b/tests/unit/test_s3.py @@ -1,11 +1,11 @@ import datetime import os import unittest -import zoneinfo from io import BytesIO from urllib.parse import urlparse import pytest +import zoneinfo from requests.models import Response from localstack.aws.api import RequestContext diff --git a/tests/unit/utils/test_net_utils.py b/tests/unit/utils/test_net_utils.py index 7fe88ce0ace16..b48c68e6d0969 100644 --- a/tests/unit/utils/test_net_utils.py +++ b/tests/unit/utils/test_net_utils.py @@ -32,7 +32,6 @@ def test_resolve_hostname(): @pytest.mark.parametrize("protocol", ["tcp", "udp"]) def test_port_open(protocol): - if protocol == "tcp": sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) else: diff --git a/tests/unit/utils/test_objects.py b/tests/unit/utils/test_objects.py index da87ff47973f2..d981b99b59279 100644 --- a/tests/unit/utils/test_objects.py +++ b/tests/unit/utils/test_objects.py @@ -62,7 +62,6 @@ def my_singleton(): mock.assert_has_calls([(), ()]) def test_exception_does_not_set_a_value(self): - mock = MagicMock() @singleton_factory