use std::error::Error;
use axum::http::{header, StatusCode};
use axum::response::{IntoResponse, Response};
use crate::servers::apis::v1::context::auth_key::resources::AuthKey;
use crate::servers::apis::v1::responses::{bad_request_response, unhandled_rejection_response};
#[must_use]
pub fn auth_key_response(auth_key: &AuthKey) -> Response {
(
StatusCode::OK,
[(header::CONTENT_TYPE, "application/json; charset=utf-8")],
serde_json::to_string(auth_key).unwrap(),
)
.into_response()
}
#[must_use]
pub fn failed_to_generate_key_response<E: Error>(e: E) -> Response {
unhandled_rejection_response(format!("failed to generate key: {e}"))
}
#[must_use]
pub fn failed_to_add_key_response<E: Error>(e: E) -> Response {
unhandled_rejection_response(format!("failed to add key: {e}"))
}
#[must_use]
pub fn failed_to_delete_key_response<E: Error>(e: E) -> Response {
unhandled_rejection_response(format!("failed to delete key: {e}"))
}
#[must_use]
pub fn failed_to_reload_keys_response<E: Error>(e: E) -> Response {
unhandled_rejection_response(format!("failed to reload keys: {e}"))
}
#[must_use]
pub fn invalid_auth_key_response<E: Error>(auth_key: &str, e: E) -> Response {
bad_request_response(&format!("Invalid URL: invalid auth key: string \"{auth_key}\", {e}"))
}
#[must_use]
pub fn invalid_auth_key_duration_response(duration: u64) -> Response {
bad_request_response(&format!("Invalid URL: invalid auth key duration: \"{duration}\""))
}