readSanitizeJSONInto reads and sanitizes a JSON request body and returns DatabaseConfig. Expands environment variables (if any) referenced in the config.
(val interface{})
| 1332 | // readSanitizeJSONInto reads and sanitizes a JSON request body and returns DatabaseConfig. |
| 1333 | // Expands environment variables (if any) referenced in the config. |
| 1334 | func (h *handler) readSanitizeJSON(val interface{}) ([]byte, error) { |
| 1335 | // Performs the Content-Type validation and Content-Encoding check. |
| 1336 | input, err := processContentEncoding(h.rq.Header, h.requestBody, "application/json") |
| 1337 | if err != nil { |
| 1338 | return nil, err |
| 1339 | } |
| 1340 | |
| 1341 | // Read body bytes to sanitize the content and substitute environment variables. |
| 1342 | defer func() { _ = input.Close() }() |
| 1343 | raw, err := io.ReadAll(input) |
| 1344 | if err != nil { |
| 1345 | return nil, err |
| 1346 | } |
| 1347 | |
| 1348 | content, err := sanitiseConfig(h.ctx(), raw, h.server.Config.Unsupported.AllowDbConfigEnvVars) |
| 1349 | if err != nil { |
| 1350 | return nil, err |
| 1351 | } |
| 1352 | |
| 1353 | // Decode the body bytes into target structure. |
| 1354 | decoder := base.JSONDecoder(bytes.NewReader(content)) |
| 1355 | decoder.DisallowUnknownFields() |
| 1356 | decoder.UseNumber() |
| 1357 | err = decoder.Decode(&val) |
| 1358 | |
| 1359 | if err != nil { |
| 1360 | err = base.WrapJSONUnknownFieldErr(err) |
| 1361 | if errors.Cause(err) != base.ErrUnknownField { |
| 1362 | err = base.HTTPErrorf(http.StatusBadRequest, "Bad JSON: %s", err.Error()) |
| 1363 | } |
| 1364 | } |
| 1365 | return raw, err |
| 1366 | } |
| 1367 | |
| 1368 | // readJavascript reads a javascript function from a request body. |
| 1369 | func (h *handler) readJavascript() (string, error) { |
no test coverage detected