Last active
June 21, 2019 20:47
-
-
Save a-chumagin/24c44f918accb03a9123f3703d02ade8 to your computer and use it in GitHub Desktop.
simple_flask_server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request, after_this_request | |
app = Flask(__name__) | |
@app.route("/api/auth", methods=["GET"]) | |
def auth(): | |
username = request.args.get('username') | |
password = request.args.get('password') | |
encode = username + password | |
@after_this_request | |
def add_header(response): | |
response.headers['X-Auth'] = encode | |
return response | |
return 'Hello World!' | |
@app.route("/api/login", methods=["GET"]) | |
def login(): | |
token = request.args.get('token') | |
return token |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
flask run --host=0.0.0.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM alpine:latest | |
RUN apk update && apk add python3 | |
RUN python3 -m ensurepip | |
COPY ./requirements.txt /opt/flask_auth/requirements.txt | |
WORKDIR /opt/flask_auth | |
RUN pip3 install -r requirements.txt | |
COPY . /opt/flask_auth | |
RUN chmod a+x boot.sh | |
EXPOSE 5000 | |
VOLUME /opt/FlaskMock | |
ENV FLASK_APP app.py | |
ENTRYPOINT ["./boot.sh"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"info": { | |
"_postman_id": "83bbad13-4a2b-4934-800c-215d1b516a04", | |
"name": "flask_auth", | |
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" | |
}, | |
"item": [ | |
{ | |
"name": "auth", | |
"event": [ | |
{ | |
"listen": "test", | |
"script": { | |
"id": "134d7ac7-0ec5-4582-bc7e-94f585c185ce", | |
"exec": [ | |
"pm.globals.set(\"auth\",postman.getResponseHeader(\"X-Auth\") );" | |
], | |
"type": "text/javascript" | |
} | |
} | |
], | |
"request": { | |
"method": "GET", | |
"header": [], | |
"url": { | |
"raw": "0.0.0.0:5000/api/auth?username=root&password=pwd", | |
"host": [ | |
"0", | |
"0", | |
"0", | |
"0" | |
], | |
"port": "5000", | |
"path": [ | |
"api", | |
"auth" | |
], | |
"query": [ | |
{ | |
"key": "username", | |
"value": "root" | |
}, | |
{ | |
"key": "password", | |
"value": "pwd" | |
} | |
] | |
} | |
}, | |
"response": [] | |
}, | |
{ | |
"name": "login", | |
"request": { | |
"method": "GET", | |
"header": [], | |
"url": { | |
"raw": "0.0.0.0:5000/api/login?token={{auth}}", | |
"host": [ | |
"0", | |
"0", | |
"0", | |
"0" | |
], | |
"port": "5000", | |
"path": [ | |
"api", | |
"login" | |
], | |
"query": [ | |
{ | |
"key": "token", | |
"value": "{{auth}}" | |
} | |
] | |
} | |
}, | |
"response": [] | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Flask |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
docker build . -t flask_auth
docker run --rm -p 5000:5000 -it flask_auth