I need a bit of guidance

So, currently we deploy MSI's by manually incorporating some info (a token), what happens is: i get mailed a token, i add it to some xml, then run a batch file that compiles the files into an MSI. Then i return the MSI for deployment by the enduser.

I am thinking, this can be automated as well. perhaps like so: someone opens https://msiserver/reallylongtokeninformation then a rust web framework takes "reallylongtokeninformation" and puts it in an xml file, and then executes the batchfile. after which it returns the msi to the user for download?

So, would you do it like this? Or are there perhaps better ways to do this? Which framework is better for me? There are really awesome ones out there like Rocket, Tokio, Warp.. but are these suited for beginners like myself?

This seems like a very simple one-off task so basically any framework that can handle requests and send responses will be sufficient. You should probably not bother with async frameworks, for the same reason – the code will be simpler when written in a blocking style.

(I'm assuming you don't need async because if you were able to do it manually so far, then there isn't enough computation or I/O for async to result in any significant speedup.)

1 Like

indeed async is not needed, it'll be a wonder if we need to do this multiple times a day, let alone multiple times an hour :slight_smile: I would think that in essence its no different from building a simple blog? But instead of getting data from a database and return a html object, i'd run some commandline commands and return a binary object?

Indeed. Ideally, you would set up a separate temporary directory each time you handle such a request, and then clean it up once you are done. This would ensure that the batch script to be run always sees a consistent state and nothing else on the filesystem interferes with it.

1 Like

First things first, i need to create a basic webserver :slight_smile:

An alternative would be to automate your existing email-based process. You can have a static web page with an HTML form which sends its results to a mailto: url. This will ensure that the received requests are all in a standard format, and you won't have to deal with the network transport.

You can then set up a cron job on a server somewhere that periodically checks the mailbox, processes the pending requests, and emails back the resulting files.

2 Likes

okay, i found Rouille which seems easy enough :slight_smile: now i need to learn how to copy files from a source dir into a temp dir which seems easy enough when you have statics dirs, but ofcourse i want the temp dir to have the token name (to avoid problems with other cases) like so: rust docs about copy but this example uses static foldernames, i imagine i cant simply swap them out for dynamic ones?

You shouldn't name your temporary directories yourself. It's surprisingly hard to correctly (i.e., atomically, uniquely, without an attacker to be able to intervene, etc.) create temporary directories. You should likely use an existing solution for creating temporary directories with random names, e.g. tempfile::tempdir().

Why couldn't you?

1 Like

This seems nice!
Currently i have this:

#![allow(unreachable_code)]
#[macro_use]
extern crate rouille;

fn main() {
    println!("Now listening on localhost:8000");
    rouille::start_server("localhost:8000", move |request| {
        router!(request,

                (GET) (/{id: String}) => {
                // 1: copy files to temp dir
                // Create a directory inside of `std::env::temp_dir()`
                // 2: write data with id from url into xml
                // 3: run command to compile files into msi (must be done on windows)
                // 4: return the MSI for the user to download

                 // let file = File::open("test.msi").unwrap();
                 // Response::from_file("application/x-msi", file)
                 rouille::Response::text(format!("hello, {}", id))
                 },

            // The code block is called if none of the other blocks matches the request.
            // We return an empty response with a 404 status code.
            _ => rouille::Response::empty_404()
        )
    });
}

So, i would create a function (because tempdir wants to return something, i can't use it inside the (GET) block correct?) to make a temp dir, then use the standard FS tools to copy files into it, write the XML with the token in this directory, then run a batch file and use the rouille::Response::from_file to return the build MSI?

I have no idea how rouille works, but usually the point of a function (at least partially) is to return a value. I can't imagine why you couldn't call arbitrary functions in request handlers.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.