mirror of
https://github.com/block/goose.git
synced 2026-07-17 12:56:20 +02:00
Handle missing keys with a default (#3753)
Co-authored-by: Douwe Osinga <douwe@squareup.com>
This commit is contained in:
@@ -7,9 +7,9 @@ use axum::{
|
||||
Json, Router,
|
||||
};
|
||||
use etcetera::{choose_app_strategy, AppStrategy};
|
||||
use goose::config::Config;
|
||||
use goose::config::APP_STRATEGY;
|
||||
use goose::config::{extensions::name_to_key, PermissionManager};
|
||||
use goose::config::{Config, ConfigError};
|
||||
use goose::config::{ExtensionConfigManager, ExtensionEntry};
|
||||
use goose::model::ModelConfig;
|
||||
use goose::providers::base::ProviderMetadata;
|
||||
@@ -142,7 +142,7 @@ pub async fn remove_config(
|
||||
request_body = ConfigKeyQuery,
|
||||
responses(
|
||||
(status = 200, description = "Configuration value retrieved successfully", body = Value),
|
||||
(status = 404, description = "Configuration key not found")
|
||||
(status = 500, description = "Unable to get the configuration value"),
|
||||
)
|
||||
)]
|
||||
pub async fn read_config(
|
||||
@@ -160,17 +160,24 @@ pub async fn read_config(
|
||||
}
|
||||
|
||||
let config = Config::global();
|
||||
|
||||
match config.get(&query.key, query.is_secret) {
|
||||
let response_value = match config.get(&query.key, query.is_secret) {
|
||||
Ok(value) => {
|
||||
if query.is_secret {
|
||||
Ok(Json(Value::Bool(true)))
|
||||
Value::Bool(true)
|
||||
} else {
|
||||
Ok(Json(value))
|
||||
value
|
||||
}
|
||||
}
|
||||
Err(_) => Err(StatusCode::NOT_FOUND),
|
||||
}
|
||||
Err(ConfigError::NotFound(_)) => {
|
||||
if query.is_secret {
|
||||
Value::Bool(false)
|
||||
} else {
|
||||
Value::Null
|
||||
}
|
||||
}
|
||||
Err(_) => return Err(StatusCode::INTERNAL_SERVER_ERROR),
|
||||
};
|
||||
Ok(Json(response_value))
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
|
||||
@@ -333,8 +333,8 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "Configuration key not found"
|
||||
"500": {
|
||||
"description": "Unable to get the configuration value"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1015,9 +1015,9 @@ export type ReadConfigData = {
|
||||
|
||||
export type ReadConfigErrors = {
|
||||
/**
|
||||
* Configuration key not found
|
||||
* Unable to get the configuration value
|
||||
*/
|
||||
404: unknown;
|
||||
500: unknown;
|
||||
};
|
||||
|
||||
export type ReadConfigResponses = {
|
||||
|
||||
Reference in New Issue
Block a user