Get admin database info
()
| 377 | |
| 378 | // Get admin database info |
| 379 | func (h *handler) handleGetDbConfig() error { |
| 380 | if redact, _ := h.getOptBoolQuery("redact", true); !redact { |
| 381 | return base.HTTPErrorf(http.StatusBadRequest, "redact=false is no longer supported") |
| 382 | } |
| 383 | |
| 384 | // load config from bucket once for: |
| 385 | // - Populate an up to date ETag header |
| 386 | // - Applying if refresh_config is set |
| 387 | // - Returning if include_runtime=false |
| 388 | var responseConfig *DbConfig |
| 389 | if h.server.BootstrapContext.Connection != nil { |
| 390 | found, dbConfig, err := h.server.fetchDatabase(h.ctx(), h.db.Name) |
| 391 | if err != nil { |
| 392 | return err |
| 393 | } |
| 394 | |
| 395 | if !found || dbConfig == nil { |
| 396 | return base.HTTPErrorf(http.StatusNotFound, "database config not found") |
| 397 | } |
| 398 | |
| 399 | h.setEtag(dbConfig.Version) |
| 400 | // refresh_config=true forces the config loaded out of the bucket to be applied on the node |
| 401 | if h.getBoolQuery("refresh_config") && h.server.BootstrapContext.Connection != nil { |
| 402 | // set cas=0 to force a refresh |
| 403 | dbConfig.cfgCas = 0 |
| 404 | h.server.applyConfigs(h.ctx(), map[string]DatabaseConfig{h.db.Name: *dbConfig}) |
| 405 | } |
| 406 | |
| 407 | responseConfig = &dbConfig.DbConfig |
| 408 | |
| 409 | // Strip out bootstrap credentials that are stamped into the config |
| 410 | responseConfig.Username = "" |
| 411 | responseConfig.Password = "" |
| 412 | responseConfig.CACertPath = "" |
| 413 | responseConfig.KeyPath = "" |
| 414 | responseConfig.CertPath = "" |
| 415 | } else { |
| 416 | // non-persistent mode just returns running database config |
| 417 | responseConfig = h.server.GetDbConfig(h.db.Name) |
| 418 | } |
| 419 | |
| 420 | // include_runtime controls whether to return the raw bucketDbConfig, or the runtime version populated with default values, etc. |
| 421 | includeRuntime, _ := h.getOptBoolQuery("include_runtime", false) |
| 422 | if includeRuntime { |
| 423 | |
| 424 | var err error |
| 425 | responseConfig, err = MergeDatabaseConfigWithDefaults(h.server.Config, h.server.GetDbConfig(h.db.Name)) |
| 426 | if err != nil { |
| 427 | return err |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | // defensive check - there could've been an in-flight request to remove the database between entering the handler and getting the config above. |
| 432 | if responseConfig == nil { |
| 433 | return base.HTTPErrorf(http.StatusNotFound, "database config not found") |
| 434 | } |
| 435 | |
| 436 | var err error |
nothing calls this directly
no test coverage detected