Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
44b58bc48c
|
|||
1bddff4a23
|
|||
b500b81d80
|
|||
5937c99eb4
|
|||
dfc5c8421a
|
|||
b30e587c34
|
|||
3d0e602ee6
|
|||
30aa514495
|
|||
c72d9bc5ae
|
|||
b64d04c45a
|
@ -37,8 +37,6 @@ build:
|
|||||||
docker push $IMAGE_NAME:${CI_COMMIT_TAG};
|
docker push $IMAGE_NAME:${CI_COMMIT_TAG};
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
stage: deploy
|
stage: deploy
|
||||||
image: registry.hottis.de/dockerized/docker-bash:latest
|
image: registry.hottis.de/dockerized/docker-bash:latest
|
||||||
@ -59,5 +57,5 @@ deploy:
|
|||||||
- docker rm $CONTAINER_NAME || echo "$CONTAINER_NAME not exsting, anyway okay"
|
- docker rm $CONTAINER_NAME || echo "$CONTAINER_NAME not exsting, anyway okay"
|
||||||
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY;
|
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY;
|
||||||
- docker pull $IMAGE_NAME:${CI_COMMIT_TAG}
|
- docker pull $IMAGE_NAME:${CI_COMMIT_TAG}
|
||||||
- docker run -d --restart always --name "hv2-api" --network docker-server --ip 172.16.10.38 -v $SERVICE_VOLUME:/opt/app/config $IMAGE_NAME:${CI_COMMIT_TAG}
|
- docker run -d --restart always --name $CONTAINER_NAME --network docker-server --ip 172.16.10.38 -v $SERVICE_VOLUME:/opt/app/config $IMAGE_NAME:${CI_COMMIT_TAG}
|
||||||
|
|
||||||
|
8
ENV.tmpl
8
ENV.tmpl
@ -1,2 +1,10 @@
|
|||||||
# copy to ENV and adjust values
|
# copy to ENV and adjust values
|
||||||
|
|
||||||
|
JWT_PUB_KEY="..."
|
||||||
|
|
||||||
|
DB_USER="hv2"
|
||||||
|
DB_PASS="..."
|
||||||
|
DB_HOST="172.16.10.27"
|
||||||
|
DB_NAME="hv2"
|
||||||
|
|
||||||
|
|
||||||
|
17
account.py
Normal file
17
account.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
from db import execDatabaseOperation
|
||||||
|
from loguru import logger
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
def _opGetAccounts(cursor, params):
|
||||||
|
accounts = []
|
||||||
|
cursor.execute('SELECT id, description FROM account_t')
|
||||||
|
for accountObj in cursor:
|
||||||
|
logger.debug("add account {} -> {}".format(accountObj[0], accountObj[1]))
|
||||||
|
accounts.append({"id": accountObj[0], "description": accountObj[1]})
|
||||||
|
return accounts
|
||||||
|
|
||||||
|
|
||||||
|
def getAccounts(user, token_info):
|
||||||
|
logger.info("getAccounts, token: {}".format(json.dumps(token_info)))
|
||||||
|
return execDatabaseOperation(_opGetAccounts, ())
|
12
auth.py
12
auth.py
@ -2,7 +2,7 @@ from jose import JWTError, jwt
|
|||||||
import werkzeug
|
import werkzeug
|
||||||
import os
|
import os
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
import json
|
||||||
|
|
||||||
JWT_PUB_KEY = ""
|
JWT_PUB_KEY = ""
|
||||||
try:
|
try:
|
||||||
@ -19,9 +19,9 @@ def decodeToken(token):
|
|||||||
logger.error("{}".format(e))
|
logger.error("{}".format(e))
|
||||||
raise werkzeug.exceptions.Unauthorized()
|
raise werkzeug.exceptions.Unauthorized()
|
||||||
|
|
||||||
def testToken(user, token_info):
|
|
||||||
return '''
|
|
||||||
You are user_id {user} and the provided token has been signed by this issuers. Fine.'.
|
|
||||||
Decoded token claims: {token_info}.
|
|
||||||
'''.format(user=user, token_info=token_info)
|
|
||||||
|
|
||||||
|
def testToken(user, token_info):
|
||||||
|
return {
|
||||||
|
"message": f"You are user_id {user} and the provided token has been signed by this issuers. Fine.",
|
||||||
|
"details": json.dumps(token_info)
|
||||||
|
}
|
50
db.py
Normal file
50
db.py
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
import psycopg2
|
||||||
|
from loguru import logger
|
||||||
|
import os
|
||||||
|
import configparser
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
DB_USER = ""
|
||||||
|
DB_PASS = ""
|
||||||
|
DB_HOST = ""
|
||||||
|
DB_NAME = ""
|
||||||
|
try:
|
||||||
|
DB_USER = os.environ["DB_USER"]
|
||||||
|
DB_PASS = os.environ["DB_PASS"]
|
||||||
|
DB_HOST = os.environ["DB_HOST"]
|
||||||
|
DB_NAME = os.environ["DB_NAME"]
|
||||||
|
except KeyError:
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
config.read('/opt/app/config/dbconfig.ini')
|
||||||
|
DB_USER = config["database"]["user"]
|
||||||
|
DB_PASS = config["database"]["pass"]
|
||||||
|
DB_HOST = config["database"]["host"]
|
||||||
|
DB_NAME = config["database"]["name"]
|
||||||
|
|
||||||
|
|
||||||
|
def databaseOperation(cursor, params):
|
||||||
|
cursor.execute('SELECT key, value FROM claims_for_user_v where "user" = %s and application = %s',
|
||||||
|
params)
|
||||||
|
for claimObj in cursor:
|
||||||
|
logger.debug("add claim {} -> {}".format(claimObj[0], claimObj[1]))
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
def execDatabaseOperation(func, params):
|
||||||
|
conn = None
|
||||||
|
cur = None
|
||||||
|
try:
|
||||||
|
conn = psycopg2.connect(user = DB_USER, password = DB_PASS,
|
||||||
|
host = DB_HOST, database = DB_NAME)
|
||||||
|
conn.autocommit = False
|
||||||
|
|
||||||
|
with conn.cursor() as cur:
|
||||||
|
return func(cur, params)
|
||||||
|
except psycopg2.Error as err:
|
||||||
|
raise Exception("Error when connecting to database: {}".format(err))
|
||||||
|
finally:
|
||||||
|
if conn:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
50
openapi.yaml
50
openapi.yaml
@ -1,10 +1,18 @@
|
|||||||
openapi: 3.0.0
|
openapi: 3.0.0
|
||||||
info:
|
info:
|
||||||
title: hv2-api
|
title: hv2-api
|
||||||
version: "0.1"
|
version: "1"
|
||||||
|
description: "REST-API for the Nober Grundbesitz GbR Hausverwaltungs-Software"
|
||||||
|
termsOfService: "https://home.hottis.de/dokuwiki/doku.php?id=hv2pub:termsofuse"
|
||||||
|
contact:
|
||||||
|
name: "Wolfgang Hottgenroth"
|
||||||
|
email: "wolfgang.hottgenroth@icloud.com"
|
||||||
|
externalDocs:
|
||||||
|
description: "Find more details here"
|
||||||
|
url: "https://home.hottis.de/dokuwiki/doku.php?id=hv2pub:externaldocs"
|
||||||
|
|
||||||
paths:
|
paths:
|
||||||
/test:
|
/v1/test:
|
||||||
get:
|
get:
|
||||||
tags: [ "Test" ]
|
tags: [ "Test" ]
|
||||||
summary: Return secret string
|
summary: Return secret string
|
||||||
@ -13,12 +21,27 @@ paths:
|
|||||||
'200':
|
'200':
|
||||||
description: secret response
|
description: secret response
|
||||||
content:
|
content:
|
||||||
'text/plain':
|
'application/json':
|
||||||
schema:
|
schema:
|
||||||
type: string
|
$ref: '#/components/schemas/TestOutput'
|
||||||
|
security:
|
||||||
|
- jwt: ['secret']
|
||||||
|
/v1/accounts:
|
||||||
|
get:
|
||||||
|
tags: [ "Account" ]
|
||||||
|
summary: Return all normalized accounts
|
||||||
|
operationId: account.getAccounts
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: accounts response
|
||||||
|
content:
|
||||||
|
'application/json':
|
||||||
|
schema:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/Account'
|
||||||
security:
|
security:
|
||||||
- jwt: ['secret']
|
- jwt: ['secret']
|
||||||
|
|
||||||
|
|
||||||
components:
|
components:
|
||||||
securitySchemes:
|
securitySchemes:
|
||||||
@ -27,3 +50,20 @@ components:
|
|||||||
scheme: bearer
|
scheme: bearer
|
||||||
bearerFormat: JWT
|
bearerFormat: JWT
|
||||||
x-bearerInfoFunc: auth.decodeToken
|
x-bearerInfoFunc: auth.decodeToken
|
||||||
|
schemas:
|
||||||
|
TestOutput:
|
||||||
|
description: Test Output
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
details:
|
||||||
|
type: string
|
||||||
|
Account:
|
||||||
|
description: Account
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
description:
|
||||||
|
type: string
|
||||||
|
Reference in New Issue
Block a user