Clean up some warnings from rustc
This commit is contained in:
parent
c256be98d8
commit
705a7fffa9
@ -18,7 +18,7 @@ dotenv = "~0.15"
|
||||
driftwood = "0"
|
||||
# Command line parsing
|
||||
gumdrop = "0.8"
|
||||
handlebars = { version = "3", features = ["dir_source"] }
|
||||
handlebars = { version = "4", features = ["dir_source"] }
|
||||
html-escape = "0.2"
|
||||
log = "~0.4.8"
|
||||
# Needed for GitHub API calls
|
||||
|
@ -27,9 +27,7 @@ mod routes {
|
||||
use crate::caps::*;
|
||||
use crate::*;
|
||||
use janky::{CommandRequest, CommandResponse};
|
||||
use log::*;
|
||||
use tide::{Body, Request, Response, StatusCode};
|
||||
use url::Url;
|
||||
use uuid::Uuid;
|
||||
|
||||
use std::path::Path;
|
||||
@ -58,7 +56,7 @@ mod routes {
|
||||
// Create my log directory
|
||||
let log_dir = Path::new(AGENT_LOGS_DIR).join(uuid.hyphenated().to_string());
|
||||
// TODO: Handle this error
|
||||
std::fs::create_dir(log_dir.clone());
|
||||
std::fs::create_dir(log_dir.clone()).expect("Failed to create log dir");
|
||||
|
||||
let log_file_path = log_dir.join("console.log");
|
||||
let work = Work {
|
||||
@ -66,7 +64,7 @@ mod routes {
|
||||
log_file: log_file_path.clone(),
|
||||
command: c,
|
||||
};
|
||||
req.state().channel.send(work).await;
|
||||
req.state().channel.send(work).await?;
|
||||
|
||||
let response = CommandResponse {
|
||||
uuid,
|
||||
@ -129,7 +127,6 @@ async fn worker(receiver: Receiver<Work>) {
|
||||
for command in work.command.commands.iter() {
|
||||
debug!("Command: {:?}", command);
|
||||
use os_pipe::pipe;
|
||||
use std::io::{BufRead, BufReader, Write};
|
||||
use std::process::Command;
|
||||
let mut cmd = Command::new("sh");
|
||||
cmd.args(["-xec", &command.script]);
|
||||
@ -141,7 +138,7 @@ async fn worker(receiver: Receiver<Work>) {
|
||||
drop(cmd);
|
||||
|
||||
debug!("executing: {}", &command.script);
|
||||
std::io::copy(&mut reader, &mut bufw);
|
||||
std::io::copy(&mut reader, &mut bufw).expect("Failed to copy streams");
|
||||
|
||||
let status = handle.wait().expect("Failed to wait on handle");
|
||||
debug!("status of {}: {:?}", &command.script, status);
|
||||
@ -174,7 +171,7 @@ async fn main() -> Result<(), tide::Error> {
|
||||
|
||||
debug!("Configuring routes");
|
||||
app.at("/").get(routes::index);
|
||||
app.at("/agent-logs").serve_dir(AGENT_LOGS_DIR);
|
||||
app.at("/agent-logs").serve_dir(AGENT_LOGS_DIR)?;
|
||||
routes::api::register(&mut app);
|
||||
app.listen("0.0.0.0:9000").await?;
|
||||
Ok(())
|
||||
|
@ -27,15 +27,20 @@ pub struct AppState<'a> {
|
||||
|
||||
impl AppState<'_> {
|
||||
fn new(db: SqlitePool, config: ServerConfig) -> Self {
|
||||
let mut hb = Handlebars::new();
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
hb.set_dev_mode(true);
|
||||
|
||||
Self {
|
||||
db,
|
||||
config,
|
||||
agents: vec![],
|
||||
hb: Arc::new(RwLock::new(Handlebars::new())),
|
||||
hb: Arc::new(RwLock::new(hb)),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn register_templates(&self) -> Result<(), handlebars::TemplateFileError> {
|
||||
pub async fn register_templates(&self) -> Result<(), handlebars::TemplateError> {
|
||||
let mut hb = self.hb.write().await;
|
||||
hb.clear_templates();
|
||||
hb.register_templates_directory(".hbs", "views")
|
||||
@ -46,14 +51,6 @@ impl AppState<'_> {
|
||||
name: &str,
|
||||
data: &serde_json::Value,
|
||||
) -> Result<tide::Body, tide::Error> {
|
||||
/*
|
||||
* In debug mode, reload the templates on ever render to avoid
|
||||
* needing a restart
|
||||
*/
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
self.register_templates().await;
|
||||
}
|
||||
let hb = self.hb.read().await;
|
||||
let view = hb.render(name, data)?;
|
||||
Ok(tide::Body::from_string(view))
|
||||
@ -68,7 +65,6 @@ impl AppState<'_> {
|
||||
*/
|
||||
mod routes {
|
||||
use crate::AppState;
|
||||
use log::*;
|
||||
use tide::{Body, Request};
|
||||
|
||||
/**
|
||||
@ -86,9 +82,9 @@ mod routes {
|
||||
}
|
||||
|
||||
pub mod api {
|
||||
use crate::{AppState, JankyYml, Scm};
|
||||
use log::*;
|
||||
use tide::{Body, Request, Response, StatusCode};
|
||||
use crate::{AppState, JankyYml, Scm};
|
||||
use tide::{Request, Response, StatusCode};
|
||||
|
||||
/**
|
||||
* POST /projects/{name}
|
||||
@ -133,7 +129,7 @@ mod routes {
|
||||
.collect();
|
||||
let commands = janky::CommandRequest { commands };
|
||||
let client = reqwest::Client::new();
|
||||
let res = client
|
||||
let _res = client
|
||||
.put(
|
||||
agent
|
||||
.url
|
||||
@ -282,7 +278,7 @@ async fn main() -> Result<(), tide::Error> {
|
||||
});
|
||||
}
|
||||
|
||||
state.register_templates().await;
|
||||
state.register_templates().await.expect("Failed to register handlebars templates");
|
||||
let mut app = tide::with_state(state);
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
|
Loading…
Reference in New Issue
Block a user