This repository contains the REST API created for the createstructure service.
To get more info about how it works and how can you can contribute, please go to the wiki.
โโโ bin # PHP source code
โย ย โโโ config # configuration file where to store passwords, tokens, ...
โย ย โย ย โโโ database.php
โย ย โย ย โโโ key.php
โย ย โย ย โโโ webhook.php
โย ย โโโ core # main part of the REST API
โย ย โย ย โโโ action.php # interface for any of the other actions
โย ย โย ย โโโ auth.php
โย ย โย ย โโโ create_repo.php
โย ย โย ย โโโ create_server.php
โย ย โย ย โโโ help.php
โย ย โย ย โโโ server_get_job_info.php
โย ย โย ย โโโ server_get_priority.php
โย ย โย ย โโโ server_reserve_job.php
โย ย โย ย โโโ server_set_job_done.php
โย ย โย ย โโโ server_set_priority.php
โย ย โย ย โโโ server_set_priority_done.php
โย ย โย ย โโโ splitter.php # where the request is splitted to the needed action
โย ย โย ย โโโ welcome.php
โย ย โโโ index.php
โย ย โโโ webhook.php
โโโ db # DB utilities
โย ย โโโ database.sql
โย ย โโโ functions-procedures # folder containing all the needed functions and procedures
โย ย โย ย โโโ CreateRepo.sql
โย ย โย ย โโโ CreateServer.sql
โย ย โย ย โโโ CreateUpdateRemoveClient.sql
โย ย โย ย โโโ GetClient.sql
โย ย โย ย โโโ ServerGetJobInfo.sql
โย ย โย ย โโโ ServerGetPriority.sql
โย ย โย ย โโโ ServerGetPublicKey.sql
โย ย โย ย โโโ ServerReserveJob.sql
โย ย โย ย โโโ ServerSetJobDone.sql
โย ย โย ย โโโ ServerSetPriority.sql
โย ย โย ย โโโ ServerSetPriorityDone.sql
โย ย โโโ tables # DB tables definition
โย ย โโโ client.sql
โย ย โโโ client_account.sql
โย ย โโโ client_accounts_type.sql
โย ย โโโ repo_declaration.sql
โย ย โโโ repo_log.sql
โย ย โโโ repo_status.sql
โย ย โโโ server_list.sql
โย ย โโโ server_priority_declaration.sql
โย ย โโโ server_priority_instructions.sql
โย ย โโโ server_priority_log.sql
โย ย โโโ server_priority_status.sql
โย ย โโโ server_secrets.sql
โโโ docs # documentation
โโโ CHANGELOG.md
โโโ ERD.svg
โโโ LICENSE
โโโ README.md
โโโ rest-createstructure-Class-UML.svg
โโโ rest-createstructure-ER.svg
โโโ rest-createstructure.drawio
7 directories, 49 files
| name | type | action | request | URL | response | notes |
|---|---|---|---|---|---|---|
| Welcome | POST | Returns a random welcome message | {"request": "welcome"} | / | {"code": , "message": <random_welcome_message>} |
Basic request |
| Help | POST | Returns a message to help user to use this API | {"request": "help"} or {} | / | {"code": , "message": <help_generic_message>, "help": {<REST_command_name>: {"name": <REST_command_name>, "type": <GET_or_POST>, "action": , "request": <request_structure>, "URL": <REST_URL>, "response": <response_structure>, "notes": }, ...}} |
Gives to the user all the information to use this REST API |
| Auth | POST | Check if account is it ok | {"request": "login", "payload": {"username": <GitHub_username>, "token": <Github_token>}} | / | {"code": , "message": <ok_or_error_message>, "sub_info": {"name": <sub_name>, "active": <true/false>, "super": <true/false>, "max": {"day": <max_usages_for_day>, "h": <max_usages_for_hour>, "m": <max_usages_for_minute>}, "remaining": {"day": <remaining_usages_for_day>, "h": <remaining_usages_for_hour>, "m": <remaining_usages_for_minute>}}} |
This is userfull to get any usefull info about a consumer |
| Create Repository | POST | Permits user to create a repository | {"request": "create_repo", payload: {"token": <GitHub_token>, "username": <GitHub_username>, "answers": { "name": <New_repo_name> [, "template": <Template_to_use(eg. default or Owner/repo-template)>] [, "descr": ] [, "prefix": <The_prefix_of_the_repo(if you want once)>] [, "private": <true/false>] [, "isOrg": <If_you_want_your_repo_in_an_organization(true/false)> , "org": <Name_of_the_org_if_isOrg_true> [, "team": <The_name_of_the_team_if_isOrg_true>] ]}}} | / | {"code": , "message": <response_message>} |
This REST API call permits to the consumer to ask to createstructure"s service to create a repository |
| Create Server | POST | Permits to add a server to valid ones | {"request": "create_server", payload: {"token": <GitHub_token>, "username": <GitHub_username>, "server_name": <server_name>, "server_password": <server_password>, "server_description": <server_description>, "server_public_key": <server_public_key>} | / | {"code": , "message": <response_message>} |
This REST API call permits to add a server to valid ones, so it can start to contribute to the project |
| Reserve a new repo to create (server-side) | POST | functionality | {"request": "server_reserve_job", "server_name": <server_name>, "server_password": <server_password>} | / | {"code": , "message": <response_message>, "repoID": } |
Usefull for the server to reserve a repo to create it |
| Get a new repo info to create it (server-side) | POST | functionality | {"request": "server_get_job_info", "server_name": <server_name>, "server_password": <server_password>, "repoID": } | / | {"code": , "message": <response_message>, "repo_info": <repo_info>} |
Usefull for the server to ask a repo info to create it |
| Set a repo job as done (server-side) | POST | functionality | {"request": "server_set_job_done", "server_name": <server_name>, "server_password": <server_password>, "repoID": } | / | {"code": , "message": <response_message>} |
Usefull for the server to set repo job as done |
| Set a new server priority (server-side) | POST | functionality | {"request": "server_set_priority", "username": <GitHub_username>, "token": <Github_token>, "server_name": <server_name>, "server_priority": <server_priority>} | / | {"code": , "message": <response_message>} |
Ask to do some commands to a server without ssh |
| Get a priority if there was one (server-side) | POST | functionality | {"request": "server_get_priority", "server_name": <server_name>, "server_password": <server_password>} | / | {"code": , "message": <response_message> [, "priority_instruction": <priority_instruction>, "priorityID": ]} |
Usefull for the server to get the priority |
| Set a repo job as done (server-side) | POST | functionality | {"request": "server_set_priority_done", "server_name": <server_name>, "server_password": <server_password>, "priorityID": } | / | {"code": , "message": <response_message>} |
Usefull to set priority as done |
Repo containing the public part of the REST/API
- Optimized code and fixed few bugs
- v10-beta (rest-createstructure)
- Now usernames can have "-" inside
- Fixed a bug in esec_elem.php file
- Now you can use your own temlpate :happy:
- Fixed release action
- Initial version for this repo
Install the REST API locally permits you to do some debug and try new configurations.
ATTENTION
Some features, like subscription with GitHub marketplace, can't be done with the local configuration.
To do these actions you need to run manually the functions, in the previous example
CreateUpdateRemoveClient
- Install VirtualBox on the PC
- Install Ubuntu
- Install dependencies
- Add PHP source code
- Create server
- Use REST API
- Do the changes/ debug you want
For installation we suggest VirtualBox, a tool that allows you to create one or more virtual machines ๐ป. If any of these crashes, in any case, your PC will not lose data, at most you will have to restart it ๐.
To install VirtualBox on your PC you need to:
- Get in into the UEFI
- Enable the function which name is like "Virtualization" (for each UEFI this step is different but similar)
- Save the configuration and restart the PC
- Go to the VirtualBox website
- Press "Download"
- Run the downloaded file
- Follow the installation steps
As the OS we suggest to use Ubuntu, because it is lightweight (for RAM and CPU) and it's free.
To install Ubuntu on VirtualBox you need to:
- Download the last LTS version of Ubuntu by the following link: https://ubuntu.com/download/desktop
Now you can continue with the other steps during the download
- Open VirtualBox
- Press "New"
- Compile the form
- As name put "rest-createstructure"
- As Type: "Linux"
- As version: "Ubuntu (64-bit)" or "Ubuntu (32-bit)"
- Press "Next >"
- Set the RAM to use for the VirtualMachine, at most half of local RAM and press "Next >"
- Leave "Create a virtual hard disk now" and press "Create"
- Leave "VDI ..." and press "Next >"
- Leave "Dynamically allocated" and press "Next >"
- Change the hard disk memory, we suggest 16GB and press "Create"
Make sure that Ubuntu download is finished before to continue
- On the VirtualBox console, selecting the created VM, press "Start"
- Select as start-up disk Ubuntu, already downloaded
- Press the folder icon
- Press "Add", in the top menu
- Select the Ubuntu iso, the file will have a structure like "ubuntu-version-other_info.iso"
- Press "Choose" and "Start"
- Follow the install steps (the installation needs some minutes)
Now you have to install lamp (Linux Apache MySQL (DB) PHP) on the VM.
We suggest you to open this guide on the virtual machine, so you can copy and paste easlier the following commands.
To install Dependes on the Virtual Machine you need to:
- On the VM (Virtual Machine) open the terminal (
Ctrl + Alt + T) - On the terminal paste
sudo apt install apache2 curl mysql-server php libapache2-mod-php php-mysql git -y; sudo systemctl restart apache2and press enter (you have to insert your password) - On the terminal paste
sudo apt install phpmyadmin -y; sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf; sudo a2enconf phpmyadmin.conf; sudo systemctl reload apache2.service- leave "apache2" in the selecting menu
- when required select "<Yes>"
- set a password for phpmyadmin, after that select "<Ok>"
- Check the installation opening Firefox (the first item in the left menu bar) and as link put
localhost - If it works check also
localhost/phpmyadmin/as link, better if in a new tab- To do the login here put "phpmyadmin" ad username and the password you setted a while go
To add the PHP source code on VirtualBox you need to:
- Go back to the terminal and type
cd /var/www/html; sudo git clone https://github.com/createstructure/rest-createstructure.git; cd rest-createstructure/bin/config/; sed -i 's/<YOUR_DB_NAME>/localhost/g' database.php; sed -i 's/<YOUR_DB_USERNAME>/localhost/g' database.php; sed -i 's/<YOUR_DB_PASSWORD>/localhost/g' database.php; sed -i 's/<YOUR_DB_TABLE_NAME>/createstructure/g' database.php; sed -i 's/ \/\/ TODO//g' database.php - Generate GPG key:
gpg --gen-keyand insert your data (DO NOT PUT ANY PASSWORD) - On the terminal type
echo --armor --export <YOUR_EMAIL>) | sed -e 's/ /\n/g' -e 's/\nPGP\nPUBLIC\nKEY\nBLOCK/ PGP PUBLIC KEY BLOCK/g'(Replace in the string <YOUR_EMAIL> with your email) and copy the result (to copy Ctrl + Alt + C) - Type
sudo nano key.phpand replace <PUBLIC_KEY> with the copied text (to paste Ctrl + Alt + V) and save (Ctrl + X => Y => Enter) - On the terminal type
echo --armor --export-secret-keys <YOUR_EMAIL>) | sed -e 's/ /\n/g' -e 's/\nPGP\nPRIVATE\nKEY\nBLOCK/ PGP PRIVATE KEY BLOCK/g'(Replace in the string <YOUR_EMAIL> with your email) and copy the result (to copy Ctrl + Alt + C) - Type
sudo nano key.phpand replace <PRIVATE_KEY> with the copied text (to paste Ctrl + Alt + V) and save (Ctrl + X => Y => Enter)
Now you will create a DB and the basic structure.
To do that you need to:
- Go back to the phpmyadmin page
- On the hight menu select "SQL"
- Copy this and paste it in the box
- Press "Go"
To use the REST API you need to:
- On the terminal write:
curl -d '{<INSERT_YOUR_REQUEST>}' -H "Content-Type: application/json" -X POST http://localhost/rest-createstructure/bin/ | json_pp -json_opt pretty,canonical, replacing <INSERT_YOUR_REQUEST> with your request, see requests rupported here
Now you can try any changes you want and, if you want, improve the REST API (using Issues, Pull requests, or if you want to suggest/ discuss on how to improve Discussion)
Made w/ :heart: by Castellani Davide
If you want to contribute you can start with: