This is a Flask (python) application that runs alongside a postgreSQL database with random data in a docker container. From this source code you can build the docker image.
Our sales team has asked our support engineering team to configure a pre-established process to integrate a new ally into our platform. This process requires adding new records to a SQL database and using an endpoint of our API.
The process consists of:
- Manually insert the following information to the table
stores
using an SQL script:
Data:
1. id: 1234567890
2. name: Aliado ADDI
3. tags: tecnologia, informacion, finanzas
4. brand: Merchant
5. discount: 5
6. maxAmount: 150
7. minAMount: 20
8. credentials: null
-
Build an SQL query to find all allies that have the tag
finanzas
-
Build an HTTP request to add the ally's credentials through our API.
Since the credentials used to communicate with our partner are sensitive information, an encryption process must be carried out. This process can be done by making an HTTP request to our API which receives the necessary data and adds the credentials in the stores table. Endpoint documentation can be found attached to this file.
The credentials to add for this new ally are:
username: aliado_addi
password: }sxh7_5}BdJ4K:Qf
- We expect you to run the application on local machine using docker
- We expect you to build SQL queries using json data handling functions. You can use database management tools like DBeaver
- You can use any tool or programming language to perform HTTP resquests to the API. For example Postman, CURL, wget or any programming languages.
- We expec a README file describing the general process and the steps to develop it using the resources created during the process (queries, API requests). This with the goal for it to be used as future reference and as an easy-to-follow document for another person to follow.
- We do not expect you to publish the application on the public internet
- SQL script to add a new ally.
- SQL query to list all allies with the tag "finance"
- HTTP Request that adds a given ally's credentials through our API
- A README as a runbook explaining how to carry out the process.
- We hope to receive these files in a private GITHUB repository.
To run this application in a local environment, the following requirements must be met:
- Use a Linux environment (Distributions like Ubuntu or Manjaro are the most popular)
- Have docker installed
- Have Git installed
Then the following steps must be performed:
- Clone this repository to a local folder.
git clone https://github.com/AdelanteFinancialHoldings/SE-technical-challenge.git
- Build the docker image (With a terminal in the directory that contains the dockerfile):
sudo docker build -t addi-assesment .
- Run the bash file
run.sh
:
bash run.sh
- Open the docker container's bash:
sudo docker exec -it addi-app /bin/bash
- Alternatively you can use the file with friendly name:
bash enter_docker_bash.sh
- Once inside the docker cli, you will be in a folder that contains the necessary script to start, the "run_flask.sh" application:
bash run_flask.sh
This starts the application and the database, which are listening on port 5000 and 5432 respectively. At this point the terminal can be closed and the application will continue to run.
To stop the application this commands can be used from a different terminal:
sudo docker stop addi-app
sudo docker system prune
The credentials for the locally deployed database are:
- host: localhost:5432
- database: postgres
- password: 1234
The API, when started with the run_flash.sh command, does the following:
- Start the application.
- Populate the database with random data.
- Starts listening to requests at address 127.0.0.1:5000
POST /allies/{allyId}/credentials
Add communication credentials to an ally
Headers: "Content-Type: application/json"
Parameters:
allyId(path): string identification for an ally.
Payload(body): json object, example
{
"username": "addi",
"password": "123456"
}
Responses:
200:
{
"message": "Credentials added",
"allyId": "allyId",
"allyName": "ally name"
}
400:
{
"message": "The ally was not found or the request is not correct"
}
500:
{
"message": "Server error"
}
GET /allies/{allyId}/credentials
Checks if the given ally has active credentials and is an allowed origin in our application
Headers: "Content-Type: application/json"
Parameters:
allyId(path): string identification for an ally.
Responses:
200:
{
"message": "Ally has credentials set!"
}
400:
{
"message": "Ally does not have credentials set!"
}
404:
{
"message": "Ally was not found"
}
500:
{
"message": "Server error"
}