A microservice that publish a Rest API based on salvo.rs
You can run it with docker compose
for develop enviroment, the complete services are:
- S3 Service
- S3 Gateway Service
docker compose version
Docker Compose version v2.16.0
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
- Just install rust from page
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
apt install pkg-config openssl libssl-dev
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
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 isY
orN
. Default:N
SSL_CERT_FILE
: File path to Cert File, use this if theMANAGE_HTTPS
is enabled. Default:/opt/apps/server/cacert.pem
RUST_LOG
: The log level for service. Defaultinfo
.TZ
: (Time Zone) Indicates the time zone to set in the nginx-based container, the default value isAmerica/Caracas
(UTC -4:00).VERSION
: This is automatically set with the version of the image construction, it can be overwritten but is not recommended.
Just build it and run
cargo build
cargo run --bin server
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
A test case to connect with a S3 service using SSL connection like Digital Ocean can be running with follow commands:
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
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
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