Skip to content

Commit 9ac82fe

Browse files
AI feedback 10 - address feedback
Signed-off-by: Lukasz Gryglicki <lgryglicki@cncf.io> Assisted by [OpenAI](https://platform.openai.com/) Assisted by [GitHub Copilot](https://github.com/features/copilot)
1 parent 5bc6b99 commit 9ac82fe

File tree

5 files changed

+27
-19
lines changed

5 files changed

+27
-19
lines changed

cla-backend-go/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: MIT
33
module github.com/linuxfoundation/easycla/cla-backend-go
44

5-
go 1.24.0
5+
go 1.24
66

77
replace github.com/awslabs/aws-lambda-go-api-proxy => github.com/LF-Engineering/aws-lambda-go-api-proxy v0.3.2
88

cla-backend-go/serverless.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ provider:
301301
DD_API_KEY_SECRET_ARN: ${file(./env.json):dd-api-key-secret-arn-${opt:stage}, ssm:/cla-dd-api-key-secret-arn-${opt:stage}}
302302
DD_OTLP_CONFIG_RECEIVER_PROTOCOLS_HTTP_ENDPOINT: localhost:4318
303303
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: http://localhost:4318/v1/traces
304+
OTEL_DATADOG_API_LOGGING: ${file(./env.json):otel-datadog-api-logging-${opt:stage}, ssm:/cla-otel-datadog-api-logging-${opt:stage}}
305+
DDB_API_LOGGING: ${file(./env.json):dynamodb-api-logging-${opt:stage}, ssm:/cla-dynamodb-api-logging-${opt:stage}}
304306

305307
stackTags:
306308
Name: ${self:service}

cla-backend-go/telemetry/datadog_otlp.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ func WrapHTTPHandler(next http.Handler) http.Handler {
114114
reAssetExt := regexp.MustCompile(`\.(png|svg|css|js|json|xml|htm|html)$`)
115115
reSwaggerAsset := regexp.MustCompile(`^(/v[0-9]+)/swagger\.\{asset\}$`)
116116
reUUID := regexp.MustCompile(`[0-9a-fA-F-]{36}`)
117-
reNumericID := regexp.MustCompile(`/[0-9]+(?=/|$)`)
118-
reSFID := regexp.MustCompile(`/(?:00|a0)[A-Za-z0-9]{13,16}(?=/|$)`)
119-
reLFXID := regexp.MustCompile(`/lf[A-Za-z0-9]{16,22}(?=/|$)`)
120-
reNull := regexp.MustCompile(`/null(?=/|$)`)
117+
reNumericID := regexp.MustCompile(`/[0-9]+(/|$)`)
118+
reSFID := regexp.MustCompile(`/(?:00|a0)[A-Za-z0-9]{13,16}(/|$)`)
119+
reLFXID := regexp.MustCompile(`/lf[A-Za-z0-9]{16,22}(/|$)`)
120+
reNull := regexp.MustCompile(`/null(/|$)`)
121121

122122
sanitize := func(path string) string {
123123
p := strings.TrimSpace(path)
@@ -143,10 +143,10 @@ func WrapHTTPHandler(next http.Handler) http.Handler {
143143

144144
// Dynamic segment masking (use template placeholders, not "*")
145145
p = reUUID.ReplaceAllString(p, "{uuid}")
146-
p = reNumericID.ReplaceAllString(p, "/{id}")
147-
p = reSFID.ReplaceAllString(p, "/{sfid}")
148-
p = reLFXID.ReplaceAllString(p, "/{lfxid}")
149-
p = reNull.ReplaceAllString(p, "/{null}")
146+
p = reNumericID.ReplaceAllString(p, "/{id}$1")
147+
p = reSFID.ReplaceAllString(p, "/{sfid}$1")
148+
p = reLFXID.ReplaceAllString(p, "/{lfxid}$1")
149+
p = reNull.ReplaceAllString(p, "/{null}$1")
150150

151151
if p == "" {
152152
return "/"

cla-backend/cla/routes.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@
5858
_RE_ASSET_EXT = re.compile(r"\.(png|svg|css|js|json|xml|htm|html)$")
5959
_RE_SWAGGER_ASSET = re.compile(r"^(/v[0-9]+)/swagger\.\{asset\}$")
6060
_RE_UUID = re.compile(r"[0-9a-fA-F-]{36}")
61-
_RE_NUMERIC_ID = re.compile(r"/[0-9]+(?=/|$)")
62-
_RE_SFID = re.compile(r"/(?:00|a0)[A-Za-z0-9]{13,16}(?=/|$)")
63-
_RE_LFXID = re.compile(r"/lf[A-Za-z0-9]{16,22}(?=/|$)")
64-
_RE_NULL = re.compile(r"/null(?=/|$)")
61+
_RE_NUMERIC_ID = re.compile(r"/[0-9]+(/|$)")
62+
_RE_SFID = re.compile(r"/(?:00|a0)[A-Za-z0-9]{13,16}(/|$)")
63+
_RE_LFXID = re.compile(r"/lf[A-Za-z0-9]{16,22}(/|$)")
64+
_RE_NULL = re.compile(r"/null(/|$)")
6565

6666
def _sanitize_api_path(path: str) -> str:
6767
"""
@@ -86,16 +86,20 @@ def _sanitize_api_path(path: str) -> str:
8686

8787
# Dynamic IDs -> placeholders
8888
p = _RE_UUID.sub("{uuid}", p)
89-
p = _RE_NUMERIC_ID.sub("/{id}", p)
90-
p = _RE_SFID.sub("/{sfid}", p)
91-
p = _RE_LFXID.sub("/{lfxid}", p)
92-
p = _RE_NULL.sub("/{null}", p)
89+
p = _RE_NUMERIC_ID.sub(r"/{id}\1", p)
90+
p = _RE_SFID.sub(r"/{sfid}\1", p)
91+
p = _RE_LFXID.sub(r"/{lfxid}\1", p)
92+
p = _RE_NULL.sub(r"/{null}\1", p)
9393

9494
return p or "/"
9595

9696
def _stage_to_dd_env(stage: str) -> str:
9797
st = (stage or "dev").strip().lower()
98-
return "prod" if st == "prod" else "dev"
98+
if st == "prod":
99+
return "prod"
100+
if st == "staging":
101+
return "staging"
102+
return "dev"
99103

100104
def _build_otlp_traces_endpoint() -> str:
101105
"""
@@ -319,7 +323,7 @@ def process_data_api_logs(request, response):
319323

320324
# OTel/Datadog API logging (stub only for Python for now)
321325
if _enabled_by_env_or_stage("OTEL_DATADOG_API_LOGGING", default_by_stage=(True, True)):
322-
_log_api_request_otel_datadog_async(getattr(request, "method", "GET"), request.path)
326+
_log_api_request_otel_datadog_async(getattr(request, "method", "GET"), request.path)
323327

324328
if "/github/activity" in request.path:
325329
body = request.bounded_stream.read()

cla-backend/serverless.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,8 @@ provider:
387387
DD_API_KEY_SECRET_ARN: ${file(./env.json):dd-api-key-secret-arn-${sls:stage}, ssm:/cla-dd-api-key-secret-arn-${sls:stage}}
388388
DD_OTLP_CONFIG_RECEIVER_PROTOCOLS_HTTP_ENDPOINT: localhost:4318
389389
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: http://localhost:4318/v1/traces
390+
OTEL_DATADOG_API_LOGGING: ${file(./env.json):otel-datadog-api-logging-${sls:stage}, ssm:/cla-otel-datadog-api-logging-${sls:stage}}
391+
DDB_API_LOGGING: ${file(./env.json):dynamodb-api-logging-${sls:stage}, ssm:/cla-dynamodb-api-logging-${sls:stage}}
390392

391393
stackTags:
392394
Name: ${self:service}

0 commit comments

Comments
 (0)