Commit a65e0960 authored by torgiren's avatar torgiren
Browse files

Merge branch 'poc' into 'master'

PoC with user creation - closes #149

See merge request !1
1 merge request!1PoC with user creation - closes #149
Pipeline #1009 passed with stages
in 1 minute and 20 seconds
Showing with 242 additions and 0 deletions
+242 -0
stages:
- prepare
- tests
- build
- push
- deploy
tests:
stage: tests
image: python:3.9
script:
- apt-get update && apt-get install libldap2-dev libsasl2-dev && apt-get clean
- pip install -r requirements.txt
- flake8
# - pytest --cov --cov-report term --cov-report xml --junitxml=report.xml
artifacts:
reports:
cobertura: coverage.xml
junit: report.xml
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
cache:
paths:
- .cache/pip
.registry:
before_script:
- echo -n $CI_REGISTRY_PASSWORD | podman login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
build:
stage: build
image: quay.io/podman/stable
extends: .registry
script:
- podman pull $CI_REGISTRY_IMAGE:latest || true
- >
podman build
--pull
--build-arg http_proxy=$http_proxy
--build-arg https_proxy=$https_proxy
--build-arg no_proxy=$no_proxy
--cache-from $CI_REGISTRY_IMAGE:latest
--tag $CI_REGISTRY_IMAGE:dev
.
- podman push $CI_REGISTRY_IMAGE:dev
push latest:
variables:
GIT_STRATEGY: none
image: quay.io/podman/stable
stage: push
extends: .registry
only:
- master
script:
- podman pull $CI_REGISTRY_IMAGE:dev
- podman tag $CI_REGISTRY_IMAGE:dev $CI_REGISTRY_IMAGE:latest
- podman push $CI_REGISTRY_IMAGE:latest
push tag:
variables:
GIT_STRATEGY: none
image: quay.io/podman/stable
stage: push
extends: .registry
only:
- tags
script:
- podman pull $CI_REGISTRY_IMAGE:dev
- podman tag $CI_REGISTRY_IMAGE:dev $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
- podman push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
Dockerfile 0 → 100644
from python:3.9
#run apt-get update && apt-get install libldap2-dev libsasl2-dev && apt-get clean && rm -rf /var/lib/apt/lists/*
copy requirements.txt /
run pip install -r /requirements.txt
#ENV FLASK_APP=usersservice
#ENV FLASK_ENV=development
WORKDIR /app
#cmd python main.py
#cmd flask run --host=0.0.0.0
#CMD waitress-serve --port 5000 --call 'gateway:create_app'
CMD gunicorn --bind 0.0.0.0:5000 wsgi:app --access-logfile -
#CMD waitress-serve --port 5000 --call 'gateway:create_app'
copy app /app
Makefile 0 → 100644
TAG = latest
APP = $(shell basename $(CURDIR))
build:
docker build -t $(APP):$(TAG) .
run:
docker run --rm -e FLASK_ENV=development -p 5000:5000 -it $(APP):$(TAG)
test:
docker run --rm -e FLASK_ENV=development -it $(APP):$(TAG) pytest --cov --cov-report=term --cov=report=xml
lint:
docker run --rm -e FLASK_ENV=development -it $(APP):$(TAG) flake8
from flask import Flask
from flask_cors import CORS
from flask_graphql import GraphQLView
from gateway.schema import schema
def create_app(test_config=None):
app = Flask(__name__, instance_relative_config=True)
app.logger.setLevel("DEBUG")
app.add_url_rule(
"/graphql",
view_func=GraphQLView.as_view(
"graphql",
schema=schema,
graphiql=True
)
)
CORS(app)
return app
from graphene import ObjectType, Schema, Field, List
import gateway.schema_user as schema_user
class Query(ObjectType):
user = Field(schema_user.User)
users = List(schema_user.User)
resolve_user = schema_user.resolve_user
resolve_users = schema_user.resolve_users
class Mutations(ObjectType):
user_register = schema_user.RegisterUser.Field()
schema = Schema(query=Query, mutation=Mutations)
import requests
import os
from graphene import ObjectType, String, Field, Mutation
def resolve_user(root, infp):
return User()
def resolve_users(root, infp):
return [User(sn="s2")]
class User(ObjectType):
class Meta:
description = 'a user'
sn = String()
gn = String()
mail = String()
login = String()
class RegisterUser(Mutation):
class Arguments:
sn = String(required=True)
gn = String(required=True)
mail = String(required=True)
login = String(required=True)
password = String(required=True)
user = Field(User)
error = String()
def mutate(root, info, sn, gn, mail, login, password):
print("Creating user:",
sn,
gn,
login,
mail)
usersservice_endpoint = os.environ.get('USERSSERVICE_ENDPOINT')
response = requests.post(usersservice_endpoint, json={
"sn": sn,
"gn": gn,
"login": login,
"password": password,
"mail": mail,
})
if response.status_code == 409:
return {'error': "User already exists: " +
str(response.content)}
if response.status_code == 400:
return {'error': "Bad request. TODO better messaging: " +
str(response.content)}
j = response.json()
del(j['password'])
user = RegisterUser(User(**j))
# sn = j['sn'],
# gn = j['gn'],
# login = j['login'],
# mail = j['mail']
# ))
return user
from gateway import create_app
app = create_app()
aniso8601==7.0.0
attrs==21.4.0
certifi==2021.10.8
charset-normalizer==2.0.9
click==8.0.3
coverage==6.2
flake8==4.0.1
Flask==2.0.2
Flask-Cors==3.0.10
Flask-GraphQL==2.0.1
graphene==2.1.9
graphql-core==2.3.2
graphql-relay==2.0.1
graphql-server-core==1.2.0
greenlet==1.1.2
gunicorn==20.1.0
idna==3.3
iniconfig==1.1.1
itsdangerous==2.0.1
Jinja2==3.0.3
MarkupSafe==2.0.1
mccabe==0.6.1
packaging==21.3
pluggy==1.0.0
promise==2.3
py==1.11.0
pycodestyle==2.8.0
pyflakes==2.4.0
pyparsing==3.0.6
pytest==6.2.5
pytest-cov==3.0.0
requests==2.26.0
Rx==1.6.1
singledispatch==3.7.0
six==1.16.0
toml==0.10.2
tomli==2.0.0
typing-extensions==3.10.0.2
urllib3==1.26.7
waitress==2.0.0
Werkzeug==2.0.2
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment