Logs - fix typo in log-group-name regex (#4972)
This commit is contained in:
parent
1f9f4af1c4
commit
2929f3ee35
@ -9,6 +9,9 @@ from .models import logs_backends
|
||||
# See http://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/Welcome.html
|
||||
|
||||
|
||||
REGEX_LOG_GROUP_NAME = r"[-._\/#A-Za-z0-9]+"
|
||||
|
||||
|
||||
def validate_param(
|
||||
param_name, param_value, constraint, constraint_expression, pattern=None
|
||||
):
|
||||
@ -20,7 +23,7 @@ def validate_param(
|
||||
)
|
||||
if pattern and param_value:
|
||||
try:
|
||||
assert re.match(pattern, param_value)
|
||||
assert re.fullmatch(pattern, param_value)
|
||||
except (AssertionError, TypeError):
|
||||
raise InvalidParameterException(
|
||||
constraint=f"Must match pattern: {pattern}",
|
||||
@ -67,7 +70,7 @@ class LogsResponse(BaseResponse):
|
||||
"logGroupName",
|
||||
"Minimum length of 1. Maximum length of 512.",
|
||||
lambda x: 1 <= len(x) <= 512,
|
||||
pattern="[.-_/#A-Za-z0-9]+",
|
||||
pattern=REGEX_LOG_GROUP_NAME,
|
||||
)
|
||||
metric_transformations = self._get_validated_param(
|
||||
"metricTransformations", "Fixed number of 1 item.", lambda x: len(x) == 1
|
||||
@ -90,7 +93,7 @@ class LogsResponse(BaseResponse):
|
||||
"logGroupName",
|
||||
"Minimum length of 1. Maximum length of 512",
|
||||
lambda x: x is None or 1 <= len(x) <= 512,
|
||||
pattern="[.-_/#A-Za-z0-9]+",
|
||||
pattern=REGEX_LOG_GROUP_NAME,
|
||||
)
|
||||
metric_name = self._get_validated_param(
|
||||
"metricName",
|
||||
@ -139,7 +142,7 @@ class LogsResponse(BaseResponse):
|
||||
"logGroupName",
|
||||
"Minimum length of 1. Maximum length of 512.",
|
||||
lambda x: 1 <= len(x) <= 512,
|
||||
pattern="[.-_/#A-Za-z0-9]+$",
|
||||
pattern=REGEX_LOG_GROUP_NAME,
|
||||
)
|
||||
|
||||
self.logs_backend.delete_metric_filter(filter_name, log_group_name)
|
||||
|
@ -181,26 +181,32 @@ def test_describe_metric_filters_multiple_happy():
|
||||
|
||||
@mock_logs
|
||||
def test_delete_metric_filter():
|
||||
conn = boto3.client("logs", "us-west-2")
|
||||
client = boto3.client("logs", "us-west-2")
|
||||
|
||||
response = put_metric_filter(conn, 1)
|
||||
assert response["ResponseMetadata"]["HTTPStatusCode"] == 200
|
||||
lg_name = "/hello-world/my-cool-endpoint"
|
||||
client.create_log_group(logGroupName=lg_name)
|
||||
client.put_metric_filter(
|
||||
logGroupName=lg_name,
|
||||
filterName="my-cool-filter",
|
||||
filterPattern="{ $.val = * }",
|
||||
metricTransformations=[
|
||||
{
|
||||
"metricName": "my-metric",
|
||||
"metricNamespace": "my-namespace",
|
||||
"metricValue": "$.value",
|
||||
}
|
||||
],
|
||||
)
|
||||
|
||||
response = put_metric_filter(conn, 2)
|
||||
assert response["ResponseMetadata"]["HTTPStatusCode"] == 200
|
||||
|
||||
response = conn.delete_metric_filter(
|
||||
filterName="filterName", logGroupName="logGroupName1"
|
||||
response = client.delete_metric_filter(
|
||||
filterName="filterName", logGroupName=lg_name
|
||||
)
|
||||
assert response["ResponseMetadata"]["HTTPStatusCode"] == 200
|
||||
|
||||
response = conn.describe_metric_filters(
|
||||
response = client.describe_metric_filters(
|
||||
filterNamePrefix="filter", logGroupName="logGroupName2"
|
||||
)
|
||||
assert response["metricFilters"][0]["filterName"] == "filterName2"
|
||||
|
||||
response = conn.describe_metric_filters(logGroupName="logGroupName2")
|
||||
assert response["metricFilters"][0]["filterName"] == "filterName2"
|
||||
response.should.have.key("metricFilters").equals([])
|
||||
|
||||
|
||||
@mock_logs
|
||||
|
Loading…
Reference in New Issue
Block a user