mirror of
https://github.com/sergi0g/cup.git
synced 2025-11-16 09:03:46 -05:00
Add agent mode, fix config version bug
This commit is contained in:
@@ -10,6 +10,10 @@
|
|||||||
"minimum": 3,
|
"minimum": 3,
|
||||||
"maximum": 3
|
"maximum": 3
|
||||||
},
|
},
|
||||||
|
"agent": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "Whether or not to enable agent mode. When agent mode is enabled, the server only exposes the API and the web interface is unavailable."
|
||||||
|
},
|
||||||
"registries": {
|
"registries": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"description": "Configuration options for specific registries",
|
"description": "Configuration options for specific registries",
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ pub struct ImageConfig {
|
|||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
version: u8,
|
version: u8,
|
||||||
|
pub agent: bool,
|
||||||
pub registries: FxHashMap<String, RegistryConfig>,
|
pub registries: FxHashMap<String, RegistryConfig>,
|
||||||
pub images: ImageConfig,
|
pub images: ImageConfig,
|
||||||
pub theme: Theme,
|
pub theme: Theme,
|
||||||
@@ -51,6 +52,7 @@ impl Config {
|
|||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
version: 3,
|
version: 3,
|
||||||
|
agent: false,
|
||||||
registries: FxHashMap::default(),
|
registries: FxHashMap::default(),
|
||||||
images: ImageConfig::default(),
|
images: ImageConfig::default(),
|
||||||
theme: Theme::Default,
|
theme: Theme::Default,
|
||||||
@@ -79,7 +81,7 @@ impl Config {
|
|||||||
Ok(config) => config,
|
Ok(config) => config,
|
||||||
Err(e) => error!("Unexpected error occured while parsing config: {}", e),
|
Err(e) => error!("Unexpected error occured while parsing config: {}", e),
|
||||||
};
|
};
|
||||||
if config.version != 2 {
|
if config.version != 3 {
|
||||||
error!("You are trying to run Cup with an incompatible config file! Please migrate your config file to the version 3, or if you have already done so, add a `version` key with the value `3`.")
|
error!("You are trying to run Cup with an incompatible config file! Please migrate your config file to the version 3, or if you have already done so, add a `version` key with the value `3`.")
|
||||||
}
|
}
|
||||||
config
|
config
|
||||||
|
|||||||
@@ -36,14 +36,18 @@ pub async fn serve(port: &u16, config: &Config) -> std::io::Result<()> {
|
|||||||
info!("Starting server, please wait...");
|
info!("Starting server, please wait...");
|
||||||
let data = ServerData::new(config).await;
|
let data = ServerData::new(config).await;
|
||||||
info!("Ready to start!");
|
info!("Ready to start!");
|
||||||
App::new()
|
let mut app_builder = App::new()
|
||||||
.with_state(Arc::new(Mutex::new(data)))
|
.with_state(Arc::new(Mutex::new(data)))
|
||||||
.at("/", get(handler_service(_static)))
|
|
||||||
.at("/api/v2/json", get(handler_service(api_simple)))
|
.at("/api/v2/json", get(handler_service(api_simple)))
|
||||||
.at("/api/v3/json", get(handler_service(api_full)))
|
.at("/api/v3/json", get(handler_service(api_full)))
|
||||||
.at("/api/v2/refresh", get(handler_service(refresh)))
|
.at("/api/v2/refresh", get(handler_service(refresh)))
|
||||||
.at("/api/v3/refresh", get(handler_service(refresh)))
|
.at("/api/v3/refresh", get(handler_service(refresh)));
|
||||||
.at("/*", get(handler_service(_static)))
|
if !config.agent {
|
||||||
|
app_builder = app_builder
|
||||||
|
.at("/", get(handler_service(_static)))
|
||||||
|
.at("/*", get(handler_service(_static)));
|
||||||
|
}
|
||||||
|
app_builder
|
||||||
.enclosed(Logger::new())
|
.enclosed(Logger::new())
|
||||||
.serve()
|
.serve()
|
||||||
.bind(format!("0.0.0.0:{}", port))?
|
.bind(format!("0.0.0.0:{}", port))?
|
||||||
|
|||||||
Reference in New Issue
Block a user