From 84916ad9d5b546d9f4dcfb9bc1ecf96805fb777c Mon Sep 17 00:00:00 2001 From: Aiden McClelland Date: Thu, 5 Aug 2021 16:50:12 -0600 Subject: [PATCH] minor fixes, add nginx conf --- appmgr/nginx.conf | 104 +++++++++++++++++++++++++++++++++++++++ appmgr/src/db/mod.rs | 56 +++++++++++---------- appmgr/src/lib.rs | 1 + appmgr/src/status/mod.rs | 1 + 4 files changed, 135 insertions(+), 27 deletions(-) create mode 100644 appmgr/nginx.conf diff --git a/appmgr/nginx.conf b/appmgr/nginx.conf new file mode 100644 index 000000000..d820868fd --- /dev/null +++ b/appmgr/nginx.conf @@ -0,0 +1,104 @@ +## +# You should look at the following URL's in order to grasp a solid understanding +# of Nginx configuration files in order to fully unleash the power of Nginx. +# https://www.nginx.com/resources/wiki/start/ +# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/ +# https://wiki.debian.org/Nginx/DirectoryStructure +# +# In most cases, administrators will remove this file from sites-enabled/ and +# leave it as reference inside of sites-available where it will continue to be +# updated by the nginx packaging team. +# +# This file will automatically load configuration files provided by other +# applications, such as Drupal or Wordpress. These applications will be made +# available underneath a path with that package name, such as /drupal8. +# +# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples. +## + +# Default server configuration +# +server { + listen 80 default_server; + listen [::]:80 default_server; + + # SSL configuration + # + # listen 443 ssl default_server; + # listen [::]:443 ssl default_server; + # + # Note: You should disable gzip for SSL traffic. + # See: https://bugs.debian.org/773332 + # + # Read up on ssl_ciphers to ensure a secure configuration. + # See: https://bugs.debian.org/765782 + # + # Self signed certs generated by the ssl-cert package + # Don't use them in a production server! + # + # include snippets/snakeoil.conf; + + root /var/www/html; + + # Add index.php to the list if you are using PHP + index index.html index.htm index.nginx-debian.html; + + server_name _; + + proxy_request_buffering off; + + location /rpc { + proxy_pass http://localhost:5959/; + } + + location /ws/ { + proxy_pass http://localhost:5960/; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + } + + location / { + # First attempt to serve request as file, then + # as directory, then fall back to displaying a 404. + try_files $uri $uri/ =404; + } + + # pass PHP scripts to FastCGI server + # + #location ~ \.php$ { + # include snippets/fastcgi-php.conf; + # + # # With php-fpm (or other unix sockets): + # fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; + # # With php-cgi (or other tcp sockets): + # fastcgi_pass 127.0.0.1:9000; + #} + + # deny access to .htaccess files, if Apache's document root + # concurs with nginx's one + # + #location ~ /\.ht { + # deny all; + #} +} + + +# Virtual Host configuration for example.com +# +# You can move that to a different file under sites-available/ and symlink that +# to sites-enabled/ to enable it. +# +#server { +# listen 80; +# listen [::]:80; +# +# server_name example.com; +# +# root /var/www/example.com; +# index index.html; +# +# location / { +# try_files $uri $uri/ =404; +# } +#} diff --git a/appmgr/src/db/mod.rs b/appmgr/src/db/mod.rs index 8d089d94a..2fcb2611f 100644 --- a/appmgr/src/db/mod.rs +++ b/appmgr/src/db/mod.rs @@ -11,7 +11,7 @@ use rpc_toolkit::command; use rpc_toolkit::hyper::upgrade::Upgraded; use rpc_toolkit::hyper::{Body, Error as HyperError, Request, Response}; use rpc_toolkit::yajrc::RpcError; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use serde_json::Value; use tokio::task::JoinError; use tokio_tungstenite::tungstenite::Message; @@ -19,7 +19,8 @@ use tokio_tungstenite::WebSocketStream; pub use self::model::DatabaseModel; use self::util::WithRevision; -use crate::context::RpcContext; +use crate::context::{EitherContext, RpcContext}; +use crate::util::{display_serializable, IoFormat}; use crate::{Error, ResultExt}; async fn ws_handler< @@ -67,24 +68,28 @@ pub async fn subscribe(ctx: RpcContext, req: Request) -> Result Result { +#[command(subcommands(revisions, dump, put))] +pub fn db(#[context] ctx: EitherContext) -> Result { Ok(ctx) } -#[derive(Serialize)] +#[derive(Deserialize, Serialize)] #[serde(untagged)] pub enum RevisionsRes { Revisions(Vec>), Dump(Dump), } -#[command(rpc_only)] +#[command(display(display_serializable))] pub async fn revisions( - #[context] ctx: RpcContext, + #[context] ctx: EitherContext, #[arg] since: u64, + #[allow(unused_variables)] + #[arg(long = "format")] + format: Option, ) -> Result { - let cache = ctx.revision_cache.read().await; + let rpc_ctx = ctx.as_rpc().unwrap(); + let cache = rpc_ctx.revision_cache.read().await; if cache .front() .map(|rev| rev.id <= since + 1) @@ -99,40 +104,37 @@ pub async fn revisions( )) } else { drop(cache); - Ok(RevisionsRes::Dump(ctx.db.dump().await)) + Ok(RevisionsRes::Dump(rpc_ctx.db.dump().await)) } } -#[command(rpc_only)] -pub async fn dump(#[context] ctx: RpcContext) -> Result { - Ok(ctx.db.dump().await) +#[command(display(display_serializable))] +pub async fn dump( + #[context] ctx: EitherContext, + #[allow(unused_variables)] + #[arg(long = "format")] + format: Option, +) -> Result { + Ok(ctx.as_rpc().unwrap().db.dump().await) } #[command(subcommands(ui))] -pub fn put(#[context] ctx: RpcContext) -> Result { +pub fn put(#[context] ctx: EitherContext) -> Result { Ok(ctx) } -#[command(rpc_only)] +#[command(display(display_serializable))] pub async fn ui( - #[context] ctx: RpcContext, + #[context] ctx: EitherContext, #[arg] pointer: JsonPointer, #[arg] value: Value, + #[allow(unused_variables)] + #[arg(long = "format")] + format: Option, ) -> Result, RpcError> { let ptr = "/ui".parse::()? + &pointer; Ok(WithRevision { response: (), - revision: ctx.db.put(&ptr, &value, None).await?, - }) -} - -#[command(rpc_only)] -pub async fn patch( - #[context] ctx: RpcContext, - #[arg] patch: DiffPatch, -) -> Result, RpcError> { - Ok(WithRevision { - response: (), - revision: ctx.db.apply(patch, None, None).await?, + revision: ctx.as_rpc().unwrap().db.put(&ptr, &value, None).await?, }) } diff --git a/appmgr/src/lib.rs b/appmgr/src/lib.rs index bdf0261e0..9db2b1826 100644 --- a/appmgr/src/lib.rs +++ b/appmgr/src/lib.rs @@ -62,6 +62,7 @@ pub fn echo(#[context] _ctx: EitherContext, #[arg] message: String) -> Result Result { Ok(ctx) diff --git a/appmgr/src/status/mod.rs b/appmgr/src/status/mod.rs index af15b130c..6f64a37a5 100644 --- a/appmgr/src/status/mod.rs +++ b/appmgr/src/status/mod.rs @@ -193,6 +193,7 @@ pub async fn check_all(ctx: &RpcContext) -> Result<(), Error> { } #[derive(Clone, Debug, Deserialize, Serialize, HasModel)] +#[serde(rename_all = "kebab-case")] pub struct Status { pub configured: bool, pub main: MainStatus,