Skip to content

Commit 2f4da11

Browse files
committed
feat(anonymization): implement anonymizeText mutation and associated service
- Added a new SQL migration to insert the 'anonymize.call' privilege into the privileges table. - Introduced the `anonymizeText` mutation in the GraphQL schema, allowing users to anonymize sensitive text. - Implemented the `AnonymizerService` to handle text anonymization requests via a REST API endpoint. - Updated the GraphQL resolver to integrate the new mutation and ensure proper permission checks. - Enhanced documentation with Swagger and OpenAPI specifications for the new endpoint. - Added error handling for invalid requests and unavailable anonymizer configurations.
1 parent fbf917a commit 2f4da11

14 files changed

Lines changed: 537 additions & 9 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-- +goose Up
2+
-- +goose StatementBegin
3+
4+
INSERT INTO privileges (role_id, name) VALUES
5+
(1, 'anonymize.call'),
6+
(2, 'anonymize.call')
7+
ON CONFLICT DO NOTHING;
8+
9+
-- +goose StatementEnd
10+
11+
-- +goose Down
12+
-- +goose StatementBegin
13+
14+
DELETE FROM privileges WHERE name = 'anonymize.call';
15+
16+
-- +goose StatementEnd

backend/pkg/graph/generated.go

Lines changed: 108 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/pkg/graph/resolver.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"pentagi/pkg/templates"
1212

1313
"github.com/sirupsen/logrus"
14+
"github.com/vxcontrol/cloud/anonymizer"
1415
)
1516

1617
// This file will not be regenerated automatically.
@@ -27,4 +28,5 @@ type Resolver struct {
2728
Controller controller.FlowController
2829
Subscriptions subscriptions.SubscriptionsController
2930
Knowledge knowledge.KnowledgeStore
31+
Replacer anonymizer.Replacer
3032
}

backend/pkg/graph/schema.graphqls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,7 @@ type Mutation {
10271027
createKnowledgeDocument(input: CreateKnowledgeDocumentInput!): KnowledgeDocument!
10281028
updateKnowledgeDocument(id: String!, input: UpdateKnowledgeDocumentInput!): KnowledgeDocument!
10291029
deleteKnowledgeDocument(id: String!): ResultType!
1030+
anonymizeText(text: String!): String!
10301031
}
10311032

10321033
type Subscription {

backend/pkg/graph/schema.resolvers.go

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/pkg/server/docs/docs.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,75 @@ const docTemplate = `{
140140
}
141141
}
142142
},
143+
"/anonymize/text": {
144+
"post": {
145+
"security": [
146+
{
147+
"BearerAuth": []
148+
}
149+
],
150+
"description": "Replace sensitive data patterns (credentials, keys, PII, etc.) in the provided text with safe placeholders.",
151+
"consumes": [
152+
"application/json"
153+
],
154+
"produces": [
155+
"application/json"
156+
],
157+
"tags": [
158+
"Anonymize"
159+
],
160+
"summary": "Anonymize text",
161+
"parameters": [
162+
{
163+
"description": "Text to anonymize",
164+
"name": "json",
165+
"in": "body",
166+
"required": true,
167+
"schema": {
168+
"$ref": "#/definitions/services.anonymizeTextRequest"
169+
}
170+
}
171+
],
172+
"responses": {
173+
"200": {
174+
"description": "anonymized text returned successfully",
175+
"schema": {
176+
"allOf": [
177+
{
178+
"$ref": "#/definitions/SuccessResponse"
179+
},
180+
{
181+
"type": "object",
182+
"properties": {
183+
"data": {
184+
"$ref": "#/definitions/services.anonymizeTextResponse"
185+
}
186+
}
187+
}
188+
]
189+
}
190+
},
191+
"400": {
192+
"description": "invalid request body",
193+
"schema": {
194+
"$ref": "#/definitions/ErrorResponse"
195+
}
196+
},
197+
"403": {
198+
"description": "anonymize.call permission required",
199+
"schema": {
200+
"$ref": "#/definitions/ErrorResponse"
201+
}
202+
},
203+
"503": {
204+
"description": "anonymizer is not configured",
205+
"schema": {
206+
"$ref": "#/definitions/ErrorResponse"
207+
}
208+
}
209+
}
210+
}
211+
},
143212
"/assistantlogs/": {
144213
"get": {
145214
"security": [
@@ -9683,6 +9752,25 @@ const docTemplate = `{
96839752
}
96849753
}
96859754
},
9755+
"services.anonymizeTextRequest": {
9756+
"type": "object",
9757+
"required": [
9758+
"text"
9759+
],
9760+
"properties": {
9761+
"text": {
9762+
"type": "string"
9763+
}
9764+
}
9765+
},
9766+
"services.anonymizeTextResponse": {
9767+
"type": "object",
9768+
"properties": {
9769+
"text": {
9770+
"type": "string"
9771+
}
9772+
}
9773+
},
96869774
"services.assistantlogs": {
96879775
"type": "object",
96889776
"properties": {

0 commit comments

Comments
 (0)