~signaryk/repomill

7594193dddad8d77a45bdb3907864ff31baebadf — William Luke 2 years ago 7a0c537 master
Cleanup to repo parsing
2 files changed, 6 insertions(+), 12 deletions(-)

M src/deploy.rs
M src/repoconf.rs
M src/deploy.rs => src/deploy.rs +4 -4
@@ 5,10 5,10 @@ use std::sync::Arc;

use crate::repoconf::RepoConf;

pub async fn process(req: Request<Body>, _rc: Arc<Vec<RepoConf>>) -> Result<Response<Body>, hyper::Error> {
pub async fn process(req: Request<Body>, _rc: Arc<HashMap<String, RepoConf>>) -> Result<Response<Body>, hyper::Error> {
    match (req.method(), req.uri().path()) {
        (&Method::GET, "/") | (&Method::GET, "/index.html") => Ok(Response::new(Body::from("Hello world\n"))),
        (&Method::POST, "/deploy") => deploy(req).await,
        (&Method::POST, "/deploy") => deploy(req, _rc).await,
        _ => {
            // Return 404 not found response.
            Ok(Response::builder()


@@ 19,11 19,11 @@ pub async fn process(req: Request<Body>, _rc: Arc<Vec<RepoConf>>) -> Result<Resp
    }
}

async fn deploy(req: Request<Body>) -> Result<Response<Body>, hyper::Error> {
async fn deploy(req: Request<Body>, _rc: Arc<HashMap<String, RepoConf>>) -> Result<Response<Body>, hyper::Error> {
    let bytes_stream = hyper::body::to_bytes(req).await?;
    let _data: HashMap<String, String> = serde_json::from_slice(&bytes_stream).unwrap();

    let res = Response::builder().status(StatusCode::default()).body(Body::from("Done.\n")).unwrap();
    let res = Response::builder().status(StatusCode::default()).body(Body::empty()).unwrap();

    Ok(res)
}
\ No newline at end of file

M src/repoconf.rs => src/repoconf.rs +2 -8
@@ 1,5 1,4 @@
use config::{Config, ConfigError, File};
use std::vec::Vec;
use std::collections::HashMap;

#[derive(Serialize, Deserialize, Debug, Clone)]


@@ 20,17 19,12 @@ pub enum RepoConf {
}

impl RepoConf {
    pub fn new() -> Result<Vec<RepoConf>, ConfigError> {
    pub fn new() -> Result<HashMap<String, RepoConf>, ConfigError> {
        let mut c = Config::default();
        c.merge(File::with_name("config").format(config::FileFormat::Yaml))?;

        let repos = c.get::<HashMap<String,RepoConf>>("repos")?;

        let mut v = Vec::<RepoConf>::new();
        for (_, rc) in repos {
            v.push(rc);
        }

        return Ok(v);
        Ok(repos)
    }   
}
\ No newline at end of file