Skip to content

adempiere/s3_gateway_rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Microservice with S3 gateway for Rust

A microservice that publish a Rest API based on salvo.rs

Run Docker Compose (Easy way)

You can run it with docker compose for develop enviroment, the complete services are:

  • S3 Service
  • S3 Gateway Service

Requirements

docker compose version
Docker Compose version v2.16.0

Run it

Just clone it

git clone https://github.com/adempiere/s3_gateway_rs
cd s3_gateway_rs/docker-compose
docker compose up

You can use the -d parameter to release the terminal.

docker compose up -d

Requirements

  • Just install rust from page
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Production Requirements

apt install pkg-config openssl libssl-dev

Getting Started

Deploy with docker

You can build images using the follow command

docker build -t s3-gateway-rs -f docker/Dockerfile .

After build just run it

docker run -d -p 7878:7878 --name s3-gateway-rs -e S3_URL="http://localhost:9000" -e BUCKET_NAME="adempiere" -e API_KEY="adempiere" -e SECRET_KEY="adempiere" -e MANAGE_HTTPS="N" s3-gateway-rs

Environment variables

  • PORT: Internal port for container. Default: 7878.
  • ALLOWED_ORIGIN: Define all allowed origins. Default: *.
  • S3_URL: The S3 URL to connect. Default: http://localhost:9000
  • BUCKET_NAME: The bucket name created on S3 service. Default: - fill it.
  • API_KEY: API Key created on S3 service. Default: - fill it.
  • SECRET_KEY: Secret Key created on S3 service. Default: - fill it.
  • MANAGE_HTTPS: Determine if use https, note that this flag is Y or N. Default: N
  • SSL_CERT_FILE: File path to Cert File, use this if the MANAGE_HTTPS is enabled. Default: /opt/apps/server/cacert.pem
  • RUST_LOG: The log level for service. Default info.
  • TZ: (Time Zone) Indicates the time zone to set in the nginx-based container, the default value is America/Caracas (UTC -4:00).
  • VERSION: This is automatically set with the version of the image construction, it can be overwritten but is not recommended.

Running project

Just build it and run

cargo build
cargo run --bin server

Console Output

A output generated by the Arduino UNO emulator can be like it:

Server Address: "0.0.0.0:7878"
└──!NULL!
    └──api
        ├──[OPTIONS] -> server::options_response
        ├──[GET] -> server::get_system_info
        ├──resources
        │   ├──[OPTIONS] -> server::options_response
        │   ├──[GET] -> server::get_resources_file_container_based
        │   └──<**file_name>
        │       ├──[OPTIONS] -> server::options_response
        │       ├──[GET] -> server::get_resource
        │       └──[DELETE] -> server::delete_resource
        ├──download-url/<**file_name>
        │   ├──[OPTIONS] -> server::options_response
        │   └──[GET] -> server::get_presigned_url_download_file
        └──presigned-url/<client_id>
            ├──<file_name>
            │   ├──[OPTIONS] -> server::options_response
            │   └──[GET] -> server::get_presigned_url_put_file_container_based
            └──<container_id>/<file_name>
                ├──[OPTIONS] -> server::options_response
                └──[GET] -> server::get_presigned_url_put_file_container_based

General Info

Using SSL

A test case to connect with a S3 service using SSL connection like Digital Ocean can be running with follow commands:

Download Certificate

The SSL connection is supported but you must implement your own certificate or download any like this:

curl -o cacert.pem https://curl.se/ca/cacert.pem

Running Container

docker run -d -p 7878:7878 --name do-s3-gateway-rs -e S3_URL="nyc3.digitaloceanspaces.com" -e BUCKET_NAME="shift" -e API_KEY="<Your_API_Key>" -e SECRET_KEY="<Your_Secret_Key>" -e MANAGE_HTTPS="Y" -e SSL_CERT_FILE="<Internal_Cert_Path>" -v <Local_Cert_Path>:<Internal_Cert_Path> do-s3-gateway-rs

Testing OpenSearch

For test it just run a CURL like this:

curl -L -X GET 'http://localhost:7878/api/presignedUrl?file_name=File.txt'

The response:

"http://localhost:9000/test/File.txt?X-Amz-Signature=855063e40b4d606351c4698f1b85bf3e4ba9af320ddd31b65619ddfd5dde0766&X-Amz-Credential=QrhtkEZoeiO4NsI3VQ7j%2F20240201%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240201T192400Z&X-Amz-SignedHeaders=host&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Expires=604800"

For the upload resousrce

curl -L -X PUT 'http://localhost:9000/test/File.txt?X-Amz-Signature=855063e40b4d606351c4698f1b85bf3e4ba9af320ddd31b65619ddfd5dde0766&X-Amz-Credential=QrhtkEZoeiO4NsI3VQ7j%2F20240201%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240201T192400Z&X-Amz-SignedHeaders=host&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Expires=604800' \
--data-binary '@/File.txt'

For get resource

curl -L -X GET 'http://localhost:7878/api/resources/File.txt'

A complete doc here

The exported Postman file can be used from here

To review the library source just click here