mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 10:21:52 +00:00
add set-marketplace rpc
This commit is contained in:
committed by
Aiden McClelland
parent
1ef6099ab5
commit
bef09b0fb3
@@ -79,30 +79,7 @@ async fn inner_main(cfg_path: Option<&str>) -> Result<Option<Shutdown>, Error> {
|
||||
.expect("send shutdown signal");
|
||||
});
|
||||
|
||||
tokio::fs::write("/etc/nginx/sites-available/default", {
|
||||
let info = embassy::db::DatabaseModel::new()
|
||||
.server_info()
|
||||
.get(&mut rpc_ctx.db.handle(), true)
|
||||
.await?;
|
||||
format!(
|
||||
include_str!("../nginx/main-ui.conf.template"),
|
||||
lan_hostname = info.lan_address.host_str().unwrap(),
|
||||
tor_hostname = info.tor_address.host_str().unwrap()
|
||||
)
|
||||
})
|
||||
.await
|
||||
.with_ctx(|_| {
|
||||
(
|
||||
embassy::ErrorKind::Filesystem,
|
||||
"/etc/nginx/sites-available/default",
|
||||
)
|
||||
})?;
|
||||
Command::new("systemctl")
|
||||
.arg("reload")
|
||||
.arg("nginx")
|
||||
.invoke(embassy::ErrorKind::Nginx)
|
||||
.await?;
|
||||
|
||||
rpc_ctx.set_nginx_conf(&mut rpc_ctx.db.handle()).await?;
|
||||
let auth = auth(rpc_ctx.clone());
|
||||
let ctx = rpc_ctx.clone();
|
||||
let server = rpc_server!({
|
||||
|
||||
@@ -8,7 +8,7 @@ use std::time::Duration;
|
||||
|
||||
use bollard::Docker;
|
||||
use patch_db::json_ptr::JsonPointer;
|
||||
use patch_db::{PatchDb, Revision};
|
||||
use patch_db::{DbHandle, PatchDb, Revision};
|
||||
use reqwest::Url;
|
||||
use rpc_toolkit::url::Host;
|
||||
use rpc_toolkit::Context;
|
||||
@@ -16,6 +16,7 @@ use serde::Deserialize;
|
||||
use sqlx::sqlite::SqliteConnectOptions;
|
||||
use sqlx::SqlitePool;
|
||||
use tokio::fs::File;
|
||||
use tokio::process::Command;
|
||||
use tokio::sync::{broadcast, oneshot, Mutex, RwLock};
|
||||
use tracing::instrument;
|
||||
|
||||
@@ -35,7 +36,7 @@ use crate::status::{MainStatus, Status};
|
||||
use crate::system::launch_metrics_task;
|
||||
use crate::util::io::from_toml_async_reader;
|
||||
use crate::util::logger::EmbassyLogger;
|
||||
use crate::util::AsyncFileExt;
|
||||
use crate::util::{AsyncFileExt, Invoke};
|
||||
use crate::{Error, ResultExt};
|
||||
|
||||
#[derive(Debug, Default, Deserialize)]
|
||||
@@ -248,6 +249,38 @@ impl RpcContext {
|
||||
.await?
|
||||
.to_owned())
|
||||
}
|
||||
#[instrument(skip(self, db))]
|
||||
pub async fn set_nginx_conf<Db: DbHandle>(&self, db: &mut Db) -> Result<(), Error> {
|
||||
tokio::fs::write("/etc/nginx/sites-available/default", {
|
||||
let info = crate::db::DatabaseModel::new()
|
||||
.server_info()
|
||||
.get(db, true)
|
||||
.await?;
|
||||
format!(
|
||||
include_str!("../nginx/main-ui.conf.template"),
|
||||
lan_hostname = info.lan_address.host_str().unwrap(),
|
||||
tor_hostname = info.tor_address.host_str().unwrap(),
|
||||
eos_marketplace = info.eos_marketplace,
|
||||
package_marketplace = info
|
||||
.package_marketplace
|
||||
.as_ref()
|
||||
.unwrap_or(&info.eos_marketplace),
|
||||
)
|
||||
})
|
||||
.await
|
||||
.with_ctx(|_| {
|
||||
(
|
||||
crate::ErrorKind::Filesystem,
|
||||
"/etc/nginx/sites-available/default",
|
||||
)
|
||||
})?;
|
||||
Command::new("systemctl")
|
||||
.arg("reload")
|
||||
.arg("nginx")
|
||||
.invoke(crate::ErrorKind::Nginx)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
#[instrument(skip(self))]
|
||||
pub async fn shutdown(self) -> Result<(), Error> {
|
||||
self.managers.empty().await?;
|
||||
|
||||
@@ -22,6 +22,7 @@ pub mod inspect;
|
||||
pub mod install;
|
||||
pub mod logs;
|
||||
pub mod manager;
|
||||
pub mod marketplace;
|
||||
pub mod middleware;
|
||||
pub mod migration;
|
||||
pub mod net;
|
||||
@@ -75,7 +76,8 @@ pub fn main_api() -> Result<(), RpcError> {
|
||||
system::metrics,
|
||||
shutdown::shutdown,
|
||||
shutdown::restart,
|
||||
update::update_system
|
||||
update::update_system,
|
||||
marketplace::set_eos_url,
|
||||
))]
|
||||
pub fn server() -> Result<(), RpcError> {
|
||||
Ok(())
|
||||
@@ -95,6 +97,7 @@ pub fn server() -> Result<(), RpcError> {
|
||||
properties::properties,
|
||||
dependencies::dependency,
|
||||
backup::package_backup,
|
||||
marketplace::set_package_url,
|
||||
))]
|
||||
pub fn package() -> Result<(), RpcError> {
|
||||
Ok(())
|
||||
|
||||
35
appmgr/src/marketplace.rs
Normal file
35
appmgr/src/marketplace.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
use patch_db::DbHandle;
|
||||
use reqwest::Url;
|
||||
use rpc_toolkit::command;
|
||||
|
||||
use crate::context::RpcContext;
|
||||
use crate::util::display_none;
|
||||
use crate::Error;
|
||||
|
||||
#[command(rename = "set-marketplace", display(display_none))]
|
||||
pub async fn set_eos_url(#[context] ctx: RpcContext, #[arg] url: Url) -> Result<(), Error> {
|
||||
let mut db = ctx.db.handle();
|
||||
let mut tx = db.begin().await?;
|
||||
crate::db::DatabaseModel::new()
|
||||
.server_info()
|
||||
.eos_marketplace()
|
||||
.put(&mut tx, &url)
|
||||
.await?;
|
||||
ctx.set_nginx_conf(&mut tx).await?;
|
||||
tx.commit(None).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[command(rename = "set-marketplace", display(display_none))]
|
||||
pub async fn set_package_url(#[context] ctx: RpcContext, #[arg] url: Url) -> Result<(), Error> {
|
||||
let mut db = ctx.db.handle();
|
||||
let mut tx = db.begin().await?;
|
||||
crate::db::DatabaseModel::new()
|
||||
.server_info()
|
||||
.package_marketplace()
|
||||
.put(&mut tx, &Some(url))
|
||||
.await?;
|
||||
ctx.set_nginx_conf(&mut tx).await?;
|
||||
tx.commit(None).await?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -42,8 +42,12 @@ server {{
|
||||
proxy_pass http://127.0.0.1:5961/;
|
||||
}}
|
||||
|
||||
location /marketplace/ {{
|
||||
proxy_pass https://beta-registry-0-3.start9labs.com/; # TODO
|
||||
location /marketplace/eos/ {{
|
||||
proxy_pass {eos_marketplace}/eos/;
|
||||
}}
|
||||
|
||||
location /marketplace/package/ {{
|
||||
proxy_pass {package_marketplace}/package/;
|
||||
}}
|
||||
|
||||
location / {{
|
||||
|
||||
Reference in New Issue
Block a user