Skip to content

Commit

Permalink
add a web UI for S3 (with auth support) (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
maminrayej authored Nov 18, 2024
2 parents 52c27f7 + a36c4d6 commit 407cca3
Show file tree
Hide file tree
Showing 15 changed files with 1,944 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/wasix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
cargo install cargo-wasix
- name: "Download Toolchain"
run: |
cargo wasix download-toolchain v2024-06-26.1
cargo wasix download-toolchain
- name: "Build"
run: |
cargo wasix build --features=binary --release --bin s3-server
Expand Down Expand Up @@ -84,4 +84,4 @@ jobs:
ls
- name: "Push"
run: |
wasmer package push --registry="wasmer.io" --non-interactive --token=${{ secrets.WASMER_CIUSER_PROD_TOKEN }} .
wasmer package push --registry="wasmer.io" --non-interactive --token=${{ secrets.WASMER_CIUSER_PROD_TOKEN }} .
16 changes: 16 additions & 0 deletions app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
kind: wasmer.io/App.v0
name: s3-server
owner: ayysadmin
package: .
domains:
- s3-demo.wasmer.app

volumes:
- name: bucket-1
mounts:
- mount_path: /bucket-1
- mount_path: /bucket-2

env:
PORT: '80'
app_id: da_RrWI0t5UGpZ2
1 change: 1 addition & 0 deletions bucket-1/1722536833
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fri Aug 2 12:12:13 AM +0545 2024
1 change: 1 addition & 0 deletions bucket-1/dir with spaces/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Hello</h1>
1 change: 1 addition & 0 deletions bucket-1/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Hey there!</h1>
1 change: 1 addition & 0 deletions bucket-1/test-dir/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Hello</h1>
5 changes: 5 additions & 0 deletions bucket-2/mint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
docker run \
-e "SERVER_ENDPOINT=localhost:8080" \
-e "ACCESS_KEY=AKIAIOSFODNN7EXAMPLE" -e "SECRET_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" \
--network host \
minio/mint:latest
16 changes: 16 additions & 0 deletions bucket-2/s3-server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
DATA_DIR="./"

if [ -n "$1" ]; then
DATA_DIR="$1"
fi

RELEASE=""
if [ "$2" == "--release" ]; then
RELEASE="--release"
fi

cargo run $RELEASE --features binary \
-- \
--access-key AKIAIOSFODNN7EXAMPLE \
--secret-key wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY \
--fs-root $DATA_DIR
4 changes: 2 additions & 2 deletions scripts/wasix-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

set -xe

wasmer run --net --mapdir /data:tests/data/ s3-server.wasm -- --fs-root /data --access-key access-key-id --secret-key secret-access-key &
wasmer run --net --mapdir /data:tests/data/ s3-server.wasm -- --fs-root /data --access-key access-key-id --secret-key secret-access-key --port 8080 &

cargo test --package s3-server --test rclone -- --show-output

pkill wasmer
pkill wasmer
27 changes: 17 additions & 10 deletions src/bin/s3-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//! --fs-root <fs-root> [default: .]
//! --host <host> [default: localhost]
//! --port <port> [default: 8080]
//! --access-key <access-key>
//! --access-key <access-key>
//! --secret-key <secret-key>
//! ```

Expand All @@ -36,19 +36,29 @@ use tracing::{debug, info};

#[derive(StructOpt)]
struct Args {
#[structopt(long, default_value = ".")]
#[structopt(long, default_value = "/s3", env = "WASMER_APP_S3_FS_ROOT")]
fs_root: PathBuf,

#[structopt(long, default_value = "localhost")]
#[structopt(long, default_value = "localhost", env = "WASMER_APP_S3_HOST")]
host: String,

#[structopt(long, default_value = "8080")]
#[structopt(long, default_value = "80", env = "WASMER_APP_S3_PORT")]
port: u16,

#[structopt(long, requires("secret-key"), display_order = 1000)]
#[structopt(
long,
requires("secret-key"),
display_order = 1000,
env = "WASMER_APP_S3_ACCESS_KEY"
)]
access_key: Option<String>,

#[structopt(long, requires("access-key"), display_order = 1000)]
#[structopt(
long,
requires("access-key"),
display_order = 1000,
env = "WASMER_APP_S3_SECRET_KEY"
)]
secret_key: Option<String>,

#[structopt(flatten)]
Expand Down Expand Up @@ -111,10 +121,7 @@ async fn main() -> Result<()> {
service.set_auth(auth);
}

s3_server::DISALLOW_BUCKET_MANIPULATION.store(
!args.allow_bucket_manipulation,
std::sync::atomic::Ordering::Relaxed,
);
s3_server::DISALLOW_BUCKET_MANIPULATION.store(false, std::sync::atomic::Ordering::Relaxed);

let server = {
let service = service.into_shared();
Expand Down
Loading

0 comments on commit 407cca3

Please sign in to comment.