Rename ping endpoint
This commit is contained in:
parent
e1fa218df4
commit
2d54781228
3 changed files with 8 additions and 8 deletions
|
|
@ -0,0 +1,24 @@
|
||||||
|
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Server configuration and authentication status.
|
||||||
|
*/
|
||||||
|
export type ServerConfigResponse = {
|
||||||
|
/**
|
||||||
|
* Semantic version of the server.
|
||||||
|
*/
|
||||||
|
serverVersion: string,
|
||||||
|
/**
|
||||||
|
* Whether the client is authenticated based on the sent Authorization
|
||||||
|
* header.
|
||||||
|
*/
|
||||||
|
isAuthenticated: boolean,
|
||||||
|
/**
|
||||||
|
* List of file extensions that are allowed to be merged.
|
||||||
|
*/
|
||||||
|
mergeableFileExtensions: Array<string>,
|
||||||
|
/**
|
||||||
|
* API version that must match exactly between the client
|
||||||
|
* and server.
|
||||||
|
*/
|
||||||
|
supportedApiVersion: number, };
|
||||||
|
|
@ -3,10 +3,10 @@ pub mod fetch_document_version_content;
|
||||||
pub mod fetch_latest_document_metadata;
|
pub mod fetch_latest_document_metadata;
|
||||||
pub mod fetch_latest_document_version;
|
pub mod fetch_latest_document_version;
|
||||||
pub mod get_file_manifest;
|
pub mod get_file_manifest;
|
||||||
|
pub mod get_server_config;
|
||||||
pub mod index;
|
pub mod index;
|
||||||
pub mod method_not_allowed;
|
pub mod method_not_allowed;
|
||||||
pub mod not_found;
|
pub mod not_found;
|
||||||
pub mod ping;
|
|
||||||
pub mod put_file_content;
|
pub mod put_file_content;
|
||||||
pub mod put_file_manifest;
|
pub mod put_file_manifest;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
|
||||||
33
sync-server/src/server/endpoints/get_server_config.rs
Normal file
33
sync-server/src/server/endpoints/get_server_config.rs
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
use axum::{
|
||||||
|
Json,
|
||||||
|
extract::{Path, State},
|
||||||
|
};
|
||||||
|
use axum_extra::{
|
||||||
|
TypedHeader,
|
||||||
|
headers::{Authorization, authorization::Bearer},
|
||||||
|
};
|
||||||
|
use log::debug;
|
||||||
|
|
||||||
|
use super::VaultPath;
|
||||||
|
use crate::server::{auth::authenticate_user, responses::ServerConfigResponse};
|
||||||
|
use crate::{app_state::AppState, consts::SUPPORTED_API_VERSION, errors::SyncServerError};
|
||||||
|
|
||||||
|
#[axum::debug_handler]
|
||||||
|
pub async fn get_server_config(
|
||||||
|
maybe_auth_header: Option<TypedHeader<Authorization<Bearer>>>,
|
||||||
|
Path(VaultPath(vault_id)): Path<VaultPath>,
|
||||||
|
State(state): State<AppState>,
|
||||||
|
) -> Result<Json<ServerConfigResponse>, SyncServerError> {
|
||||||
|
debug!("Fetching configuration for vault `{vault_id}`");
|
||||||
|
|
||||||
|
let is_authenticated = maybe_auth_header.is_some_and(|auth_header| {
|
||||||
|
authenticate_user(&state, auth_header.token(), &vault_id).is_ok()
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok(Json(ServerConfigResponse {
|
||||||
|
server_version: env!("CARGO_PKG_VERSION").to_owned(),
|
||||||
|
is_authenticated,
|
||||||
|
mergeable_file_extensions: state.config.server.mergeable_file_extensions.clone(),
|
||||||
|
supported_api_version: SUPPORTED_API_VERSION,
|
||||||
|
}))
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue