A Flask application that generate passwords on demand.
This repository contains code for Password Factory:
app/
-- contains code for api, schema, utilities and loggerdocker/
-- docker-compose file and docker files for nginx and webapp. It also contains configs for uwsgi and nginxtests/
-- Unit test scripts and Datapostman/
-- postman collection along with api testslogs/
-- Application generated logs will store here
.env
-- contatins the server default params. If any param is missing in the API call, it would be filled from this file..flake8
-- configurations for linting the codeMakefile
-- contains the automation scriptspytest.ini
-- configurations for testing and coverage reportrequirements.txt
-- lists all the dependencies of the applicationtests_requirements.txt
-- list all the dependencies for running the tests.
Note: Make sure you have python3 installed
-
Clone the repository
-
Navidate into the code directory
cd <directory>
-
Run the following command to create virtual environment
python3 -m venv venv
-
Activate the virtual enviroment using the following command
source venv/bin/activate
-
Now start dev server using the following command. It will install dependencies and run the developement server on localhost default port 5000 : http://localhost:5000/generate?numbers=1
make start-dev
-
Import the postman collection from the
postman/
directory and set environment to 'Password factory' and baseurl to {{local}}. -
Run the API calls to test
Note: Make sure you have installed docker and docker-compose.
-
Clone the repository
-
Navidate into the code directory
cd <directory>
-
To fireup docker containers using docker-compose:
make start-docker
-
The application would be served at http://localhost/generate?numbers=1
-
To stop docker containers:
make stop-docker
-
To build docker images from the docker files:
make build-docker
-
Import the postman collection in the
postman/
directory and set environment to 'Password factory' and baseurl to {{docker}}. -
Run the API call to test
-
Clone the repository
-
Navidate into the code directory
cd <directory>
-
To create distribution files run command
make dist
Note A dist directory will be created with tar.gz file. It can be published and installed using setup.py commands
Note: Github Actions are used for continuous integration
-
Checks performed on commit to main
- Run linter to check code standards - Run pytest to execute tests
-
Code will be merged to main branch once the checks are successfull
To only install requirements:
make install
To run unit tests:
make test
To run code linting:
make lint
To format code:
make format
-
postman/
-- contains api collection and test cases. -
Each API has a documentation section to explain the scenario.
-
40 postman API tests are in the collection to test API.
-
Import the collection and execute run collection.
Note Diagram is created using mermaid code, only visible in repository.
graph TD
A[Request password: '/generate'] -->|Gets params and calls| B(Password Factory)
B --> C{Validate params}
C -->|Incorrect params| E[Return 404 Bad Request]
E -->id1([Done])
C -->|Correct params| F[Generate Password]
F -->G[Return password to user]
G -->Hid1([Done])
-
Followed the rule of simplicity. Simple is better than complex.
-
Code distribution across modules and files to ensure separation of concern.
-
Custom logging with user readable message format and log rotation.
-
Handled error such that they get noticed. log file is maintained incase error in the console is missed.
-
In docker implementation, reverse proxy through nginx to ensure api calls donot fall on flask app directly (best practice to ensure security).
-
Continuous integration implemented to make sure code is not buggy and upto the set standard.
-
.env file varibales are overridden by env variables exported through export command.
-
virtual environment used to make sure dependencies are installed in the env.
-
Marshmallow schema for validation of API request.
-
flake8 is used for linting code.
-
black is used for formating code.
-
setup.py implemented for distribution packages.
-
test cases implementation.