Skip to content

Instantly share code, notes, and snippets.

@a-chumagin
Last active June 21, 2019 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a-chumagin/24c44f918accb03a9123f3703d02ade8 to your computer and use it in GitHub Desktop.
Save a-chumagin/24c44f918accb03a9123f3703d02ade8 to your computer and use it in GitHub Desktop.
simple_flask_server
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
#!/bin/sh
flask run --host=0.0.0.0
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"]
{
"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": []
}
]
}
@a-chumagin
Copy link
Author

docker build . -t flask_auth
docker run --rm -p 5000:5000 -it flask_auth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment