You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
APIKey: "YOUR API KEY HERE", // retrieve from Speakeasy API dashboard.
78
+
ApiID: "product_api", // this is an ID you provide that you would like to associate captured requests with.
79
+
VersionID: "1.0.0", // this is a Version you provide that you would like to associate captured requests with.
80
+
})
81
+
82
+
// The different instances of the SDK (with differnt IDs or even versions assigned) can be used to associate requests with different APIs and Versions.
83
+
s:= r.PathPrefix("/store").Subrouter()
84
+
r.Use(storeSDKInstance.Middleware)
85
+
86
+
s:= r.PathPrefix("/products").Subrouter()
87
+
r.Use(productSDKInstance.Middleware)
76
88
}
77
89
```
78
90
@@ -131,4 +143,53 @@ func MyHandler(w http.ResponseWriter, r *http.Request) {
131
143
}
132
144
```
133
145
134
-
Note: This is not required, but is highly recommended. By setting a customer ID you can easily associate requests with your customers/users in the Speakeasy Dashboard, powering filters in the Request Viewer [(Coming soon)](https://docs.speakeasyapi.dev/speakeasy-user-guide/request-viewer-coming-soon).
146
+
Note: This is not required, but is highly recommended. By setting a customer ID you can easily associate requests with your customers/users in the Speakeasy Dashboard, powering filters in the [Request Viewer](https://docs.speakeasyapi.dev/speakeasy-user-guide/request-viewer).
147
+
148
+
## Masking sensitive data
149
+
150
+
Speakeasy can mask sensitive data in the query string parameters, headers, cookies and request/response bodies captured by the SDK. This is useful for maintaining sensitive data isolation, and retaining control over the data that is captured.
151
+
152
+
Using the `Advanced Configuration` section above you can completely ignore certain routes by not assigning the middleware to their router, causing the SDK to not capture any requests to that router.
153
+
154
+
But if you would like to be more selective you can mask certain sensitive data using our middleware controller allowing you to mask fields as needed in different handlers:
155
+
156
+
```go
157
+
funcMyHandler(whttp.ResponseWriter, r *http.Request) {
158
+
ctrl:= speakeasy.MiddlewareController(req)
159
+
ctrl.Masking(speakeasy.WithRequestHeaderMask("Authorization")) // Mask the Authorization header in the request
160
+
161
+
// the rest of your handlers code
162
+
}
163
+
```
164
+
165
+
The `Masking` function takes a number of different options to mask sensitive data in the request:
166
+
167
+
*`speakeasy.WithQueryStringMask` - **WithQueryStringMask** will mask the specified query strings with an optional mask string.
168
+
*`speakeasy.WithRequestHeaderMask` - **WithRequestHeaderMask** will mask the specified request headers with an optional mask string.
169
+
*`speakeasy.WithResponseHeaderMask` - **WithResponseHeaderMask** will mask the specified response headers with an optional mask string.
170
+
*`speakeasy.WithRequestCookieMask` - **WithRequestCookieMask** will mask the specified request cookies with an optional mask string.
171
+
*`speakeasy.WithResponseCookieMask` - **WithResponseCookieMask** will mask the specified response cookies with an optional mask string.
172
+
*`speakeasy.WithRequestFieldMaskString` - **WithRequestFieldMaskString** will mask the specified request body fields with an optional mask. Supports string fields only. Matches using regex.
173
+
*`speakeasy.WithRequestFieldMaskNumber` - **WithRequestFieldMaskNumber** will mask the specified request body fields with an optional mask. Supports number fields only. Matches using regex.
174
+
*`speakeasy.WithResponseFieldMaskString` - **WithResponseFieldMaskString** will mask the specified response body fields with an optional mask. Supports string fields only. Matches using regex.
175
+
*`speakeasy.WithResponseFieldMaskNumber` - **WithResponseFieldMaskNumber** will mask the specified response body fields with an optional mask. Supports number fields only. Matches using regex.
176
+
177
+
Masking can also be done more globally on all routes or a selection of routes by taking advantage of middleware. Here is an example:
178
+
179
+
```go
180
+
speakeasy.Configure(speakeasy.Config {
181
+
APIKey: "YOUR API KEY HERE", // retrieve from Speakeasy API dashboard.
182
+
ApiID: "YOUR API ID HERE", // this is an ID you provide that you would like to associate captured requests with.
183
+
VersionID: "YOUR VERSION ID HERE", // this is a Version you provide that you would like to associate captured requests with.
184
+
})
185
+
186
+
r:= mux.NewRouter()
187
+
r.Use(speakeasy.Middleware)
188
+
r.Use(func (next http.Handler) http.Handler {
189
+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
190
+
// Mask the Authorization header in the request for all requests served by this middleware
0 commit comments