In IT, you never know when you need to quickly spin up a web server for hosting files ... One of my favorite and super easy way to do this is by leveraging Python's SimpleHTTPServer which can immediately serve files within a directory with this 1-liner:
python -m http.server 9000
This certainly beats standing up a full blown web server if you just need GET and HEAD operations.
If you do not require authentication for serving your files, then this solution fits the bill perfectly! However, if you require authentication, then I typically resort to deploying a full blown web server and use .htaccess to manage users and passwords.
For customers that have a need to host a VMware Cloud Foundation (VCF) offline depot or any VMware-based offline depot, the solution will typically require a web server due to the authentication requirements. With that said, I have recently been using an alternative method, especially if you just need to quickly host some files for say an upgrade or deployment.
I came this awesome modified version of the Python SimpleHTTPServer to easily support username and password for basic authentication, which would could be used to easily serve content to SDDC Manager. Today, VCF 5.x still requires an HTTPS endpoint and the script can be adapted to support TLS endpoint which would require certificate and private key as input.
Step 1 - Download either the original http_server_auth.py script for HTTP or this modified http_server_auth.py version (thanks to ChatGPT) for HTTPS to a system that has the Python runtime, which can even be you local workstation. I typically work on macOS, so that is perfect as I can serve the files directly from my desktop.
Step 2 - Create the necessary folder structure and content that you wish to host
Step 3 - Start the Python script with your desired parameters including the ability to specify the directory to serve the content over HTTP:
python http_server_auth.py --bind 192.168.30.4 --user vcf --password vcf123! --port 8888 --directory depot
To serve over HTTPs, you can use the following
python3 http_server_auth.py --bind 192.168.30.4 --user vcf --password vcf123! --port 443 --directory depot --certfile ~/cert.crt --keyfile ~/key.pem
If I open a web browser to that address/port, I can see I am now prompted for authentication.
Once I have successfully authenticated, I can now access the content without the need to deploy a complex web server and setup htaccess!
The next time you need to quickly host something that requires authentication, you may want to consider this quick and dirty solution!
Note: For those consuming this with VCF 5.x, if you are using a self-signed TLS certificate, you will need to also import the certificate into the SDDC Manager keystore, see this blog post for more details.
Thanks for the comment!