简体中文 | English
Here is the backend part of SEATiDE RESTful api. The backend simplifies the process of creating, starting and deleting Aliyun ECS instance for game playing, and also provides a platform for users to communicate with the database, which could be used to save Minecraft user data, user identity, levels & ranks, and so on in the not-too-distant future.
Using a secret AccessKey & AccessSecret set to manage the ECSs. Any action will be recorded as history in the database. Using type
in post requests to determine actual action. A token with administrator's permission is required to POST action api.
- POST
/api/ecs/v1/action
delete
— Forcefully delete current instance (without confirmation)new
— Create a preferred instance, then allocate a public ip for it, finally boot it.start
— Start the instancestop
— Stop the instance
- GET
/api/ecs/v1/describe/:name
available
— Check if the instance type is available to be createdinstance
— Get the detailed information of the preferred instance (type, bandwidth, disksize, zone)status
— Get the status of the current instanceprice
— Get the hourly price of the preferred instancelast-invoke
— Get the results of the last invocation (only ifdeploy
is set totrue
)
If deploy
in config.yml
is set to true
, src/run.sh
will be executed when the system is completely booted. Please make sure there is a run.sh
in src
directory before you enable deploy
. Note: You can't use ~
in run.sh
, which will lead to execution problems.
CRUD on users. Using type
to determine actual action. A token with administrator's permission is required to POST action api.
- POST
/api/user/v1/action
create
— Create a new user with 3 required arguments:username
,password
,email
get
— Get information of a user. Incompatible withpassword
delete
— Delete a useralter
— Update a user's data using a k-v structure. Incompatible withpassword
changepasswd
— Update a user's password
- POST
/api/user/v1/auth
auth
— Get login token with 7-day lifetime using username and passwordcheck
— Check if a token is valid, expired or invalid
Note: You must fill the secret
in config.yml
with random string (any value) to make it work.
Requires Python 3.8+ and MySQL This won't work under Python 3.8 (exclusive).
- Clone the repository
git clone https://github.com/seatidemc/backend.git
- (Recommended but Optional) Create a virtual environment
cd backend
python -m venv .
- Install dependencies
pip install ./requirements.txt
cd src
unzip ./localdep.zip # Edited Aliyun Python SDK Core & Ecs
- Initialize database. Just simply copy all the content in
.sql
and execute them in the MySQL command prompt. Please don't continue if there is any problem. - Rename
config.example.yml
toconfig.yml
and change its content to suit your need. Please make sure all the items marked as required are filled in properly.
mv config.example.yml config.yml
vim config.yml
- (Optional) Boot the api by running
app.py
. The type of server opening is depend on theproduction
key inconfig.yml
. If it's in production, the server will be open at port8080
, otherwise5000
.
python ./app.py