Skip to content

Commit

Permalink
[SDK-158]: Added Docker files for Flask, minor tweaks (#19)
Browse files Browse the repository at this point in the history
* [SDK-224]: Changed Django version to be 1.11 to ensure Python 2.7 compatibility

* [SDK-158]: Added examples to .env files, so that it was clearer that the identifiers shouldn't be enclosed with quotes (this was fine when running regularly, but was causing the docker build to pass them with the quotes)

* [SDK-158]: Renamed all instances of YOTI_FULL_KEY_FILE_PATH variable to YOTI_KEY_FILE_PATH, to avoid any potential confusion

* [SDK-158]: Added docker files for Django example application

* [SDK-224]: Updated Flask example KEY_FILE_PATH to be consistent with Django one, fixed Django tests, updated Flask test instructions

* [SDK-224]: Minor README tweaks

* [SDK-224]: Corrected indentation

* [SDK-158]: Excluded .pem files in Example folders from being committed, since they now are required to reside in these folders when building with Docker

* [SDK-158]: Minor changes to Dockerfiles and README after PR comments
  • Loading branch information
echarrod authored Jan 18, 2018
1 parent fded720 commit b60e18f
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 29 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,7 @@ ENV/
examples/yoti_example_django/yoti_example/static/YotiSelfie.jpg
examples/yoti_example_django/db.sqlite3
examples/yoti_example_flask/static/YotiSelfie.jpg

#.pem files for examples
examples/yoti_example_django/*.pem
examples/yoti_example_flask/*.pem
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ The variables required for the SDK to work are found in the tabs on your Yoti ap

**Please do not open the pem file** as this might corrupt the key and you will need to create a new application.

One way to configure these environment variables is to use an .env file. There are `.env.example` files supplied in the [Django](/examples/yoti_example_django/yoti_example/.env.example) and [Flask](/examples/yoti_example_flask/.env.example) example projects, which you can rename to `.env` and enter your settings into this file.
One way to configure these environment variables is to use an .env file. There are `.env.example` files supplied in the [Django](/examples/yoti_example_django/yoti_example/.env.example) and [Flask](/examples/yoti_example_flask/.env.example) example projects, which you can rename to `.env` and enter your settings into this file. **Do not use quotes when entering your environment variables**

### Example Initialisation

Expand Down Expand Up @@ -129,20 +129,21 @@ nationality = user_profile.get('nationality')

## Running the Examples

The callback URL for both example projects will be http://localhost:5000/yoti/auth/
The callback URL for both example projects will be `http://localhost:5000/yoti/auth/`

### With Docker

#### Flask

To run the Flask container:
To run the Flask or Django container:

1. Clone this repository
1. Change directory to the Flask example project with `cd examples/yoti_example_flask`
1. Change directory to the example project directory with
* `cd examples/yoti_example_flask` for __Flask__
__OR__
* `cd examples/yoti_example_django` for __Django__
1. Make sure the environment variables `YOTI_APPLICATION_ID`, `YOTI_CLIENT_SDK_ID` and `YOTI_KEY_FILE_PATH` are set (instructions in the [Configuration](#configuration) section). _Please note that with Docker, the .pem file must reside in a location within where docker is being run from, so it should be placed somewhere under the respective [yoti_example_flask](/examples/yoti_example_flask)/[yoti_example_django](/examples/yoti_example_django) folders._
1. Rebuild the images if you have modified the docker-compose.yml file with
- `docker-compose build --no-cache`
1. Build the container with `docker-compose up`
1. Start the container with `docker-compose up`
1. Navigate to http://localhost:5000

### Running Locally
Expand Down
3 changes: 3 additions & 0 deletions examples/yoti_example_django/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
YOTI_APPLICATION_ID=yourApplicationId
YOTI_CLIENT_SDK_ID=yourClientSdkId
YOTI_KEY_FILE_PATH=yourKeyFilePath
14 changes: 14 additions & 0 deletions examples/yoti_example_django/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM python:3
ARG YOTI_APPLICATION_ID
ARG YOTI_CLIENT_SDK_ID
ARG YOTI_KEY_FILE_PATH
RUN if [ "$YOTI_APPLICATION_ID" = "yourApplicationId" ] ; then echo YOTI_APPLICATION_ID not set; exit 1; else echo YOTI_APPLICATION_ID is $YOTI_APPLICATION_ID ; fi
RUN if [ "$YOTI_CLIENT_SDK_ID" = "yourClientSdkId" ] ; then echo YOTI_CLIENT_SDK_ID not set; exit 1; else echo YOTI_CLIENT_SDK_ID is $YOTI_CLIENT_SDK_ID ; fi
RUN if [ "$YOTI_KEY_FILE_PATH" = "yourKeyFilePath" ] ; then echo YOTI_KEY_FILE_PATH not set; exit 1; else echo YOTI_KEY_FILE_PATH is $YOTI_KEY_FILE_PATH ; fi
ADD . /code
WORKDIR /code
RUN pip install --no-cache-dir -r requirements.txt
ENV YOTI_APPLICATION_ID $YOTI_APPLICATION_ID
ENV YOTI_CLIENT_SDK_ID $YOTI_CLIENT_SDK_ID
ENV YOTI_KEY_FILE_PATH $YOTI_KEY_FILE_PATH
CMD ["python", "manage.py", "runserver", "0.0.0.0:5000"]
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

YOTI_APPLICATION_ID = environ.get('YOTI_APPLICATION_ID')
YOTI_CLIENT_SDK_ID = environ.get('YOTI_CLIENT_SDK_ID')
YOTI_FULL_KEY_FILE_PATH = environ.get('YOTI_KEY_FILE_PATH')
YOTI_KEY_FILE_PATH = environ.get('YOTI_KEY_FILE_PATH')
12 changes: 12 additions & 0 deletions examples/yoti_example_django/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3.4'
services:
web:
build:
context: ./
args:
YOTI_APPLICATION_ID: "${YOTI_APPLICATION_ID}"
YOTI_CLIENT_SDK_ID: "${YOTI_CLIENT_SDK_ID}"
YOTI_KEY_FILE_PATH: "${YOTI_KEY_FILE_PATH}"
ports:
- "5000:5000"
restart: always
3 changes: 3 additions & 0 deletions examples/yoti_example_django/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Django==1.11
yoti
python-dotenv>=0.7.1
3 changes: 0 additions & 3 deletions examples/yoti_example_django/yoti_example/.env.example

This file was deleted.

8 changes: 4 additions & 4 deletions examples/yoti_example_django/yoti_example/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
from django.views.generic import TemplateView
from dotenv import load_dotenv

dotenv_path = join(dirname(__file__), '.env')
dotenv_path = join(dirname(__file__), '..\\', '.env')
load_dotenv(dotenv_path)

from yoti_python_sdk import Client
from .app_settings import (
from app_settings import (
YOTI_APPLICATION_ID,
YOTI_CLIENT_SDK_ID,
YOTI_FULL_KEY_FILE_PATH
YOTI_KEY_FILE_PATH
)


Expand All @@ -26,7 +26,7 @@ class AuthView(TemplateView):
template_name = 'profile.html'

def get(self, request, *args, **kwargs):
client = Client(YOTI_CLIENT_SDK_ID, YOTI_FULL_KEY_FILE_PATH)
client = Client(YOTI_CLIENT_SDK_ID, YOTI_KEY_FILE_PATH)
activity_details = client.get_activity_details(request.GET['token'])
context = activity_details.user_profile
self.save_image(context.get('selfie'))
Expand Down
6 changes: 3 additions & 3 deletions examples/yoti_example_flask/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
YOTI_APPLICATION_ID=
YOTI_CLIENT_SDK_ID=
YOTI_KEY_FILE_PATH=
YOTI_APPLICATION_ID=yourApplicationId
YOTI_CLIENT_SDK_ID=yourClientSdkId
YOTI_KEY_FILE_PATH=yourKeyFilePath
8 changes: 4 additions & 4 deletions examples/yoti_example_flask/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM python:3
ARG YOTI_APPLICATION_ID
ARG YOTI_CLIENT_SDK_ID
ARG YOTI_FULL_KEY_FILE_PATH
RUN if [ "$YOTI_APPLICATION_ID" = "" ] ; then echo YOTI_APPLICATION_ID not provided; exit 1; else echo YOTI_APPLICATION_ID is $YOTI_APPLICATION_ID ; fi
RUN if [ "$YOTI_CLIENT_SDK_ID" = "" ] ; then echo YOTI_CLIENT_SDK_ID not provided; exit 1; else echo YOTI_CLIENT_SDK_ID is $YOTI_CLIENT_SDK_ID ; fi
RUN if [ "$YOTI_FULL_KEY_FILE_PATH" = "" ] ; then echo YOTI_FULL_KEY_FILE_PATH not provided; exit 1; else echo YOTI_FULL_KEY_FILE_PATH is $YOTI_FULL_KEY_FILE_PATH ; fi
ARG YOTI_KEY_FILE_PATH
RUN if [ "$YOTI_APPLICATION_ID" = "yourApplicationId" ] ; then echo YOTI_APPLICATION_ID not set; exit 1; else echo YOTI_APPLICATION_ID is $YOTI_APPLICATION_ID ; fi
RUN if [ "$YOTI_CLIENT_SDK_ID" = "yourClientSdkId" ] ; then echo YOTI_CLIENT_SDK_ID not set; exit 1; else echo YOTI_CLIENT_SDK_ID is $YOTI_CLIENT_SDK_ID ; fi
RUN if [ "$YOTI_KEY_FILE_PATH" = "yourKeyFilePath" ] ; then echo YOTI_KEY_FILE_PATH not set; exit 1; else echo YOTI_KEY_FILE_PATH is $YOTI_KEY_FILE_PATH ; fi
ADD . /code
WORKDIR /code
RUN pip install --no-cache-dir -r requirements.txt
Expand Down
4 changes: 2 additions & 2 deletions examples/yoti_example_flask/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from settings import (
YOTI_APPLICATION_ID,
YOTI_CLIENT_SDK_ID,
YOTI_FULL_KEY_FILE_PATH,
YOTI_KEY_FILE_PATH,
)

app = Flask(__name__)
Expand All @@ -36,7 +36,7 @@ def index():

@app.route('/yoti/auth')
def auth():
client = Client(YOTI_CLIENT_SDK_ID, YOTI_FULL_KEY_FILE_PATH)
client = Client(YOTI_CLIENT_SDK_ID, YOTI_KEY_FILE_PATH)
activity_details = client.get_activity_details(request.args['token'])
user_profile = activity_details.user_profile
save_image(user_profile.get('selfie'))
Expand Down
2 changes: 1 addition & 1 deletion examples/yoti_example_flask/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
args:
YOTI_APPLICATION_ID: "${YOTI_APPLICATION_ID}"
YOTI_CLIENT_SDK_ID: "${YOTI_CLIENT_SDK_ID}"
YOTI_FULL_KEY_FILE_PATH: "${YOTI_KEY_FILE_PATH}"
YOTI_KEY_FILE_PATH: "${YOTI_KEY_FILE_PATH}"
ports:
- "5000:5000"

Expand Down
2 changes: 1 addition & 1 deletion examples/yoti_example_flask/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

YOTI_APPLICATION_ID = environ.get('YOTI_APPLICATION_ID')
YOTI_CLIENT_SDK_ID = environ.get('YOTI_CLIENT_SDK_ID')
YOTI_FULL_KEY_FILE_PATH = environ.get('YOTI_KEY_FILE_PATH')
YOTI_KEY_FILE_PATH = environ.get('YOTI_KEY_FILE_PATH')
1 change: 1 addition & 0 deletions plugins/django_yoti/django_yoti/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
'OPTIONS': {
'context_processors': [
'django_yoti.context_processors.yoti_context',
'django.contrib.auth.context_processors.auth',
],
},
},
Expand Down
5 changes: 4 additions & 1 deletion plugins/flask_yoti/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,7 @@ will be redirected to an endpoint, provided by the `YOTI_LOGIN_VIEW` setting.

## Tests ##

To run unit tests (after running `python setup.py develop`), type: `python flask_yoti/runtests.py`
To run unit tests:
1. Change to the right directory - `cd plugins/flask_yoti`
1. Run the setup file - `python setup.py develop`
1. Run the tests - `py.test`
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
click==6.6
cryptography==1.5.2
Django==1.10.2
Django==1.11
Flask==0.11.1
itsdangerous==0.24
Jinja2==2.8
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
install_requires=['cryptography>=1.4', 'protobuf>=3.0.0',
'requests>=2.0.0', 'future>=0.11.0'],
extras_require={
'examples': ['Django>=1.9', 'Flask>=0.10', 'python-dotenv>=0.7.1'],
'examples': ['Django==1.11', 'Flask>=0.10', 'python-dotenv>=0.7.1'],
},
classifiers=[
'Development Status :: 5 - Production/Stable',
Expand Down

0 comments on commit b60e18f

Please sign in to comment.