Skip to content

Commit 6346eca

Browse files
johanandrenpatriknw
authored andcommitted
docs: Small improvements of the sanitization page (#1108)
* docs: Small improvements of the sanitization page * add a link to dependency injection page * sample java formatting (cherry picked from commit 7c506ea)
1 parent 58c8974 commit 6346eca

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

docs/src/modules/sdk/pages/sanitization.adoc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ Text anonymization—detecting and masking sensitive details like names, emails,
88

99
Akka supports this through service-wide sanitization.
1010

11-
The sanitization disabled by default and can be selectively enabled through configuration.
11+
The sanitization is disabled by default and can be selectively enabled through configuration.
1212

13-
When enabled, sanitization is automatically applied to text that:
13+
When enabled, sanitization is automatically applied to text that is:
1414

1515
* written to logs
1616
* passed to agent models from agent requests
@@ -34,9 +34,16 @@ Before being written in logs or passed to agent models.
3434

3535
Sanitization can also be programmatically applied to text in any component where it makes sense for a specific
3636
business case, for example before sending some text to a third party API or before writing a text in the state
37-
of an entity. This is done by injecting a `akka.javasdk.Sanitizer` in the component constructor and
37+
of an entity. This is done by xref:setup-and-dependency-injection.adoc[injecting] a `akka.javasdk.Sanitizer` in the component constructor and
3838
then using `akka.javasdk.Sanitizer#sanitize` on the text.
3939

40+
[source,java,indent=0]
41+
.{sample-base-url}/doc-snippets/src/main/java/com/example/api/SanitizingEndpoint.java[SanitizingEndpoint.java]
42+
----
43+
include::example$doc-snippets/src/main/java/com/example/api/SanitizingEndpoint.java[tag=ad-hoc-sanitization]
44+
----
45+
46+
4047
== Sanitizer types
4148

4249
There are two types of sanitizers available, it is possible combine predefined and custom sanitizers in the same service:
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.example.api;
2+
3+
import akka.javasdk.Sanitizer;
4+
import akka.javasdk.annotations.Acl;
5+
import akka.javasdk.annotations.http.Get;
6+
import akka.javasdk.annotations.http.HttpEndpoint;
7+
8+
// tag::ad-hoc-sanitization[]
9+
@HttpEndpoint("/example-with-ad-hoc-sanitization")
10+
@Acl(allow = @Acl.Matcher(principal = Acl.Principal.ALL))
11+
public class SanitizingEndpoint {
12+
13+
private final Sanitizer sanitizer;
14+
15+
public SanitizingEndpoint(Sanitizer sanitizer) {
16+
this.sanitizer = sanitizer;
17+
}
18+
19+
@Get("/somepath/{id}")
20+
public String returnSanitizedData(String id) {
21+
// String data from another component or a third party library/API
22+
String someText = loadText();
23+
String sanitizedText = sanitizer.sanitize(someText);
24+
return sanitizedText;
25+
}
26+
27+
// end::ad-hoc-sanitization[]
28+
29+
private String loadText() {
30+
return "";
31+
}
32+
}

0 commit comments

Comments
 (0)